Skip to content

Commit 0741104

Browse files
cliffhallclaude
andcommitted
fix: answer a modern strict refusal with -32021 and cover the configs (#2374 review)
SEP-2575 gives a modern request that needs an undeclared capability its own error, -32021 MissingRequiredClientCapability with data.requiredCapabilities; -32601 there claims the method does not exist. The strict fixture now throws MissingRequiredClientCapabilityError on the modern leg and keeps -32601 on legacy, which has no such code. The negative-control test now asserts the code and data per era, and a new integration test resolves both checked-in strict configs through loadConfig/resolveConfig, so a misspelled key or a dropped mapping fails instead of leaving the manual fixtures permissive. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Q3RsrgCxVoFPokLB4vAkxi Signed-off-by: cliffhall <[email protected]>
1 parent 1d765b8 commit 0741104

4 files changed

Lines changed: 149 additions & 17 deletions

File tree

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

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,34 @@ describe("Skills extension over a real transport (#2234)", () => {
143143
const connected = await connect(started.url, modern, {
144144
"io.modelcontextprotocol/skills": false,
145145
});
146-
await expect(connected.listSkills()).rejects.toThrow(
147-
/requires the client to declare io\.modelcontextprotocol\/skills/,
148-
);
149-
await expect(
146+
// The wire code is the assertion, not just the message: the two eras
147+
// name this refusal differently, and a fixture sliding back to a
148+
// semantically different error must fail here. Modern is SEP-2575's
149+
// `-32021` MissingRequiredClientCapability listing the missing
150+
// extension; legacy has no such code and stays `-32601`.
151+
const expected = modern
152+
? {
153+
code: -32021,
154+
data: {
155+
requiredCapabilities: {
156+
extensions: { "io.modelcontextprotocol/skills": {} },
157+
},
158+
},
159+
}
160+
: { code: -32601 };
161+
const refusals = [
162+
connected.listSkills(),
150163
connected.getSkill("skill://data-analysis/SKILL.md"),
151-
).rejects.toThrow(/requires the client to declare/);
152-
await expect(
153164
connected.readResourceDirectory("skill://data-analysis"),
154-
).rejects.toThrow(/requires the client to declare/);
165+
];
166+
for (const refusal of refusals) {
167+
await expect(refusal).rejects.toMatchObject({
168+
...expected,
169+
message: expect.stringMatching(
170+
/requires the client to declare io\.modelcontextprotocol\/skills/,
171+
),
172+
});
173+
}
155174
// A skill file is an ordinary resource and stays readable.
156175
const read = await connected.readResource(
157176
"skill://data-analysis/reference.md",
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import { describe, it, expect, afterEach } from "vitest";
2+
import path from "node:path";
3+
import { fileURLToPath } from "node:url";
4+
import { InspectorClient } from "@inspector/core/mcp/inspectorClient.js";
5+
import { createTransportNode } from "@inspector/core/mcp/node/transport.js";
6+
import { eraToVersionNegotiation } from "@inspector/core/mcp/types.js";
7+
import {
8+
createTestServerHttp,
9+
type TestServerHttp,
10+
loadConfig,
11+
resolveConfig,
12+
} from "@modelcontextprotocol/inspector-test-server";
13+
14+
/**
15+
* Live coverage of the two checked-in strict Skills configs (#2373) — the
16+
* documented manual reproduction of a server that enforces the client's half
17+
* of SEP-2133 negotiation.
18+
*
19+
* `inspectorClient-skills.test.ts` exercises the fixture behavior by passing
20+
* `skillsRequireClientExtension` straight to `createTestServerHttp`, so it
21+
* never touches the JSON-to-`ServerConfig` mapping. A misspelled key in either
22+
* file, or a `resolveConfig` that stopped threading the flag, would leave the
23+
* manual fixtures quietly permissive while that suite stayed green. These
24+
* tests **resolve the checked-in files** and assert the refusal they exist
25+
* for, so that class fails here instead.
26+
*/
27+
const configsDir = path.resolve(
28+
path.dirname(fileURLToPath(import.meta.url)),
29+
"../../../../../../test-servers/configs",
30+
);
31+
32+
const CONFIGS = [
33+
{ file: "skills-strict-legacy-http.json", era: "legacy" as const },
34+
{ file: "skills-strict-modern-http.json", era: "modern" as const },
35+
];
36+
37+
describe("strict Skills showcase configs (#2373)", () => {
38+
let client: InspectorClient | null = null;
39+
let server: TestServerHttp | null = null;
40+
41+
afterEach(async () => {
42+
if (client) {
43+
try {
44+
await client.disconnect();
45+
} catch {
46+
// ignore
47+
}
48+
client = null;
49+
}
50+
if (server) {
51+
try {
52+
await server.stop();
53+
} catch {
54+
// ignore
55+
}
56+
server = null;
57+
}
58+
});
59+
60+
for (const { file, era } of CONFIGS) {
61+
describe(file, () => {
62+
const configPath = path.join(configsDir, file);
63+
64+
it("resolves with the strict flag, skills, and its era intact", () => {
65+
const resolved = resolveConfig(loadConfig(configPath));
66+
expect(resolved.skills).toBe(true);
67+
expect(resolved.skillsRequireClientExtension).toBe(true);
68+
// One file per era is the documented contract: a legacy client
69+
// reaching a modern server is served statelessly and cannot be
70+
// checked, so the legacy file must not turn the modern leg on.
71+
expect(resolved.modern !== undefined).toBe(era === "modern");
72+
});
73+
74+
it("refuses skills/list to a client that did not declare the extension", async () => {
75+
// The harness picks the port rather than the config's fixed one, so
76+
// this cannot collide with a showcase server someone runs by hand.
77+
const resolved = resolveConfig(loadConfig(configPath));
78+
const started = createTestServerHttp({ ...resolved, port: undefined });
79+
await started.start();
80+
server = started;
81+
82+
const connected = new InspectorClient(
83+
{ type: "streamable-http", url: started.url },
84+
{
85+
environment: { transport: createTransportNode },
86+
versionNegotiation: eraToVersionNegotiation(era),
87+
advertisedExtensions: { "io.modelcontextprotocol/skills": false },
88+
},
89+
);
90+
await connected.connect();
91+
client = connected;
92+
expect(connected.getProtocolEra()).toBe(era);
93+
94+
await expect(connected.listSkills()).rejects.toMatchObject({
95+
code: era === "modern" ? -32021 : -32601,
96+
});
97+
});
98+
});
99+
}
100+
});

‎docs/test-servers.md‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,13 @@ declaration and passed against this fixture regardless
8686
([#2373](https://github.com/modelcontextprotocol/inspector/issues/2373)).
8787
`skills-strict-legacy-http.json` (port 3232) and
8888
`skills-strict-modern-http.json` (port 3233) add
89-
`"skillsRequireClientExtension": true`, which answers `skills/list`,
90-
`skills/get` and `resources/directory/read` with `-32601` unless the client
91-
declared it (skill files still come through ordinary `resources/read`, which
92-
needs no extension). ⚠️ **Connect each with its own era.** A modern request
89+
`"skillsRequireClientExtension": true`, which refuses `skills/list`,
90+
`skills/get` and `resources/directory/read` unless the client declared it
91+
(skill files still come through ordinary `resources/read`, which needs no
92+
extension). The refusal differs by era: a **modern** request gets SEP-2575's
93+
`-32021` MissingRequiredClientCapability (HTTP 400) with the Skills extension
94+
under `data.requiredCapabilities`; a **legacy** one, whose era has no such code,
95+
gets `-32601`. ⚠️ **Connect each with its own era.** A modern request
9396
carries the declaration in its `_meta` envelope; a legacy one relies on what
9497
`initialize` declared, which only a stateful legacy server keeps. A legacy
9598
client reaching the modern file is served statelessly, holds no declaration,

‎test-servers/src/skills.ts‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import { createHash } from "node:crypto";
6060
import * as z from "zod/v4";
6161
import {
6262
CLIENT_CAPABILITIES_META_KEY,
63+
MissingRequiredClientCapabilityError,
6364
ProtocolError,
6465
ProtocolErrorCode,
6566
type McpServer,
@@ -747,15 +748,24 @@ function assertClientDeclaredSkills(
747748
method: string,
748749
envelope: ReceivedEnvelope,
749750
): void {
751+
const modernCapabilities = envelope?.[CLIENT_CAPABILITIES_META_KEY];
750752
const capabilities =
751-
envelope?.[CLIENT_CAPABILITIES_META_KEY] ??
752-
mcpServer.server.getClientCapabilities();
753-
if (!hasSkillsExtension(capabilities)) {
754-
throw new ProtocolError(
755-
ProtocolErrorCode.MethodNotFound,
756-
`${method} requires the client to declare ${SKILLS_EXTENSION_KEY} in its capabilities`,
753+
modernCapabilities ?? mcpServer.server.getClientCapabilities();
754+
if (hasSkillsExtension(capabilities)) return;
755+
const message = `${method} requires the client to declare ${SKILLS_EXTENSION_KEY} in its capabilities`;
756+
// The two eras name this refusal differently. SEP-2575 gives a modern
757+
// request that needs an undeclared capability its own code, `-32021`
758+
// MissingRequiredClientCapability (HTTP 400), carrying the missing
759+
// capabilities in `data.requiredCapabilities` so the client can see what to
760+
// declare. `-32601` there would claim the method does not exist. The legacy
761+
// era has no such code, so a legacy refusal stays `-32601`.
762+
if (modernCapabilities !== undefined) {
763+
throw new MissingRequiredClientCapabilityError(
764+
{ requiredCapabilities: { extensions: { [SKILLS_EXTENSION_KEY]: {} } } },
765+
message,
757766
);
758767
}
768+
throw new ProtocolError(ProtocolErrorCode.MethodNotFound, message);
759769
}
760770

761771
/**

0 commit comments

Comments
 (0)