( env: Record<string, string> | undefined, mcpServerName: string, )
| 42 | const processEnv = process[envKey] as NodeJS.ProcessEnv |
| 43 | |
| 44 | function resolveMcpEnv( |
| 45 | env: Record<string, string> | undefined, |
| 46 | mcpServerName: string, |
| 47 | ): Record<string, string> { |
| 48 | if (!env) return {} |
| 49 | |
| 50 | const resolved: Record<string, string> = {} |
| 51 | |
| 52 | for (const [key, value] of Object.entries(env)) { |
| 53 | if (value.startsWith('$')) { |
| 54 | // $VAR_NAME reference - resolve from process.env |
| 55 | const envVarName = value.slice(1) // Remove the leading $ |
| 56 | const envValue = processEnv[envVarName] |
| 57 | |
| 58 | if (envValue === undefined) { |
| 59 | throw new Error( |
| 60 | `Missing environment variable '${envVarName}' required by MCP server '${mcpServerName}' in mcp.json`, |
| 61 | ) |
| 62 | } |
| 63 | |
| 64 | resolved[key] = envValue |
| 65 | } else { |
| 66 | // Plain string value - use as-is |
| 67 | resolved[key] = value |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | return resolved |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Resolves all MCP server env references in a config. |
no outgoing calls
no test coverage detected