Skip to content

The mcp auth and mcp debug don't send configured headers during OAuth flow #20286

@obaranov

Description

@obaranov

Description

When a remote MCP server requires custom headers on every request (e.g. for routing/realm selection), the opencode mcp auth and opencode mcp debug commands fail because the headers configured under mcp..headers are not forwarded during the OAuth flow.

The headers are correctly sent for normal MCP connections (connectRemote), but three code paths ignore them:

  1. startAuth in src/mcp/index.ts — creates StreamableHTTPClientTransport without requestInit
  2. The fetch probe in src/cli/cmd/mcp.ts (McpDebugCommand) — raw fetch() call omits the headers
  3. The OAuth transport in src/cli/cmd/mcp.ts (McpDebugCommand) — creates StreamableHTTPClientTransport without requestInit

The result: mcp auth gets a 404 instead of 401 from the server and reports "Authentication failed". mcp debug similarly probes without the headers and reports wrong status.

Plugins

No response

OpenCode version

1.3.10

Steps to reproduce

  1. Configure a remote MCP server that requires a custom header on all requests:
 mcp: {
     my-server: {
       type: remote,
       url: https://example.com/mcp,
       headers: { X-Custom-Header: value },
       oauth: {}
     }
   }
  1. Run opencode mcp auth my-server
  2. Authentication fails with a 404 error

Screenshot and/or share link

No response

Operating System

Linux (Fedora 43)

Terminal

Ghostty

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcoreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions