feat(server): accept Standard Schemas in inputRequired.elicit (#2369)

Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com>
This commit is contained in:
Matt 2026-07-09 11:04:16 +01:00 • committed by GitHub
commit 24be4040d4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 236 additions and 17 deletions

View file

@ -96,7 +96,7 @@ export type { CacheHint, CacheScope } from '@modelcontextprotocol/core-internal'
// helpers a handler uses to request additional client input by returning an
// input-required result instead of sending a server→client request, and the
// typed readers for the responses a retried request carries back.
export type { InputRequiredSpec, InputResponseView } from '@modelcontextprotocol/core-internal';
export type { ElicitInputParams, InputRequiredSpec, InputResponseView } from '@modelcontextprotocol/core-internal';
export { acceptedContent, inputRequired, inputResponse } from '@modelcontextprotocol/core-internal';
// re-export curated public API from core

View file

@ -119,17 +119,18 @@ function errorOf(message: JSONRPCMessage): { code: number; message: string; data
describe('input-required returns on the 2026-07-28 era', () => {
it('a write-once tool returning inputRequired() reaches the wire as input_required and completes on the retry', async () => {
const server = new McpServer({ name: 's', version: '1.0.0' }, { capabilities: { tools: {} } });
const confirmationSchema = z.object({ confirm: z.boolean().meta({ title: 'Confirm deployment' }) });
server.registerTool(
'deploy',
{ inputSchema: z.object({ env: z.string() }), outputSchema: z.object({ deployed: z.boolean() }) },
async ({ env }, ctx) => {
const confirmed = acceptedContent<{ confirm: boolean }>(ctx.mcpReq.inputResponses, 'confirm');
const confirmed = acceptedContent(ctx.mcpReq.inputResponses, 'confirm', confirmationSchema);
if (!confirmed?.confirm) {
return inputRequired({
inputRequests: {
confirm: inputRequired.elicit({
message: `Deploy to ${env}?`,
requestedSchema: { type: 'object', properties: { confirm: { type: 'boolean' } } }
requestedSchema: confirmationSchema
})
},
requestState: 'opaque-deploy-state'
@ -147,7 +148,19 @@ describe('input-required returns on the 2026-07-28 era', () => {
);
expect(first.resultType).toBe('input_required');
expect(first.requestState).toBe('opaque-deploy-state');
expect(first.inputRequests).toMatchObject({ confirm: { method: 'elicitation/create' } });
expect(first.inputRequests).toMatchObject({
confirm: {
method: 'elicitation/create',
params: {
mode: 'form',
requestedSchema: {
type: 'object',
properties: { confirm: { type: 'boolean', title: 'Confirm deployment' } },
required: ['confirm']
}
}
}
});
expect(first.ttlMs).toBeUndefined();
expect(first.cacheScope).toBeUndefined();
expect(first.content).toBeUndefined();

View file

@ -35,19 +35,21 @@ import { errorOf, legacyInitialize, resultOf, toolText, wireLegacy } from './leg
import { McpServer } from '../../src/server/mcp';
import { Server } from '../../src/server/server';
const CONFIRM_SCHEMA = z.object({ confirm: z.boolean().meta({ title: 'Confirm deployment' }) });
/** A sessionful legacy connection serving one write-once elicitation tool. */
async function elicitingToolServer(options?: ConstructorParameters<typeof McpServer>[1]) {
const server = new McpServer({ name: 's', version: '1.0.0' }, { capabilities: { tools: {} }, ...options });
const seenResponses: Array<Record<string, unknown> | undefined> = [];
server.registerTool('deploy', { inputSchema: z.object({ env: z.string() }) }, async ({ env }, ctx) => {
seenResponses.push(ctx.mcpReq.inputResponses);
const confirmed = acceptedContent<{ confirm: boolean }>(ctx.mcpReq.inputResponses, 'confirm');
const confirmed = acceptedContent(ctx.mcpReq.inputResponses, 'confirm', CONFIRM_SCHEMA);
if (!confirmed?.confirm) {
return inputRequired({
inputRequests: {
confirm: inputRequired.elicit({
message: `Deploy to ${env}?`,
requestedSchema: { type: 'object', properties: { confirm: { type: 'boolean' } }, required: ['confirm'] }
requestedSchema: CONFIRM_SCHEMA
})
}
});
@ -82,10 +84,18 @@ describe('legacy shim: write-once fulfilment on a sessionful 2025-era connection
// The mis-typed input_required result never reached the wire.
expect(resultOf(answer).resultType).toBeUndefined();
// A real wire request went out, form-mode, with the handler's params.
// A real wire request went out, form-mode, with the Standard Schema converted to MCP's restricted JSON Schema.
const legs = wire.peerRequests('elicitation/create');
expect(legs).toHaveLength(1);
expect(legs[0]!.params).toMatchObject({ mode: 'form', message: 'Deploy to prod?' });
expect(legs[0]!.params).toMatchObject({
mode: 'form',
message: 'Deploy to prod?',
requestedSchema: {
type: 'object',
properties: { confirm: { type: 'boolean', title: 'Confirm deployment' } },
required: ['confirm']
}
});
// Stream association: the leg is stamped with the ORIGINATING request id.
const [legOptions] = wire.sentOptionsFor('elicitation/create');