Skip to content

SDK overwrites custom Accept headers unconditionally #1646

@russianoracle

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions