Skip to content

feat: support custom headers for HTTP/SSE transports - #29

Merged
maplezzk merged 2 commits into
maplezzk:mainfrom
mutallipp:feat/support-headers-for-http-transport
Apr 28, 2026
Merged

maplezzk merged 2 commits into
maplezzk:mainfrom
mutallipp:feat/support-headers-for-http-transport

Conversation

@mutallipp

Copy link
Copy Markdown

Problem

When connecting to HTTP-based MCP servers that require authentication (e.g., Arthas MCP with Authorization: Bearer <token>), the connection fails because custom headers from the server config are not passed to the transport layer.

The headers field in the config is silently ignored, causing 401/403 errors for servers that require authentication.

Solution

  • src/types/config.ts: Added optional type and headers fields to HttpServerConfigSchema
  • src/core/client.ts: Read config.headers and pass them via requestInit.headers to both StreamableHTTPClientTransport and SSEClientTransport
  • Environment variable placeholders (\${VAR}) in header values are resolved automatically

Config Example

{
  "mcpServers": {
    "arthas-mcp": {
      "type": "streamableHttp",
      "url": "http://172.1.6.196:8563/mcp",
      "headers": {
        "Authorization": "Bearer \${ARTHAS_TOKEN}"
      }
    }
  }
}

Testing

Tested with Arthas MCP server (v4.1.8) which requires Bearer token authentication:

  • Before: Failed to list tools: Streamable HTTP error: Error POSTing to endpoint
  • After: arthas-mcp Connected 30 tools

mutallipp added 2 commits April 28, 2026 10:33
Pass headers from server config to StreamableHTTPClientTransport and
SSEClientTransport via requestInit. This enables authentication for
HTTP-based MCP servers (e.g. Arthas MCP) that require Authorization
or other custom headers.

Changes:
- config.ts: add optional 'type' and 'headers' fields to HttpServerConfigSchema
- client.ts: read config.headers and pass as requestInit.headers to transports
- Environment variable placeholders in header values are resolved
- detectServerType: http, sse, stdio detection
- StreamableHTTP: headers passed, no headers, env placeholder resolution, missing env error
- SSE: headers passed, no headers, env placeholder resolution
- HttpServerConfigSchema: headers/type validation, reject invalid type/non-string headers

17 new tests, all 62 tests passing.
@maplezzk
maplezzk merged commit ea8c521 into maplezzk:main Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants