()
| 27 | |
| 28 | // Parse named servers config from JSON file or MCP_NAMED_SERVERS env var |
| 29 | function parseNamedServersConfig() { |
| 30 | // Try env var first (JSON string) |
| 31 | if (process.env.MCP_NAMED_SERVERS) { |
| 32 | try { |
| 33 | return JSON.parse(process.env.MCP_NAMED_SERVERS); |
| 34 | } catch (err) { |
| 35 | console.error('[mcp-proxy] Failed to parse MCP_NAMED_SERVERS JSON:', err.message); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | // Try config file path |
| 40 | if (process.env.MCP_NAMED_SERVERS_CONFIG) { |
| 41 | try { |
| 42 | const configPath = process.env.MCP_NAMED_SERVERS_CONFIG; |
| 43 | const configContent = readFileSync(configPath, 'utf-8'); |
| 44 | return JSON.parse(configContent); |
| 45 | } catch (err) { |
| 46 | console.error('[mcp-proxy] Failed to read MCP_NAMED_SERVERS_CONFIG file:', err.message); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | // Try default config file location |
| 51 | const defaultConfigPath = join(__dirname, 'named-servers.json'); |
| 52 | try { |
| 53 | const configContent = readFileSync(defaultConfigPath, 'utf-8'); |
| 54 | return JSON.parse(configContent); |
| 55 | } catch (err) { |
| 56 | // Config file doesn't exist, not an error |
| 57 | } |
| 58 | |
| 59 | return null; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Handle a JSON-RPC request by forwarding to the stdio MCP client. |
no test coverage detected