Skip to content

CompatibilityCallToolResultSchema should be set based on protocol version #82

Closed
@dsp-ant

Description

@dsp-ant

Describe the bug
When using the TS client against an old version of the SDK, CompatibilityCallToolResultSchema must be passed. Clients accept servers with protocol version '2024-10-07', but do not automatically set CompatibilityCallToolResultSchema in callTools in this case. Implementors must manually set it depending on the server version. However, there is no easy way to obtain the protocol version.

To Reproduce
Steps to reproduce the behavior:
Run

import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";

const client = new Client(
  {
    name: "maps",
    version: "1.0.0",
  },
  { capabilities: { tools: {} } }
);

const transport = new StdioClientTransport({
  command: "npx",
  args: ["-y", "@modelcontextprotocol/server-google-maps"],
  env: {
    ...process.env,
    GOOGLE_MAPS_API_KEY: "A_VALID_KEY",
  },
});
await client.connect(transport);
const result = await client.callTool({
  name: "maps_search_places",
  arguments: { query: "bookstores near 94552" },
});

console.log(result);

Call tool fails

Expected behavior
callTool succeeds

Logs

ZodError: [
  {
    "code": "invalid_type",
    "expected": "array",
    "received": "undefined",
    "path": [
      "content"
    ],
    "message": "Required"
  }
]
    at get error (file:///Users/bleigh/sandbox/mcp-bug/node_modules/zod/lib/index.mjs:587:31)
    at ZodObject.parse (file:///Users/bleigh/sandbox/mcp-bug/node_modules/zod/lib/index.mjs:692:22)
    at file:///Users/bleigh/sandbox/mcp-bug/node_modules/@modelcontextprotocol/sdk/dist/shared/protocol.js:212:49
    at Client._onresponse (file:///Users/bleigh/sandbox/mcp-bug/node_modules/@modelcontextprotocol/sdk/dist/shared/protocol.js:153:13)
    at _transport.onmessage (file:///Users/bleigh/sandbox/mcp-bug/node_modules/@modelcontextprotocol/sdk/dist/shared/protocol.js:45:22)
    at StdioClientTransport.processReadBuffer (file:///Users/bleigh/sandbox/mcp-bug/node_modules/@modelcontextprotocol/sdk/dist/client/stdio.js:117:79)
    at Socket.<anonymous> (file:///Users/bleigh/sandbox/mcp-bug/node_modules/@modelcontextprotocol/sdk/dist/client/stdio.js:92:22)
    at Socket.emit (node:events:519:28)
    at addChunk (node:internal/streams/readable:561:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:512:3) {
  issues: [
    {
      code: 'invalid_type',
      expected: 'array',
      received: 'undefined',
      path: [ 'content' ],
      message: 'Required'
    }
  ],
  addIssue: [Function (anonymous)],
  addIssues: [Function (anonymous)],
  errors: [
    {
      code: 'invalid_type',
      expected: 'array',
      received: 'undefined',
      path: [ 'content' ],
      message: 'Required'
    }
  ]
}

Node.js v22.9.0

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions