Skip to content

fix(client): let auth headers override request headers#2219

Closed
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/auth-derived-headers-win
Closed

fix(client): let auth headers override request headers#2219
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/auth-derived-headers-win

Conversation

@he-yufeng
Copy link
Copy Markdown

Summary

requestInit.headers.Authorization currently wins over the transport's auth-provider token in both HTTP client transports. That makes fallback auth awkward: a stale configured Authorization header keeps overriding the fresh OAuth or bearer token even after the transport has one.

This changes the common header merge order so user request headers are still included, but derived auth/session/protocol headers win when the transport has them.

Fixes #2208.

Tests

pnpm --filter @modelcontextprotocol/client test -- test/client/streamableHttp.test.ts test/client/sse.test.ts
pnpm --filter @modelcontextprotocol/client typecheck
pnpm --filter @modelcontextprotocol/client exec eslint src/client/streamableHttp.ts src/client/sse.ts
pnpm exec prettier --check .changeset/fresh-buses-auth.md packages/client/src/client/streamableHttp.ts packages/client/src/client/sse.ts packages/client/test/client/streamableHttp.test.ts packages/client/test/client/sse.test.ts
git diff --check

The repository pre-push hook also ran successfully:

pnpm sync:snippets --check && pnpm -r lint
pnpm -r build
pnpm -r typecheck

@he-yufeng he-yufeng requested a review from a team as a code owner May 31, 2026 02:07
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 31, 2026

🦋 Changeset detected

Latest commit: 8dd696b

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

@he-yufeng
Copy link
Copy Markdown
Author

Closing this as a duplicate of #2209. I missed the existing same-topic branch during the first search; #2209 is already green and should remain the active path for #2208.

@he-yufeng he-yufeng closed this May 31, 2026
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.

One line change to enable fallback authentication

1 participant