-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
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
- Configure an MCP server with custom Accept headers:
{
"mcpServers": {
"example-api": {
"url": "https://api.example.com/mcp",
"headers": {
"Accept": "application/vnd.example.v1+json"
}
}
}
}-
The SDK will overwrite the Accept header to:
"accept": "application/json, text/event-stream" -
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.