Skip to content

feat(web): mirror SEP-2792 _meta acceptLanguage to upstream Accept-Language - #2988

Merged
cliffhall merged 2 commits into
v2/mainfrom
v2/feat/2979-accept-language-meta
Nov 18, 2026
Merged

cliffhall merged 2 commits into
v2/mainfrom
v2/feat/2979-accept-language-meta

Conversation

@cliffhall

@cliffhall cliffhall commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

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 carries Accept-Language with 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, plus acceptLanguageHeaderFor(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, because Headers would trim it and break exact equality.
  • core/mcp/remote/node/server.ts: upstreamSendHeaders() combines the existing Mcp-Param-* allowlist with the derived language header on /api/mcp/send. The allowlist is unchanged. Accept-Language is never accepted from the browser's header channel, only derived from the body it has to agree with. The per-send header also replaces an Accept-Language configured in the server's custom headers; sending both would be the mismatch the SEP forbids.
  • No new UI. The existing Request Metadata setting already stamps its keys on every request, tools/list included, 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 new localized_greeting preset. It answers in en/es/fr/de/ja (RFC 4647 lookup in q order, English fallback), reports the _meta value and the Accept-Language header it actually received, returns contentLanguage in the result _meta, flags a mismatch as an isError HeaderMismatch, and lets an explicit language argument override the preference.
  • The composable test server now passes a handler's isError and result _meta through; until now it dropped both. No existing fixture returned either.
  • Demo guide: Language preferences (SEP-2792) in 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: upstreamSendHeaders merging, and that a client-supplied Accept-Language is ignored.
  • transport.test.ts: real transport, browser client → remote backend → Streamable HTTP server. One case checks that the fixture answers Bonjour and that the upstream tools/list and tools/call POSTs both carry the exact value. The other checks that the mirror replaces a configured Accept-Language while 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:gate passes.

Out of scope: CLI and TUI (#2987)

Node's fetch sends Accept-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/call entry expanded. The upstream POST carries accept-language: fr-CA, en;q=0.5, exactly equal to params._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.

Network monitor: tools/call request headers show accept-language fr-CA, en;q=0.5 and the request body _meta carries the same value

Tool result. The server answered in French, reports identical _meta and header values, and selected Content-Language: fr.

localized_greeting result: Bonjour, world! with matching _meta acceptLanguage and Accept-Language header, Content-Language fr

🤖 Generated with Claude Code

…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]>
@cliffhall cliffhall added the v2 Issues and PRs for v2 label Nov 18, 2026
@cliffhall cliffhall linked an issue Nov 18, 2026 that may be closed by this pull request
2 tasks done
@cliffhall
cliffhall requested a balanced review from Copilot November 18, 2026 05:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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-Language from 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

@cliffhall

Copy link
Copy Markdown
Member Author

Copilot round 1: one finding, fixed in a1b9929. The greeting fixture's language lookup used in, which matched inherited keys such as constructor. It now uses Object.hasOwn, and the test cases cover those keys. Nothing was in the Suppressed comments block. Requesting round 2.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the language-preference support change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@cliffhall

Copy link
Copy Markdown
Member Author

Copilot review loop closed: round 2 came back clean (approval recommended, no inline comments, nothing suppressed), and the round-1 finding is marked resolved.

@cliffhall
cliffhall merged commit 827d8ab into v2/main Nov 18, 2026
14 checks passed
@cliffhall
cliffhall deleted the v2/feat/2979-accept-language-meta branch November 18, 2026 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Issues and PRs for v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support SEP-2792 language preferences in Web Inspector

2 participants