Skip to content

Client.callTool() throws -32602 after tools/list_changed replaces an in-flight call's output schema #2612

Open

Description

@sebthom

Description

Client.callTool() retrieves the cached output validator after awaiting the tools/call response.

If listTools() runs while that request is pending, cacheToolMetadata() clears and replaces the validator cache. The completed call can therefore be validated against a newer schema than the one active when the call started.

Reproduction

  1. List a tool whose output schema requires { generation: "old" }.
  2. Start a delayed callTool() for that tool.
  3. While it is pending, refresh the tool list with a schema requiring
    { generation: "new" }.
  4. Complete the original call with { generation: "old" }.

Actual result:
McpError -32602: Structured content does not match the tool's output schema

Expected result:* The call is validated using the schema generation active when the call began.

Proposed fix

Capture the validator before yielding to the request:

const validator = this.getToolOutputValidator(params.name);
const result = await this.request(
  { method: "tools/call", params },
  resultSchema,
  options,
);

This is consistent with the existing required-task check, which is also performed before the request.

diff --git a/src/client/index.ts b/src/client/index.ts
--- a/src/client/index.ts
+++ b/src/client/index.ts
@@
         if (this.isToolTaskRequired(params.name)) {
             throw new McpError(
                 ErrorCode.InvalidRequest,
                 `Tool "${params.name}" requires task-based execution. Use client.experimental.tasks.callToolStream() instead.`
             );
         }

-        const result = await this.request({ method: 'tools/call', params }, resultSchema, options);
-
-        // Check if the tool has an outputSchema
+        // A concurrent listTools() can replace the cache while this request is
+        // in flight. Capture the validator used when the call is dispatched.
         const validator = this.getToolOutputValidator(params.name);
+        const result = await this.request({ method: 'tools/call', params }, resultSchema, options);

         if (validator) {
             // If tool has outputSchema, it MUST return structuredContent (unless it's an error)
             if (!result.structuredContent && !result.isError) {

Affected versions

Reproduced with @modelcontextprotocol/sdk 1.30.0.

Activity

  1. Linxiushen commented on Aug 5, 2026

    @Linxiushen

    I would like to work on this. I verified that the v1.x client still resolves the output validator after awaiting the tools/call response, so a concurrent tools/list refresh can replace the schema generation used by an in-flight call. I plan to target v1.x with a deterministic regression test that pauses tools/call, refreshes the catalog, and verifies the original response is validated against the dispatch-time schema, then move the validator lookup before the request await. Please assign it to me if that approach looks right.

  2. added
    bug
    P2
    ready for work
    on Aug 17, 2026
  3. added
    v1
    on Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2bugready for workv1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions