From bd0f315f02c547756cfcedaa738467bec6ea90d3 Mon Sep 17 00:00:00 2001 From: King Star Date: Thu, 19 Nov 2026 17:59:42 +0000 Subject: [PATCH 1/2] fix(client): skip elicitation-sep1034-defaults for clients without the capability Elicitation is an optional client capability in 2025-11-25. The scenario previously sent elicitation/create unconditionally, so a client that legitimately declined to declare elicitation failed all six checks with -32601. Read capabilities from initialize: when elicitation is absent the tool returns without eliciting and every check reports SKIPPED; a client that does declare it is still scored (and still fails if it rejects). This fixes #584 --- .../client/elicitation-defaults.test.ts | 112 +++++++++++++++ src/scenarios/client/elicitation-defaults.ts | 134 +++++++++++++++++- 2 files changed, 244 insertions(+), 2 deletions(-) create mode 100644 src/scenarios/client/elicitation-defaults.test.ts diff --git a/src/scenarios/client/elicitation-defaults.test.ts b/src/scenarios/client/elicitation-defaults.test.ts new file mode 100644 index 00000000..63fa2959 --- /dev/null +++ b/src/scenarios/client/elicitation-defaults.test.ts @@ -0,0 +1,112 @@ +/** + * Capability gating for `elicitation-sep1034-client-defaults` (issue #584). + * + * Elicitation is an optional client capability at 2025-11-25. A client that + * negotiates without it must not be sent `elicitation/create`; its checks + * are SKIPPED, not failed. A client that does declare it is still scored. + */ +import { describe, test, expect, afterEach } from 'vitest'; +import { Client } from '@modelcontextprotocol/sdk/client/index.js'; +import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'; +import type { ConformanceCheck, Scenario } from '../../types'; +import { testScenarioContext } from '../../mock-server/testing'; +import { getScenario } from '../index'; + +const SCENARIO_NAME = 'elicitation-sep1034-client-defaults'; +const ELICITATION_CHECK_PREFIX = 'client-elicitation-sep1034-'; + +const DEFAULT_SLUGS = [ + 'client-elicitation-sep1034-string-default', + 'client-elicitation-sep1034-integer-default', + 'client-elicitation-sep1034-number-default', + 'client-elicitation-sep1034-enum-default', + 'client-elicitation-sep1034-boolean-default' +]; + +let scenario: Scenario | undefined; + +afterEach(async () => { + await scenario?.stop(); + scenario = undefined; +}); + +/** + * Drive `runClient` against the scenario in-process, the way the + * everything-client would be spawned against it, and return the checks. + */ +async function runAgainst( + runClient: (serverUrl: string) => Promise +): Promise { + scenario = getScenario(SCENARIO_NAME); + if (!scenario) { + throw new Error(`Scenario not found: ${SCENARIO_NAME}`); + } + const urls = await scenario.start(testScenarioContext()); + try { + await runClient(urls.serverUrl); + } finally { + await scenario.stop(); + } + return scenario.getChecks(); +} + +async function runClientWithoutElicitation(serverUrl: string): Promise { + const client = new Client( + { name: 'no-elicitation-test-client', version: '1.0.0' }, + { capabilities: {} } + ); + const transport = new StreamableHTTPClientTransport(new URL(serverUrl)); + await client.connect(transport); + await client.callTool({ + name: 'test_client_elicitation_defaults', + arguments: {} + }); + await transport.close(); +} + +async function runRejectingElicitationClient(serverUrl: string): Promise { + // Declares the capability but registers no elicitation handler, so the + // SDK answers `elicitation/create` with a method-not-found error. + const client = new Client( + { name: 'rejecting-elicitation-test-client', version: '1.0.0' }, + { capabilities: { elicitation: {} } } + ); + const transport = new StreamableHTTPClientTransport(new URL(serverUrl)); + await client.connect(transport); + await client.callTool({ + name: 'test_client_elicitation_defaults', + arguments: {} + }); + await transport.close(); +} + +describe('elicitation-sep1034-client-defaults capability gating', () => { + test('client without the elicitation capability gets SKIPPED, not FAILURE', async () => { + const checks = await runAgainst(runClientWithoutElicitation); + + const scored = checks.filter((c) => + c.id.startsWith(ELICITATION_CHECK_PREFIX) + ); + expect(scored.length).toBe(DEFAULT_SLUGS.length + 1); + expect(scored.every((c) => c.status === 'SKIPPED')).toBe(true); + expect(checks.every((c) => c.status !== 'FAILURE')).toBe(true); + }); + + test('client declaring elicitation still receives elicitation/create', async () => { + const checks = await runAgainst(runRejectingElicitationClient); + + // The request must actually be delivered: the client declares the + // capability, so a refusal is a real FAILURE and nothing is SKIPPED. + const general = checks.find( + (c) => c.id === 'client-elicitation-sep1034-general' + ); + expect(general?.status).toBe('FAILURE'); + expect(general?.errorMessage).toContain('Elicitation failed'); + expect( + checks.some( + (c) => + c.id.startsWith(ELICITATION_CHECK_PREFIX) && c.status === 'SKIPPED' + ) + ).toBe(false); + }); +}); diff --git a/src/scenarios/client/elicitation-defaults.ts b/src/scenarios/client/elicitation-defaults.ts index d4170295..36f7d5fc 100644 --- a/src/scenarios/client/elicitation-defaults.ts +++ b/src/scenarios/client/elicitation-defaults.ts @@ -30,14 +30,68 @@ function isInitializeRequest(body: unknown): boolean { return false; } +/** + * Whether the client's `initialize` request declared the `elicitation` + * capability. This scenario only runs at 2025-11-25, where `elicitation` is + * a single object capability (the form/url sub-split arrives in the draft + * revision), so any declared value other than `null`/`false` counts. + * Defaults to `true` when the request shape is unreadable so behaviour is + * unchanged for clients that negotiated elicitation normally. + */ +function declaresElicitation(body: unknown): boolean { + if (typeof body !== 'object' || body === null) { + return true; + } + const capabilities = (body as { params?: { capabilities?: unknown } }).params + ?.capabilities; + if (typeof capabilities !== 'object' || capabilities === null) { + return true; + } + const elicitation = (capabilities as Record).elicitation; + return ( + elicitation !== undefined && elicitation !== null && elicitation !== false + ); +} + +const SEP1034_SPEC_REFERENCES = [ + { + id: 'SEP-1034', + url: 'https://github.com/modelcontextprotocol/modelcontextprotocol/issues/1034' + } +]; + +const ELICITATION_NOT_DECLARED_MESSAGE = + 'Client did not declare the elicitation capability during initialize; check not applicable'; + +function skippedElicitationCheck( + id: string, + name: string, + description: string +): ConformanceCheck { + return { + id, + name, + description, + status: 'SKIPPED', + timestamp: new Date().toISOString(), + errorMessage: ELICITATION_NOT_DECLARED_MESSAGE, + specReferences: SEP1034_SPEC_REFERENCES + }; +} + function createServer(checks: ConformanceCheck[]): { app: express.Application; cleanup: () => void; + elicitationDeclared: () => boolean; } { // Session management const transports: { [sessionId: string]: StreamableHTTPServerTransport } = {}; const servers: { [sessionId: string]: Server } = {}; + // Elicitation is an optional client capability; a client that did not + // declare it is not applicable for this scenario rather than failing it. + let elicitationDeclared = true; + const createMcpServer = () => { const server = new Server( { @@ -70,6 +124,51 @@ function createServer(checks: ConformanceCheck[]): { server.setRequestHandler(CallToolRequestSchema, async (request) => { if (request.params.name === 'test_client_elicitation_defaults') { + if (!elicitationDeclared) { + // The client negotiated without the optional elicitation + // capability, so it must not receive `elicitation/create` and the + // checks are not applicable rather than failed. + checks.push( + skippedElicitationCheck( + 'client-elicitation-sep1034-general', + 'ClientElicitationSEP1034General', + 'Client handles elicitation with defaults' + ), + skippedElicitationCheck( + 'client-elicitation-sep1034-string-default', + 'ClientElicitationSEP1034StringDefault', + 'Client applies string default value for elicitation' + ), + skippedElicitationCheck( + 'client-elicitation-sep1034-integer-default', + 'ClientElicitationSEP1034IntegerDefault', + 'Client applies integer default value for elicitation' + ), + skippedElicitationCheck( + 'client-elicitation-sep1034-number-default', + 'ClientElicitationSEP1034NumberDefault', + 'Client applies number default value for elicitation' + ), + skippedElicitationCheck( + 'client-elicitation-sep1034-enum-default', + 'ClientElicitationSEP1034EnumDefault', + 'Client applies enum default value for elicitation' + ), + skippedElicitationCheck( + 'client-elicitation-sep1034-boolean-default', + 'ClientElicitationSEP1034BooleanDefault', + 'Client applies boolean default value for elicitation' + ) + ); + return { + content: [ + { + type: 'text', + text: 'Elicitation capability not declared by client; checks skipped' + } + ] + }; + } try { // Request elicitation with all optional fields having defaults // Using raw server.request() to verify client applies defaults before sending response @@ -371,6 +470,7 @@ function createServer(checks: ConformanceCheck[]): { // Reuse existing transport for established sessions transport = transports[sessionId]; } else if (!sessionId && isInitializeRequest(req.body)) { + elicitationDeclared = declaresElicitation(req.body); // Create new transport for initialization requests const mcpServer = createMcpServer(); @@ -470,7 +570,7 @@ function createServer(checks: ConformanceCheck[]): { } }; - return { app, cleanup }; + return { app, cleanup, elicitationDeclared: () => elicitationDeclared }; } export class ElicitationClientDefaultsScenario implements Scenario { @@ -485,12 +585,14 @@ export class ElicitationClientDefaultsScenario implements Scenario { private httpServer: any = null; private checks: ConformanceCheck[] = []; private cleanup: (() => void) | null = null; + private elicitationDeclared: () => boolean = () => true; async start(_ctx: ScenarioContext): Promise { this.checks = []; - const { app, cleanup } = createServer(this.checks); + const { app, cleanup, elicitationDeclared } = createServer(this.checks); this.app = app; this.cleanup = cleanup; + this.elicitationDeclared = elicitationDeclared; this.httpServer = this.app.listen(0); const port = this.httpServer.address().port; return { serverUrl: `http://localhost:${port}/mcp` }; @@ -517,6 +619,34 @@ export class ElicitationClientDefaultsScenario implements Scenario { 'client-elicitation-sep1034-boolean-default' ]; + if (!this.elicitationDeclared()) { + // The client never declared the optional elicitation capability: the + // general check plus any untriggered defaults are SKIPPED, not failed. + if ( + !this.checks.find((c) => c.id === 'client-elicitation-sep1034-general') + ) { + this.checks.push( + skippedElicitationCheck( + 'client-elicitation-sep1034-general', + 'ClientElicitationSEP1034General', + 'Client handles elicitation with defaults' + ) + ); + } + for (const slug of expectedSlugs) { + if (!this.checks.find((c) => c.id === slug)) { + this.checks.push( + skippedElicitationCheck( + slug, + slug.replace(/-/g, ''), + `Server applies ${slug.split('-')[4]} default for elicitation` + ) + ); + } + } + return this.checks; + } + // Add failures for any checks that weren't triggered (tool not called) for (const slug of expectedSlugs) { if (!this.checks.find((c) => c.id === slug)) { From 79bcb454095b822728ed034b0801149da728b2ee Mon Sep 17 00:00:00 2001 From: King Star Date: Thu, 19 Nov 2026 18:09:23 +0000 Subject: [PATCH 2/2] fix(client): gate elicitation-defaults on negotiated form mode At 2025-11-25 elicitation splits into form and url modes, so a client declaring only {elicitation: {url: {}}} must not receive the scenario's form elicitation/create request; a bare {elicitation: {}} stays backwards-compatible with form. Read the settled capabilities from the SDK server per session instead of intercepting initialize. --- .../client/elicitation-defaults.test.ts | 88 +++++++++++++------ src/scenarios/client/elicitation-defaults.ts | 45 ++++++---- 2 files changed, 86 insertions(+), 47 deletions(-) diff --git a/src/scenarios/client/elicitation-defaults.test.ts b/src/scenarios/client/elicitation-defaults.test.ts index 63fa2959..3bee48b8 100644 --- a/src/scenarios/client/elicitation-defaults.test.ts +++ b/src/scenarios/client/elicitation-defaults.test.ts @@ -1,9 +1,12 @@ /** * Capability gating for `elicitation-sep1034-client-defaults` (issue #584). * - * Elicitation is an optional client capability at 2025-11-25. A client that - * negotiates without it must not be sent `elicitation/create`; its checks - * are SKIPPED, not failed. A client that does declare it is still scored. + * Elicitation is an optional client capability at 2025-11-25, split into + * `form` and `url` modes. A client that negotiates without form mode — + * either no `elicitation` or a URL-only declaration — must not be sent the + * form `elicitation/create` request; its checks are SKIPPED, not failed. + * A client that does declare form support, including the backwards- + * compatible bare `elicitation: {}`, is still scored. */ import { describe, test, expect, afterEach } from 'vitest'; import { Client } from '@modelcontextprotocol/sdk/client/index.js'; @@ -64,20 +67,24 @@ async function runClientWithoutElicitation(serverUrl: string): Promise { await transport.close(); } -async function runRejectingElicitationClient(serverUrl: string): Promise { +function makeElicitationRejectingClient( + elicitation: Record +): (serverUrl: string) => Promise { // Declares the capability but registers no elicitation handler, so the // SDK answers `elicitation/create` with a method-not-found error. - const client = new Client( - { name: 'rejecting-elicitation-test-client', version: '1.0.0' }, - { capabilities: { elicitation: {} } } - ); - const transport = new StreamableHTTPClientTransport(new URL(serverUrl)); - await client.connect(transport); - await client.callTool({ - name: 'test_client_elicitation_defaults', - arguments: {} - }); - await transport.close(); + return async (serverUrl: string) => { + const client = new Client( + { name: 'rejecting-elicitation-test-client', version: '1.0.0' }, + { capabilities: { elicitation } } + ); + const transport = new StreamableHTTPClientTransport(new URL(serverUrl)); + await client.connect(transport); + await client.callTool({ + name: 'test_client_elicitation_defaults', + arguments: {} + }); + await transport.close(); + }; } describe('elicitation-sep1034-client-defaults capability gating', () => { @@ -92,21 +99,44 @@ describe('elicitation-sep1034-client-defaults capability gating', () => { expect(checks.every((c) => c.status !== 'FAILURE')).toBe(true); }); - test('client declaring elicitation still receives elicitation/create', async () => { - const checks = await runAgainst(runRejectingElicitationClient); + test('client with only url-mode elicitation gets SKIPPED', async () => { + // `elicitation: {url: {}}` supports URL mode only; the scenario's form + // request is not applicable. + const checks = await runAgainst( + makeElicitationRejectingClient({ url: {} }) + ); - // The request must actually be delivered: the client declares the - // capability, so a refusal is a real FAILURE and nothing is SKIPPED. - const general = checks.find( - (c) => c.id === 'client-elicitation-sep1034-general' + const scored = checks.filter((c) => + c.id.startsWith(ELICITATION_CHECK_PREFIX) ); - expect(general?.status).toBe('FAILURE'); - expect(general?.errorMessage).toContain('Elicitation failed'); - expect( - checks.some( - (c) => - c.id.startsWith(ELICITATION_CHECK_PREFIX) && c.status === 'SKIPPED' - ) - ).toBe(false); + expect(scored.length).toBe(DEFAULT_SLUGS.length + 1); + expect(scored.every((c) => c.status === 'SKIPPED')).toBe(true); + expect(checks.every((c) => c.status !== 'FAILURE')).toBe(true); }); + + test.each([ + { elicitation: {}, label: 'backwards-compatible elicitation: {}' }, + { elicitation: { form: {} }, label: 'explicit form mode' } + ])( + 'client declaring $label still receives elicitation/create', + async ({ elicitation }) => { + const checks = await runAgainst( + makeElicitationRejectingClient(elicitation) + ); + + // The request must actually be delivered: the client declares the + // capability, so a refusal is a real FAILURE and nothing is SKIPPED. + const general = checks.find( + (c) => c.id === 'client-elicitation-sep1034-general' + ); + expect(general?.status).toBe('FAILURE'); + expect(general?.errorMessage).toContain('Elicitation failed'); + expect( + checks.some( + (c) => + c.id.startsWith(ELICITATION_CHECK_PREFIX) && c.status === 'SKIPPED' + ) + ).toBe(false); + } + ); }); diff --git a/src/scenarios/client/elicitation-defaults.ts b/src/scenarios/client/elicitation-defaults.ts index 36f7d5fc..c786fa7a 100644 --- a/src/scenarios/client/elicitation-defaults.ts +++ b/src/scenarios/client/elicitation-defaults.ts @@ -31,26 +31,28 @@ function isInitializeRequest(body: unknown): boolean { } /** - * Whether the client's `initialize` request declared the `elicitation` - * capability. This scenario only runs at 2025-11-25, where `elicitation` is - * a single object capability (the form/url sub-split arrives in the draft - * revision), so any declared value other than `null`/`false` counts. - * Defaults to `true` when the request shape is unreadable so behaviour is + * Whether the negotiated client capabilities include form-mode elicitation. + * + * At 2025-11-25 `elicitation` already splits into `form` and `url` modes. + * A client declaring `elicitation: {url: {}}` only must not receive this + * scenario's `elicitation/create` form request. A bare `elicitation: {}` is + * backwards-compatible with form mode and is scored normally. Anything + * unreadable or non-object defaults to form-capable so behaviour is * unchanged for clients that negotiated elicitation normally. */ -function declaresElicitation(body: unknown): boolean { - if (typeof body !== 'object' || body === null) { - return true; +function supportsFormElicitation(elicitation: unknown): boolean { + if ( + elicitation === undefined || + elicitation === null || + elicitation === false + ) { + return false; } - const capabilities = (body as { params?: { capabilities?: unknown } }).params - ?.capabilities; - if (typeof capabilities !== 'object' || capabilities === null) { + if (typeof elicitation !== 'object') { return true; } - const elicitation = (capabilities as Record).elicitation; - return ( - elicitation !== undefined && elicitation !== null && elicitation !== false - ); + const modes = elicitation as Record; + return !('url' in modes) || 'form' in modes; } const SEP1034_SPEC_REFERENCES = [ @@ -61,7 +63,7 @@ const SEP1034_SPEC_REFERENCES = [ ]; const ELICITATION_NOT_DECLARED_MESSAGE = - 'Client did not declare the elicitation capability during initialize; check not applicable'; + 'Client did not declare form-mode elicitation capability during initialize; check not applicable'; function skippedElicitationCheck( id: string, @@ -89,7 +91,9 @@ function createServer(checks: ConformanceCheck[]): { const servers: { [sessionId: string]: Server } = {}; // Elicitation is an optional client capability; a client that did not - // declare it is not applicable for this scenario rather than failing it. + // declare form-mode elicitation is not applicable for this scenario + // rather than failing it. Read from the negotiated capabilities on the + // SDK server, which the transport settles per session at initialize. let elicitationDeclared = true; const createMcpServer = () => { @@ -106,6 +110,9 @@ function createServer(checks: ConformanceCheck[]): { ); server.setRequestHandler(ListToolsRequestSchema, async () => { + elicitationDeclared = supportsFormElicitation( + server.getClientCapabilities()?.elicitation + ); return { tools: [ { @@ -124,6 +131,9 @@ function createServer(checks: ConformanceCheck[]): { server.setRequestHandler(CallToolRequestSchema, async (request) => { if (request.params.name === 'test_client_elicitation_defaults') { + elicitationDeclared = supportsFormElicitation( + server.getClientCapabilities()?.elicitation + ); if (!elicitationDeclared) { // The client negotiated without the optional elicitation // capability, so it must not receive `elicitation/create` and the @@ -470,7 +480,6 @@ function createServer(checks: ConformanceCheck[]): { // Reuse existing transport for established sessions transport = transports[sessionId]; } else if (!sessionId && isInitializeRequest(req.body)) { - elicitationDeclared = declaresElicitation(req.body); // Create new transport for initialization requests const mcpServer = createMcpServer();