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

Function resolveMcpEnv

sdk/src/agents/load-agents.ts:33–64  ·  view source on GitHub ↗
(
  env: Record<string, string> | undefined,
  agentId: string,
  mcpServerName: string,
)

Source from the content-addressed store, hash-verified

31 * @throws Error if a referenced environment variable is missing
32 */
33export 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.

Callers 1

resolveAgentMcpEnvFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected