Skip to content

fix(client): preserve user-supplied Accept header instead of overwriting unconditionally#1804

Open
lanxevo3 wants to merge 3 commits intomodelcontextprotocol:mainfrom
lanxevo3:fix/custom-accept-header
Open

fix(client): preserve user-supplied Accept header instead of overwriting unconditionally#1804
lanxevo3 wants to merge 3 commits intomodelcontextprotocol:mainfrom
lanxevo3:fix/custom-accept-header

Conversation

@lanxevo3
Copy link
Copy Markdown

Custom Accept headers set in MCP server configuration were unconditionally overwritten with 'application/json, text/event-stream', breaking APIs that require specific Accept values.

Before: \headers.set('accept', 'application/json, text/event-stream')\ (always overwrites)

After: Only sets the default Accept header when no Accept header has already been supplied by the caller:

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

The SSE GET channel Accept header is unaffected — it must always be 'text/event-stream'.

Fixes #1646.

OAuth 2.1 §3.2 requires token endpoint requests to use
application/x-www-form-urlencoded regardless of grant type.

Add an explicit header.set() call immediately before the fetch in
executeTokenRequest() to prevent any addClientAuthentication
implementation from accidentally overriding the Content-Type.

Fixes modelcontextprotocol/inspector#1160
…ing unconditionally

Custom Accept headers set in MCP server configuration (e.g.
'application/vnd.example.v1+json') were unconditionally overwritten
with 'application/json, text/event-stream', breaking APIs that require
specific Accept values.

Now only sets the default Accept header when no Accept header has
already been supplied by the caller. The SSE GET channel Accept header
is unaffected since it must always be 'text/event-stream'.

Fixes modelcontextprotocol#1646.
@lanxevo3 lanxevo3 requested a review from a team as a code owner March 28, 2026 16:21
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 28, 2026

⚠️ No Changeset found

Latest commit: 57d0f8e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 28, 2026

Open in StackBlitz

@modelcontextprotocol/client

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

@modelcontextprotocol/server

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

@modelcontextprotocol/express

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: 57d0f8e

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

1 participant