Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/call-tool-input-required-output-schema.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 3 additions & 1 deletion packages/client/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import {
DiscoverResultSchema,
guardLogger,
HEADER_MISMATCH_ERROR_CODE,
isInputRequiredResult,
isJSONRPCErrorResponse,
isJSONRPCRequest,
isModernProtocolVersion,
Expand Down Expand Up @@ -2527,7 +2528,8 @@ export class Client extends Protocol<ClientContext> {
}

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
Expand Down
35 changes: 35 additions & 0 deletions packages/client/test/client/inputRequiredEngine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>;
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<Client['callTool']>[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',
Expand Down
Loading