|
| 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 | +}); |
0 commit comments