Skip to content

Commit 69ea24f

Browse files
committed
add locale to mcp/servers api to allow showing mcp servers in different languages
1 parent a436341 commit 69ea24f

File tree

3 files changed

+9
-23
lines changed

3 files changed

+9
-23
lines changed

server/src/lib/llmTools.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import { callLLM } from './llm.js';
88
*/
99
export const LANGUAGES: Record<string, string> = {
1010
'en': 'English',
11-
// 'zhHans': 'Simplified Chinese',
12-
// 'zhHant': 'Traditional Chinese',
1311
'zh-hans': 'Simplified Chinese',
1412
'zh-hant': 'Traditional Chinese',
1513
'ja': 'Japanese',

server/src/lib/mcpServers.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,8 @@ const lastCacheUpdate: Record<string, number> = {};
3232
const CACHE_TTL = 60 * 60 * 1000; // 1 hour in milliseconds
3333
const DEFAULT_LOCALE = 'en';
3434

35-
// Add support for both formats of locales (kebab-case and camelCase)
36-
const SUPPORTED_LOCALES = ['en', 'de', 'es', 'ja', 'zh-hans', 'zhHans', 'zh-hant', 'zhHant'];
37-
38-
// Mapping for locale names to handle kebab-case vs. camelCase formats
39-
const localeDirectoryMapping: Record<string, string> = {
40-
'zhHans': 'zh-hans', // Map camelCase to kebab-case
41-
'zhHant': 'zh-hant', // Map camelCase to kebab-case
42-
'zh-hans': 'zh-hans', // Keep kebab-case as is
43-
'zh-hant': 'zh-hant' // Keep kebab-case as is
44-
};
45-
46-
/**
47-
* Normalizes a locale name to the directory format
48-
* @param locale The locale to normalize
49-
*/
50-
function normalizeLocaleForDirectory(locale: string): string {
51-
return localeDirectoryMapping[locale] || locale;
52-
}
35+
// Supported locales list
36+
const SUPPORTED_LOCALES = ['en', 'de', 'es', 'ja', 'zh-hans', 'zh-hant'];
5337

5438
/**
5539
* Loads all MCP server data from split files and combines them
@@ -67,7 +51,7 @@ export async function loadMcpServersData(locale: string = DEFAULT_LOCALE): Promi
6751
const baseDir = join(__dirname, '..', 'data', 'split');
6852

6953
// Map the locale to the correct directory name if needed
70-
const directoryLocale = normalizeLocaleForDirectory(locale);
54+
const directoryLocale = locale;
7155

7256
// For English, use the root directory; for other locales, use the locale-specific subdirectory
7357
let dirPath = locale === DEFAULT_LOCALE ? baseDir : join(baseDir, directoryLocale);

server/src/routes/mcp.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ const router = Router();
77
// GET /servers
88
router.get('/servers', async (req: Request, res: Response): Promise<void> => {
99
try {
10-
const mcpServersCache = await refreshCacheIfNeeded();
10+
// Get locale from query parameter or use default
11+
const locale = typeof req.query.locale === 'string' ? req.query.locale : 'en';
12+
13+
// Get servers data for the requested locale (function will use 'en' if locale is invalid)
14+
const mcpServersCache = await refreshCacheIfNeeded(locale);
1115

1216
// Return cleaned data without hubId
1317
const cleanedData = getCleanedServersData(mcpServersCache);
1418
res.json(cleanedData);
15-
console.log(`v1/mcp/servers Served cached MCP servers data at ${new Date().toISOString()}`);
19+
console.log(`v1/mcp/servers Served cached MCP servers data for locale '${locale}' at ${new Date().toISOString()}`);
1620
} catch (error) {
1721
console.error('Error serving MCP servers:', error);
1822
res.status(500).json({ error: 'Internal server error' });

0 commit comments

Comments
 (0)