MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / resolveMcpEnv

Function resolveMcpEnv

sdk/src/agents/load-mcp-config.ts:44–72  ·  view source on GitHub ↗
(
  env: Record<string, string> | undefined,
  mcpServerName: string,
)

Source from the content-addressed store, hash-verified

42const processEnv = process[envKey] as NodeJS.ProcessEnv
43
44function 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.

Callers 1

resolveMcpConfigEnvFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected