Repository navigation
feat(web): mirror SEP-2792 _meta acceptLanguage to upstream Accept-Language - #2988
Conversation
…nguage The web backend now derives the upstream Accept-Language header from each message's own params._meta["io.modelcontextprotocol/acceptLanguage"], so a preference set through the generic Request Metadata editor reaches a Streamable HTTP server on both carriers, exactly equal as SEP-2792 requires. The client-supplied per-send header channel stays restricted to Mcp-Param-*; the language header is never taken from the browser. The mirror overrides a configured Accept-Language, and a value HTTP cannot carry byte-for-byte is not mirrored. Adds a language-preference-http.json showcase server with a localized_greeting tool that reports the _meta value and header it received, flags a HeaderMismatch, and returns contentLanguage in result _meta; the composable server now forwards a handler's isError and result _meta. Covered by unit tests, real-transport e2e through the remote backend, and fixture tests, with a demo guide in docs/test-servers.md. Closes #2979 Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
The language lookup accepts inherited properties such as constructor, allowing unsupported inputs to bypass the English fallback and produce invalid greetings and contentLanguage values.
1 open issue
What changed in this PR
Adds SEP-2792 language-preference support to the Web Inspector’s upstream HTTP requests, reusing the existing Request Metadata setting without adding UI. CLI and TUI support remains tracked separately in #2987.
Changes:
- Derives
Accept-Languagefrom request metadata, preserving exact values and the existing browser-header allowlist. - Adds a localized greeting showcase with mismatch reporting and result language metadata.
- Adds focused unit and real-transport coverage, plus a demo guide.
| File | Description |
|---|---|
test-servers/src/test-server-fixtures.ts |
Adds language selection and the localized greeting fixture. |
test-servers/src/preset-registry.ts |
Registers the localized greeting preset. |
test-servers/src/composable-test-server.ts |
Exposes request headers and preserves handler errors and result metadata. |
test-servers/configs/language-preference-http.json |
Configures the HTTP language-preference showcase. |
docs/test-servers.md |
Documents the showcase and current client limitations. |
core/mcp/remote/node/server.ts |
Combines derived language headers with allowlisted per-send headers. |
core/mcp/acceptLanguage.ts |
Defines language keys and exact-value header derivation. |
clients/web/src/test/integration/mcp/remote/transport.test.ts |
Tests upstream mirroring and configured-header replacement. |
clients/web/src/test/integration/mcp/remote/server-extra-coverage.test.ts |
Tests header merging and browser-channel filtering. |
clients/web/src/test/integration/mcp/localized-greeting-fixture.test.ts |
Tests fixture negotiation, mismatches, and explicit overrides. |
clients/web/src/test/core/mcp/acceptLanguage.test.ts |
Tests metadata extraction and accepted or rejected header values. |
Review effort: Balanced
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
|
Copilot round 1: one finding, fixed in a1b9929. The greeting fixture's language lookup used |
|
Copilot review loop closed: round 2 came back clean (approval recommended, no inline comments, nothing suppressed), and the round-1 finding is marked resolved. |

Closes #2979
What changed
The web backend now mirrors the SEP-2792 language preference: each upstream Streamable HTTP request whose
params._meta["io.modelcontextprotocol/acceptLanguage"]is set carriesAccept-Languagewith exactly that string. SEP-2792 lets a server reject a present header that differs from_meta(400/HeaderMismatch).core/mcp/acceptLanguage.ts(new): the SEP keys, plusacceptLanguageHeaderFor(message), which derives the header from the message's own_meta. It only mirrors a value HTTP can carry unchanged: visible ASCII with no surrounding whitespace, becauseHeaderswould trim it and break exact equality.core/mcp/remote/node/server.ts:upstreamSendHeaders()combines the existingMcp-Param-*allowlist with the derived language header on/api/mcp/send. The allowlist is unchanged.Accept-Languageis never accepted from the browser's header channel, only derived from the body it has to agree with. The per-send header also replaces anAccept-Languageconfigured in the server's custom headers; sending both would be the mismatch the SEP forbids.tools/listincluded, which is what the SEP's "send it on every request" asks for.Showcase server and guide
test-servers/configs/language-preference-http.json(port 3240) serves a newlocalized_greetingpreset. It answers in en/es/fr/de/ja (RFC 4647 lookup inqorder, English fallback), reports the_metavalue and theAccept-Languageheader it actually received, returnscontentLanguagein the result_meta, flags a mismatch as anisErrorHeaderMismatch, and lets an explicitlanguageargument override the preference.isErrorand result_metathrough; until now it dropped both. No existing fixture returned either.docs/test-servers.md, with a row in the showcase table.Tests
clients/web/src/test/core/mcp/acceptLanguage.test.ts: values that are mirrored and values that are refused.server-extra-coverage.test.ts:upstreamSendHeadersmerging, and that a client-suppliedAccept-Languageis ignored.transport.test.ts: real transport, browser client → remote backend → Streamable HTTP server. One case checks that the fixture answersBonjourand that the upstreamtools/listandtools/callPOSTs both carry the exact value. The other checks that the mirror replaces a configuredAccept-Languagewhile the other configured headers still arrive.localized-greeting-fixture.test.ts: the fixture's agreement, mismatch, header-only and explicit-argument paths, plus the language selection.npm run local:gatepasses.Out of scope: CLI and TUI (#2987)
Node's
fetchsendsAccept-Language: *on any request that has none. The CLI and TUI connect without the backend, so they don't mirror, and a preference set there arrives next to*. A strict server rejects that. #2987 tracks it, and a fixture test records the current behavior.Screenshots
The UI is unchanged; these show the new behavior in the running web client against
language-preference-http.json. Request Metadata is set to{ "io.modelcontextprotocol/acceptLanguage": "fr-CA, en;q=0.5" }.Network monitor,
tools/callentry expanded. The upstream POST carriesaccept-language: fr-CA, en;q=0.5, exactly equal toparams._meta["io.modelcontextprotocol/acceptLanguage"]in the request body below it. The tools columns are squeezed because the monitor sidebar is set to its 720px maximum so no header row truncates.Tool result. The server answered in French, reports identical
_metaand header values, and selectedContent-Language: fr.🤖 Generated with Claude Code