You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Separate MCP clients by resolved request headers - #1749
Remote MCP clients are cached by transport, endpoint and query parameters, but request headers are omitted. Connecting to the same endpoint with a different authorization header therefore reuses the first client's transport and cached tool catalog. A local MCP server reproduces the second identity receiving the first identity's tools.
This revisits the stale-header case from closed, unmerged #890, with a regression test and a narrower scope.
Changes
Include a SHA-256 digest of the environment-resolved headers in HTTP and SSE client cache identities. The returned ID does not contain plaintext header values.
Add one real loopback HTTP MCP regression covering distinct authorization identities and reuse of an unchanged identity.
Verification
Validated locally on Windows with Bun 1.3.14, using isolated test environment settings and fictitious authorization values. The branch is based on main c5e985410d548fbf92803fc4e9d64a9142c926a8; the affected tests, probes, static checks and builds were rerun after updating the base.
bun test common/src/mcp/__tests__/client-headers.test.ts: failed before the fix (expected who_beta, received who_alpha), passed after it.
bun test common/src/mcp/__tests__/: 47 passed, 0 failed.
TypeScript checks for common and sdk: passed.
SDK build, Windows Freebuff binary build, binary version and official binary smoke test: passed.
A separate real HTTP/SSE probe verified environment-header rotation creates distinct clients and restoring the original value reuses its client.
ESLint on both changed files: 0 errors, 5 warnings. The production file has the same three warnings as main; the new test has two resolver-environment warnings. The new test passes Prettier; the production file retains its two pre-existing formatting differences.
Notes / Scope
This changes remote cache identity only. It does not add client disposal, connection eviction, retry or replay behavior, or header-name/order canonicalization. No dependency changes. A fresh frozen-lockfile install, the full monorepo suite, Linux/macOS execution and hosted CI have not been run.
Good catch: hashConfig previously ignored headers entirely, so two MCP configs differing only by Authorization would collide on the same cached client and reuse the wrong tool catalog. The loopback HTTP regression test in client-headers.test.ts is a legitimate, specific reproduction (not just a mock), and hashing the resolved headers instead of storing plaintext is the right call for the cache key.
Two concerns before this is portable as-is:
Unhandled headers: undefined case. In client.ts, both the HTTP and SSE branches now do createHash('sha256').update(JSON.stringify(substituteEnvInRecord(config.headers))).digest('hex') unconditionally. If config.headers is undefined (the common case for configs with no auth), and substituteEnvInRecord doesn't special-case undefined, JSON.stringify may return undefined, and createHash().update(undefined) throws a TypeError. The new test only covers the headers-present case — there's no test confirming existing configs without headers still work after this change. Given this touches every remote MCP connection, that's the edge case most likely to break users in practice.
JSON.stringify is key-order-sensitive. Two functionally identical header objects with keys in different insertion order will hash differently, causing unnecessary cache misses/duplicate clients. Not a correctness bug per se (you call this out explicitly in the Notes section), but worth at least a sorted-key serialization since it's a one-line fix and avoids subtle churn.
Scope and size are fine — small, focused, in common/, with a real test. Please add a case (or confirm/fix) for the no-headers path before this is portable as a straightforward fix rather than a semi-regression.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bot:triagedClassified by the community triage botpr:needs-workRight idea, not mergeable as written
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem / Why
Remote MCP clients are cached by transport, endpoint and query parameters, but request headers are omitted. Connecting to the same endpoint with a different authorization header therefore reuses the first client's transport and cached tool catalog. A local MCP server reproduces the second identity receiving the first identity's tools.
This revisits the stale-header case from closed, unmerged #890, with a regression test and a narrower scope.
Changes
Verification
Validated locally on Windows with Bun 1.3.14, using isolated test environment settings and fictitious authorization values. The branch is based on main
c5e985410d548fbf92803fc4e9d64a9142c926a8; the affected tests, probes, static checks and builds were rerun after updating the base.bun test common/src/mcp/__tests__/client-headers.test.ts: failed before the fix (expectedwho_beta, receivedwho_alpha), passed after it.bun test common/src/mcp/__tests__/: 47 passed, 0 failed.commonandsdk: passed.Notes / Scope
This changes remote cache identity only. It does not add client disposal, connection eviction, retry or replay behavior, or header-name/order canonicalization. No dependency changes. A fresh frozen-lockfile install, the full monorepo suite, Linux/macOS execution and hosted CI have not been run.