From cf2455bb582512366f8f446c6529f07f321c88ab Mon Sep 17 00:00:00 2001 From: Prasanna Jain Date: Fri, 20 Nov 2026 07:56:40 -0500 Subject: [PATCH] fix(client): return input_required from callTool before output-schema validation A tool with an outputSchema made callTool({ allowInputRequired: true }) throw on the first round, because the intermediate input_required result has no structuredContent. Validate only the completed result. Fixes #3216 --- .../call-tool-input-required-output-schema.md | 5 +++ packages/client/src/client/client.ts | 4 ++- .../test/client/inputRequiredEngine.test.ts | 35 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 .changeset/call-tool-input-required-output-schema.md diff --git a/.changeset/call-tool-input-required-output-schema.md b/.changeset/call-tool-input-required-output-schema.md new file mode 100644 index 0000000000..18560b2f3d --- /dev/null +++ b/.changeset/call-tool-input-required-output-schema.md @@ -0,0 +1,5 @@ +--- +'@modelcontextprotocol/client': patch +--- + +`callTool()` with `allowInputRequired: true` now returns an `input_required` result for a tool that declares an `outputSchema`, instead of throwing because the result has no `structuredContent`. Output-schema validation still applies to the completed result of the retry. diff --git a/packages/client/src/client/client.ts b/packages/client/src/client/client.ts index 0c45041337..541e16cfcc 100644 --- a/packages/client/src/client/client.ts +++ b/packages/client/src/client/client.ts @@ -62,6 +62,7 @@ import { DiscoverResultSchema, guardLogger, HEADER_MISMATCH_ERROR_CODE, + isInputRequiredResult, isJSONRPCErrorResponse, isJSONRPCRequest, isModernProtocolVersion, @@ -2527,7 +2528,8 @@ export class Client extends Protocol { } const validator = compiled !== undefined && compiled.ok ? compiled.validator : undefined; - if (validator) { + // An input_required result is not the tool's output yet; validate the completed retry instead. + if (validator && !isInputRequiredResult(result)) { // If tool has outputSchema, it MUST return structuredContent (unless it's an error). // SEP-2106: presence is `=== undefined`, not falsy — `null`/`0`/`false`/`""` are legal // values and are validated below (so a falsy value against an object-typed schema still diff --git a/packages/client/test/client/inputRequiredEngine.test.ts b/packages/client/test/client/inputRequiredEngine.test.ts index 14af5fc2c4..386e8b1d06 100644 --- a/packages/client/test/client/inputRequiredEngine.test.ts +++ b/packages/client/test/client/inputRequiredEngine.test.ts @@ -406,6 +406,41 @@ describe('manual mode', () => { await client.close(); }); + it('hands input_required back before output-schema validation when the tool declares an outputSchema', async () => { + const { clientTx } = await scriptedModernServer((_request, call) => + call === 1 + ? { resultType: 'input_required', inputRequests: { github_login: ELICIT_ENTRY }, requestState: 'manual-state' } + : { resultType: 'complete', content: [{ type: 'text', text: '{"id":7}' }], structuredContent: { id: 7 } } + ); + + const client = makeClient({ inputRequired: { autoFulfill: false } }); + await client.connect(clientTx); + const toolDefinition = { + name: 'deploy', + inputSchema: { type: 'object' as const }, + outputSchema: { type: 'object' as const, properties: { id: { type: 'number' } }, required: ['id'] } + }; + + const first = (await client.callTool( + { name: 'deploy', arguments: {} }, + { allowInputRequired: true, toolDefinition } + )) as unknown as Record; + expect(first.resultType).toBe('input_required'); + + const second = await client.callTool( + { + name: 'deploy', + arguments: {}, + inputResponses: { github_login: { action: 'accept', content: { name: 'octocat' } } }, + requestState: first.requestState as string + } as Parameters[0], + { toolDefinition } + ); + expect(second.structuredContent).toEqual({ id: 7 }); + + await client.close(); + }); + it('carries the result-level _meta through to the manual caller', async () => { const { clientTx } = await scriptedModernServer(() => ({ resultType: 'input_required',