Skip to content

Commit a4ee2ec

Browse files
cliffhallclaude
andcommitted
review: mirror Mcp-Param-* on the task-augmented tools/call too
Address the maintainer review on #1847: - `callToolStream` (the "Run as task" path) built its own request options and never mirrored, so a task-augmented `tools/call` on an annotated tool was still rejected by a strict modern server with -32020. It now mirrors like the plain path. - Extract the two blocks both `tools/call` entry points had duplicated — `convertStringToolArgs` (the string-arg coercion) and `applyMirroredParamHeaders` (the SEP-2243 mirroring) — so the paths can't drift again. That duplication is why the task path was missed. - Regression test: `callToolStream` against the modern `get_weather` server asserts the POST carries `Mcp-Param-City` (verified failing without the fix). - README: the modern-network showcase claimed mirroring is skipped in the browser so the web client gets -32020, and that CLI/TUI mirror. Both are now wrong — the Inspector mirrors itself, on every client. AGENTS: note that xMcpHeader.ts now also builds the wire headers. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01UkhhCHryVp5H3dqEnhwZ7t
1 parent c608f27 commit a4ee2ec

4 files changed

Lines changed: 77 additions & 38 deletions

File tree

‎AGENTS.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ inspector/
3939
│ ├── json/ # JSON utilities and parameter/argument conversion
4040
│ │ # (xMcpHeader.ts: SEP-2243 `x-mcp-header`
4141
│ │ # annotation scan/validation + mirrored-param
42-
│ │ # derivation, used by the Tools tab — #1632)
42+
│ │ # derivation, used by the Tools tab — #1632;
43+
│ │ # plus `Mcp-Param-*` header building for the
44+
│ │ # wire, used by both `tools/call` paths — #1846)
4345
│ ├── logging/ # Silent pino logger singleton
4446
│ ├── mcp/ # InspectorClient runtime + state stores
4547
│ │ # (modernTaskSchemas.ts: SEP-2663 modern Tasks

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ The Vite alias `@modelcontextprotocol/inspector-test-server` (in `clients/web/vi
113113

114114
A streamable-HTTP server can also serve the **modern (2026-07-28) protocol era** via the SDK's `createMcpHandler` — set `transport.modern` in the JSON config (`true` for dual-era stateless serving, or `{ "legacy": "reject" }` for modern-only strict), or pass `modern` on the `ServerConfig` for an in-process `createTestServerHttp`. This is what lets an Inspector connection negotiating `protocolEra: "auto" | "modern"` reach the modern leg (populated `server/discover`, sessionless). See `test-servers/configs/modern-http.json`. `test-servers/configs/modern-mrtr-http.json` additionally serves the `mrtr_confirm` tool (preset `mrtr_confirm`, `createMrtrTool`) over the modern leg: its handler returns `inputRequired(...)` embedding a form elicitation, so invoking it produces a real MRTR round-trip (`input_required` → the client fulfils the embedded elicitation and retries with a new id → `complete`). The Inspector drives MRTR manually (`inputRequired: { autoFulfill: false }`), so the embedded elicitation pauses at the pending-request modal (tagged "input_required") for you to answer, then the retry completes — useful for eyeballing both that pending-request UX and the Protocol view's MRTR conversation grouping. `test-servers/configs/mrtr-showcase-http.json` bundles every MRTR preset in one modern server for manual testing: `mrtr_confirm` (single round), `mrtr_two_step` (two elicitation rounds via `requestState`), `mrtr_sample` (embedded sampling → the Sampling panel), `mrtr_roots` (embedded `roots/list`, auto-answered silently from configured roots — no modal), `mrtr_edge` (an `inputRequests`-only round then a `requestState`-only round), and `mrtr_loop` (never completes → the `MRTR_MAX_ROUNDS` bound trips). (The legacy `collect_elicitation` preset calls `server.elicitInput`, which errors on the 2026-07-28 leg — server→client requests aren't allowed there; MRTR is the modern replacement.)
115115

116-
`test-servers/configs/modern-network-http.json` is the **Network-tab showcase** for the standardized HTTP headers and new error taxonomy (SEP-2243 / SEP-2575). It serves a `get_weather` tool whose `city` argument carries an `x-mcp-header: "City"` annotation (so a modern client mirrors it to `Mcp-Param-City`), plus four `trigger_*` tools that the modern leg's spec-error injector (`transport.modern.injectSpecErrors: true`) answers with a real HTTP status + JSON-RPC error body: `trigger_header_mismatch` → `400 / -32020`, `trigger_missing_capability` → `400 / -32021`, `trigger_unsupported_version` → `400 / -32022` (with `data.supported`), `trigger_method_not_found` → `404 / -32601`. Connect to it with **Protocol Era = Modern** and open the Network tab to see the mirrored `Mcp-*` headers highlighted, sentinel values decoded, and each error rendered distinctly. Note: `Mcp-Param-*` mirroring is **skipped by the SDK in the browser** (`detectProbeEnvironment() !== "browser"`), so calling `get_weather` from the **web** client omits `Mcp-Param-City` and the strict server answers `-32020` — the same tool is callable from the Node CLI/TUI, where mirroring is active.
116+
`test-servers/configs/modern-network-http.json` is the **Network-tab showcase** for the standardized HTTP headers and new error taxonomy (SEP-2243 / SEP-2575). It serves a `get_weather` tool whose `city` argument carries an `x-mcp-header: "City"` annotation (so a modern client mirrors it to `Mcp-Param-City`), plus four `trigger_*` tools that the modern leg's spec-error injector (`transport.modern.injectSpecErrors: true`) answers with a real HTTP status + JSON-RPC error body: `trigger_header_mismatch` → `400 / -32020`, `trigger_missing_capability` → `400 / -32021`, `trigger_unsupported_version` → `400 / -32022` (with `data.supported`), `trigger_method_not_found` → `404 / -32601`. Connect to it with **Protocol Era = Modern** and open the Network tab to see the mirrored `Mcp-*` headers highlighted, sentinel values decoded, and each error rendered distinctly. Note: the SDK only mirrors `Mcp-Param-*` inside `client.callTool()`, and skips it in the browser (`detectProbeEnvironment() !== "browser"`). The Inspector routes `tools/call` through `client.request()` to drive MRTR manually, so it builds the mirrored headers itself (#1846) — on **every** client, web included, since the web client's upstream request is issued by the Node backend rather than the browser. So `get_weather` is callable from web, CLI, and TUI alike, in both the plain and "Run as task" forms.
117117

118118
`test-servers/configs/xmcpheader-modern-http.json` is the **`x-mcp-header` Tools-tab showcase** (#1632). It serves `echo`, a `get_weather` tool with a **valid** `x-mcp-header: "City"` annotation on its `city` argument, an `invalid_header_tool` whose annotation uses the header name `"Bad Header"` (a space makes it an invalid RFC 9110 token, so the whole tool definition is invalid), and a `trigger_invalid_params` tool that the modern leg's spec-error injector (`transport.modern.injectSpecErrors: true`) answers with a real `-32602 Invalid params` JSON-RPC error whose message is not about a missing tool. Connect with **Protocol Era = Modern** and open the Tools tab: `get_weather`'s detail panel shows a **"Mirrored request headers (SEP-2243)"** section (`city → Mcp-Param-City`), and `invalid_header_tool` appears struck-through under an **"Excluded (SEP-2243)"** divider in the sidebar with the reason on hover (a conforming Streamable HTTP client MUST drop it from `tools/list`; the Inspector surfaces _why_). Under SDK v2 a `tools/call` that rejects with **`-32602`** now renders as a distinct error panel rather than an `isError` result — headed **"Unknown Tool"** when the message names a missing tool (reproduce by calling a tool the server dropped from its list), or **"Invalid Parameters"** for any other `-32602` (run `trigger_invalid_params`).
119119

‎clients/web/src/test/integration/mcp/inspectorClient-xmcpheader-mirroring.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,27 @@ describe("x-mcp-header Mcp-Param-* mirroring on tools/call", () => {
118118
expect(sent.get("Mcp-Param-City")).toBe("London");
119119
});
120120

121+
it("mirrors on the task-augmented tools/call too (callToolStream)", async () => {
122+
// The "Run as task" path builds its own request options, so it needs the
123+
// same mirroring — a strict modern server rejects the task-augmented
124+
// `tools/call` with -32020 when the header is missing, exactly as it does
125+
// the plain one.
126+
const started = await startWeatherServer();
127+
const spy = makeSpyFetch();
128+
const connected = await connectModern(started.url, spy.fetch);
129+
130+
const result = await connected.callToolStream(
131+
await weatherTool(connected),
132+
{ city: "London" },
133+
undefined,
134+
undefined,
135+
{ ttl: 60_000 },
136+
);
137+
138+
expect(result.success).toBe(true);
139+
expect(spy.toolCallHeaders.at(-1)!.get("Mcp-Param-City")).toBe("London");
140+
});
141+
121142
it("sends no Mcp-Param-* header for a tool without annotations", async () => {
122143
const started = await startWeatherServer();
123144
const spy = makeSpyFetch();

‎core/mcp/inspectorClient.ts‎

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3307,6 +3307,52 @@ export class InspectorClient extends InspectorClientEventTarget {
33073307
}
33083308
}
33093309

3310+
/**
3311+
* Coerce the string-valued entries of a tool's arguments to the types its
3312+
* `inputSchema` declares (the Tools form hands everything over as text).
3313+
* Shared by the two `tools/call` entry points — {@link attemptToolCall} and
3314+
* {@link callToolStream} — so both put the SAME arguments on the wire.
3315+
*/
3316+
private convertStringToolArgs(
3317+
tool: Tool,
3318+
args: Record<string, JsonValue>,
3319+
): Record<string, JsonValue> {
3320+
const stringArgs: Record<string, string> = {};
3321+
for (const [key, value] of Object.entries(args)) {
3322+
if (typeof value === "string") {
3323+
stringArgs[key] = value;
3324+
}
3325+
}
3326+
if (Object.keys(stringArgs).length === 0) return args;
3327+
return { ...args, ...convertToolParameters(tool, stringArgs) };
3328+
}
3329+
3330+
/**
3331+
* SEP-2243: mirror `x-mcp-header`-annotated arguments into `Mcp-Param-*`
3332+
* headers on a modern connection. The SDK only does this inside
3333+
* `client.callTool()` (and skips it in the browser), but we route
3334+
* `tools/call` through `client.request()` for manual MRTR driving (#1704), so
3335+
* we mirror ourselves. `Protocol.request` forwards `headers` (preserved
3336+
* across MRTR retry legs) to the transport, and the remote transport relays
3337+
* them to the backend's upstream send — issued server-side, where the browser
3338+
* skip doesn't apply. No-op on legacy/stdio (no annotations).
3339+
*
3340+
* Applied by BOTH `tools/call` entry points: a plain call
3341+
* ({@link attemptToolCall}) and a task-augmented one
3342+
* ({@link callToolStream}) — a strict modern server rejects either with
3343+
* `-32020` when the mirrored header is missing.
3344+
*/
3345+
private applyMirroredParamHeaders(
3346+
tool: Tool,
3347+
convertedArgs: Record<string, JsonValue>,
3348+
requestOptions: RequestOptions,
3349+
): void {
3350+
if (this.protocolEra !== "modern") return;
3351+
const paramHeaders = mcpParamHeadersForTool(tool, convertedArgs);
3352+
if (Object.keys(paramHeaders).length === 0) return;
3353+
requestOptions.headers = { ...requestOptions.headers, ...paramHeaders };
3354+
}
3355+
33103356
/**
33113357
* Run a single tools/call attempt: convert args, issue the request, validate,
33123358
* and return a successful {@link ToolCallInvocation}. Throws on any error
@@ -3329,17 +3375,7 @@ export class InspectorClient extends InspectorClientEventTarget {
33293375
if (!client) {
33303376
throw new Error("Client is not connected");
33313377
}
3332-
let convertedArgs: Record<string, JsonValue> = args;
3333-
const stringArgs: Record<string, string> = {};
3334-
for (const [key, value] of Object.entries(args)) {
3335-
if (typeof value === "string") {
3336-
stringArgs[key] = value;
3337-
}
3338-
}
3339-
if (Object.keys(stringArgs).length > 0) {
3340-
const convertedStringArgs = convertToolParameters(tool, stringArgs);
3341-
convertedArgs = { ...args, ...convertedStringArgs };
3342-
}
3378+
const convertedArgs = this.convertStringToolArgs(tool, args);
33433379

33443380
// Merge general metadata with tool-specific metadata; tool-specific wins.
33453381
const callMetadata: Record<string, string> | undefined =
@@ -3370,20 +3406,7 @@ export class InspectorClient extends InspectorClientEventTarget {
33703406
metadata?.progressToken,
33713407
signal,
33723408
);
3373-
// SEP-2243: mirror `x-mcp-header`-annotated arguments into `Mcp-Param-*`
3374-
// headers on a modern connection. The SDK only does this inside
3375-
// `client.callTool()` (and skips it in the browser), but we route
3376-
// `tools/call` through `client.request()` for manual MRTR driving (#1704),
3377-
// so we mirror ourselves. `Protocol.request` forwards `headers` (preserved
3378-
// across MRTR retry legs) to the transport, and the remote transport relays
3379-
// them to the backend's upstream send — issued server-side, where the
3380-
// browser skip doesn't apply. No-op on legacy/stdio (no annotations).
3381-
if (this.protocolEra === "modern") {
3382-
const paramHeaders = mcpParamHeadersForTool(tool, convertedArgs);
3383-
if (Object.keys(paramHeaders).length > 0) {
3384-
requestOptions.headers = { ...requestOptions.headers, ...paramHeaders };
3385-
}
3386-
}
3409+
this.applyMirroredParamHeaders(tool, convertedArgs, requestOptions);
33873410
// Route through the MRTR driver (`requestWithInputRequired`) so a modern
33883411
// `input_required` result pauses at the pending-request UI and retries with
33893412
// the user's answer (#1704). Both eras use `client.request` with
@@ -3966,17 +3989,7 @@ export class InspectorClient extends InspectorClientEventTarget {
39663989
throw new Error("Client is not connected");
39673990
}
39683991
try {
3969-
let convertedArgs: Record<string, JsonValue> = args;
3970-
const stringArgs: Record<string, string> = {};
3971-
for (const [key, value] of Object.entries(args)) {
3972-
if (typeof value === "string") {
3973-
stringArgs[key] = value;
3974-
}
3975-
}
3976-
if (Object.keys(stringArgs).length > 0) {
3977-
const convertedStringArgs = convertToolParameters(tool, stringArgs);
3978-
convertedArgs = { ...args, ...convertedStringArgs };
3979-
}
3992+
const convertedArgs = this.convertStringToolArgs(tool, args);
39803993

39813994
// Merge general metadata with tool-specific metadata; tool-specific wins.
39823995
const callMetadata: Record<string, string> | undefined =
@@ -4016,6 +4029,9 @@ export class InspectorClient extends InspectorClientEventTarget {
40164029
// emit requestorTaskProgress) for task calls only, bypassing the toggle
40174030
// that governs every other call path.
40184031
const requestOptions = this.getRequestOptions(metadata?.progressToken);
4032+
// The task-augmented `tools/call` needs the same SEP-2243 mirroring as the
4033+
// plain one — a strict modern server rejects it with -32020 otherwise.
4034+
this.applyMirroredParamHeaders(tool, convertedArgs, requestOptions);
40194035
if (this.progress) {
40204036
const innerOnProgress = requestOptions.onprogress;
40214037
requestOptions.onprogress = (progress: Progress) => {

0 commit comments

Comments
 (0)