Skip to content

fix: preserve custom Accept headers instead of unconditionally overwriting#1697

Closed
ghost wants to merge 2 commits intomainfrom
unknown repository
Closed

fix: preserve custom Accept headers instead of unconditionally overwriting#1697
ghost wants to merge 2 commits intomainfrom
unknown repository

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Mar 17, 2026

Problem

The SDK unconditionally overwrites Accept headers using headers.set(), discarding any custom values provided via requestInit.headers. This breaks MCP servers behind APIs that require specific Accept header values.

{
  "mcpServers": {
    "example-api": {
      "url": "https://api.example.com/mcp",
      "headers": {
        "Accept": "application/vnd.example.v1+json"
      }
    }
  }
}

The custom Accept header is overwritten with application/json, text/event-stream.

Fix

Check headers.has('Accept') before setting the default value. Custom Accept headers from requestInit.headers are preserved; the SDK default is only applied when no Accept header was provided.

Fixed in both transports:

  • packages/client/src/client/streamableHttp.ts (GET SSE + POST)
  • packages/client/src/client/sse.ts

Fixes #1646

…iting

The SDK unconditionally overwrites Accept headers with headers.set(),
discarding any custom Accept values provided via requestInit.headers.
This breaks APIs that require specific Accept header values.

Now checks headers.has('Accept') before setting the default value,
preserving user-provided Accept headers in both Streamable HTTP and
SSE transports.

Fixes #1646
@ghost ghost self-requested a review as a code owner March 17, 2026 19:27
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 17, 2026

🦋 Changeset detected

Latest commit: 0a586a2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@modelcontextprotocol/client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 17, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@1697

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@1697

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@1697

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@1697

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@1697

commit: 0a586a2

@ghost ghost closed this by deleting the head repository Mar 26, 2026
This pull request was closed.
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.

SDK overwrites custom Accept headers unconditionally

0 participants