( env: Record<string, string> | undefined, agentId: string, mcpServerName: string, )
| 31 | * @throws Error if a referenced environment variable is missing |
| 32 | */ |
| 33 | export function resolveMcpEnv( |
| 34 | env: Record<string, string> | undefined, |
| 35 | agentId: string, |
| 36 | mcpServerName: string, |
| 37 | ): Record<string, string> { |
| 38 | if (!env) return {} |
| 39 | |
| 40 | const resolved: Record<string, string> = {} |
| 41 | |
| 42 | for (const [key, value] of Object.entries(env)) { |
| 43 | if (value.startsWith('$')) { |
| 44 | // $VAR_NAME reference - resolve from process.env |
| 45 | const envVarName = value.slice(1) // Remove the leading $ |
| 46 | // Allow dynamic process.env access |
| 47 | const envName = 'env' |
| 48 | const envValue = process[envName][envVarName] |
| 49 | |
| 50 | if (envValue === undefined) { |
| 51 | throw new Error( |
| 52 | `Missing environment variable '${envVarName}' required by agent '${agentId}' in mcpServers.${mcpServerName}.env.${key}`, |
| 53 | ) |
| 54 | } |
| 55 | |
| 56 | resolved[key] = envValue |
| 57 | } else { |
| 58 | // Plain string value - use as-is |
| 59 | resolved[key] = value |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | return resolved |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Resolves all MCP server env references in an agent definition. |
no outgoing calls
no test coverage detected