Skip to content

SDK overwrites custom Accept headers unconditionally #1646

Closed

Description

@russianoracle

Bug Report: MCP SDK Overwrites Custom Accept Headers

Summary

The MCP SDK unconditionally overwrites custom Accept headers provided in MCP server configurations, breaking API endpoints that require specific Accept header values.

Environment

  • SDK Version: 1.17.4
  • Package: @modelcontextprotocol/sdk
  • File: package/dist/esm/client/streamableHttp.js
  • Line: Variable (exact line varies by version)

Bug Description

When configuring MCP servers with custom headers (e.g., specific Accept headers for different API endpoints), the SDK overwrites these headers with its own default value:

headers.set("accept", "application/json, text/event-stream");

This happens regardless of any custom headers provided in the MCP server configuration.

Steps to Reproduce

  1. Configure an MCP server with custom Accept headers:
{
  "mcpServers": {
    "example-api": {
      "url": "https://api.example.com/mcp",
      "headers": {
        "Accept": "application/vnd.example.v1+json"
      }
    }
  }
}
  1. The SDK will overwrite the Accept header to:
    "accept": "application/json, text/event-stream"

  2. This breaks APIs that require specific Accept header values.

Expected Behavior

Custom Accept headers provided in MCP server configurations should be preserved and not overwritten by the SDK.

Actual Behavior

The SDK overwrites custom Accept headers with its own default value, breaking API compatibility.

Impact

This bug affects:

  • MCP servers that require specific Accept headers
  • Custom API integrations
  • Vision and specialized AI tools that depend on specific media types

Affected Code

File: node_modules/@modelcontextprotocol/sdk/package/dist/esm/client/streamableHttp.js

Snippet:

// This line overwrites custom Accept headers
headers.set("accept", "application/json, text/event-stream");

Proposed Solutions

Option 1: Conditionally Set Accept Header

Only set the default Accept header if none is already present:

if (!headers.has("accept")) {
  headers.set("accept", "application/json, text/event-stream");
}

Option 2: Allow Configuration Override

Add a configuration option to control whether the SDK should set default headers.

Option 3: Merge Headers

Merge SDK headers with custom headers instead of overwriting them.

Additional Context

This bug affects zai-cli and other tools that rely on MCP servers with custom Accept headers. The issue impacts vision analysis, specialized AI tools, and custom API integrations.

Related Issues

Activity

  1. russianoracle commented on Mar 8, 2026

    @russianoracle
    Author
  2. owendevereaux commented on Mar 21, 2026

    @owendevereaux

    Option 1 (if (!headers.has("accept"))) is the right fix — simple, non-breaking, and follows the principle of least surprise.

    The current behavior violates standard header semantics: user-provided configuration should take precedence over library defaults. It's unexpected that explicit config gets silently overwritten.

    I checked the code path in streamableHttp.ts — the fix is a one-liner. Happy to submit a PR if that'd be helpful.

  3. felixweinberger commented on Mar 26, 2026

    @felixweinberger
    Contributor

    The Accept header on these requests is spec-mandated. POST needs application/json, text/event-stream and GET SSE needs text/event-stream for the transport to function. Letting users replace it outright (as in #1655) would make it easy to break the connection.

    That said, if your gateway needs application/vnd.example.v1+json to route the request, an append approach could work: the SDK would send both your value and the required MCP types. The C# SDK does this.

    Could you share more about the setup? Specifically:

    • Is the custom Accept needed by a proxy/gateway in front of the MCP server, or by the MCP server itself?
    • Would Accept: application/vnd.example.v1+json, application/json, text/event-stream (both values) work for your case?
  4. nielskaspers commented on Mar 27, 2026

    @nielskaspers
    Contributor

    Thanks for the feedback @felixweinberger — the append approach makes total sense.

    To answer your questions:

    Use case: The custom Accept header is needed by API gateways/proxies sitting in front of MCP servers. For example, versioned APIs that route requests based on Accept headers (e.g. application/vnd.example.v1+json) or content negotiation layers that need to see specific media types to forward correctly. The MCP server itself still needs the standard types to function.

    Would append work? Yes — Accept: application/vnd.example.v1+json, application/json, text/event-stream is exactly what's needed. The gateway sees its required type, and the MCP transport still gets the spec-mandated types.

    I've updated #1655 to use the append approach (matching what the C# SDK does), added a changeset, and all 260 tests pass.

  5. added a commit that references this issue on Mar 28, 2026
    57d0f8e
  6. lanxevo3 commented on Mar 28, 2026

    @lanxevo3

    Fixed in PR #1804 — added conditional check so custom Accept headers are preserved instead of being unconditionally overwritten.

  7. ghost added
    bugSomething isn't working
    on Apr 1, 2026
  8. ghost added
    ready for workEnough information for someone to start working on
    on Apr 1, 2026
  9. ghost added
    P2Moderate issues affecting some users, edge cases, potentially valuable feature
    on Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Moderate issues affecting some users, edge cases, potentially valuable featurebugSomething isn't workingready for workEnough information for someone to start working on

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions