Skip to content

Commit 382631a

Browse files
committed
fix: send configured headers during MCP OAuth flow
The mcp auth and mcp debug commands were not forwarding headers configured under mcp.<name>.headers during the OAuth flow, causing 404 errors instead of 401 from servers requiring custom headers for routing. Fixed three code paths: 1. startAuth in src/mcp/index.ts - added requestInit with headers 2. McpDebugCommand fetch probe - added headers to fetch call 3. McpDebugCommand OAuth transport - added requestInit with headers Fixes anomalyco#20286
1 parent b2eab3c commit 382631a

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

‎packages/opencode/src/cli/cmd/mcp.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ export const McpDebugCommand = cmd({
655655
headers: {
656656
"Content-Type": "application/json",
657657
Accept: "application/json, text/event-stream",
658+
...(serverConfig.headers ?? {}),
658659
},
659660
body: JSON.stringify({
660661
jsonrpc: "2.0",
@@ -699,6 +700,7 @@ export const McpDebugCommand = cmd({
699700
// Try creating transport with auth provider to trigger discovery
700701
const transport = new StreamableHTTPClientTransport(new URL(serverConfig.url), {
701702
authProvider,
703+
requestInit: serverConfig.headers ? { headers: serverConfig.headers } : undefined,
702704
})
703705

704706
try {

‎packages/opencode/src/mcp/index.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,10 @@ export namespace MCP {
739739
},
740740
)
741741

742-
const transport = new StreamableHTTPClientTransport(new URL(mcpConfig.url), { authProvider })
742+
const transport = new StreamableHTTPClientTransport(new URL(mcpConfig.url), {
743+
authProvider,
744+
requestInit: mcpConfig.headers ? { headers: mcpConfig.headers } : undefined,
745+
})
743746

744747
return yield* Effect.tryPromise({
745748
try: () => {

0 commit comments

Comments
 (0)