MCPcopy Index your code
hub / github.com/codeaashu/claude-code / getMcpHeadersFromHelper

Function getMcpHeadersFromHelper

src/services/mcp/headersHelper.ts:32–117  ·  view source on GitHub ↗
(
  serverName: string,
  config: McpSSEServerConfig | McpHTTPServerConfig | McpWebSocketServerConfig,
)

Source from the content-addressed store, hash-verified

30 * @returns Headers object or null if not configured or failed
31 */
32export async function getMcpHeadersFromHelper(
33 serverName: string,
34 config: McpSSEServerConfig | McpHTTPServerConfig | McpWebSocketServerConfig,
35): Promise<Record<string, string> | null> {
36 if (!config.headersHelper) {
37 return null
38 }
39
40 // Security check for project/local settings
41 // Skip trust check in non-interactive mode (e.g., CI/CD, automation)
42 if (
43 'scope' in config &&
44 isMcpServerFromProjectOrLocalSettings(config as ScopedMcpServerConfig) &&
45 !getIsNonInteractiveSession()
46 ) {
47 // Check if trust has been established for this project
48 const hasTrust = checkHasTrustDialogAccepted()
49 if (!hasTrust) {
50 const error = new Error(
51 `Security: headersHelper for MCP server '${serverName}' executed before workspace trust is confirmed. If you see this message, post in ${MACRO.FEEDBACK_CHANNEL}.`,
52 )
53 logAntError('MCP headersHelper invoked before trust check', error)
54 logEvent('tengu_mcp_headersHelper_missing_trust', {})
55 return null
56 }
57 }
58
59 try {
60 logMCPDebug(serverName, 'Executing headersHelper to get dynamic headers')
61 const execResult = await execFileNoThrowWithCwd(config.headersHelper, [], {
62 shell: true,
63 timeout: 10000,
64 // Pass server context so one helper script can serve multiple MCP servers
65 // (git credential-helper style). See deshaw/anthropic-issues#28.
66 env: {
67 ...process.env,
68 CLAUDE_CODE_MCP_SERVER_NAME: serverName,
69 CLAUDE_CODE_MCP_SERVER_URL: config.url,
70 },
71 })
72 if (execResult.code !== 0 || !execResult.stdout) {
73 throw new Error(
74 `headersHelper for MCP server '${serverName}' did not return a valid value`,
75 )
76 }
77 const result = execResult.stdout.trim()
78
79 const headers = jsonParse(result)
80 if (
81 typeof headers !== 'object' ||
82 headers === null ||
83 Array.isArray(headers)
84 ) {
85 throw new Error(
86 `headersHelper for MCP server '${serverName}' must return a JSON object with string key-value pairs`,
87 )
88 }
89

Callers 1

getMcpServerHeadersFunction · 0.85

Calls 13

logAntErrorFunction · 0.85
logEventFunction · 0.85
logMCPDebugFunction · 0.85
execFileNoThrowWithCwdFunction · 0.85
jsonParseFunction · 0.85
logMCPErrorFunction · 0.85
entriesMethod · 0.80
keysMethod · 0.80
errorMessageFunction · 0.50

Tested by

no test coverage detected