modelcontextprotocol / servers

Model Context Protocol Servers
https://modelcontextprotocol.io
MIT License
3.03k stars 246 forks source link

[server-google-maps][server-github] Does not work with 1.0.0 SDK #94

Open mbleigh opened 2 days ago

mbleigh commented 2 days ago

Describe the bug Trying to call tools in the Google Maps server fail with Zod validation errors when using the MCP 1.0 SDK. It appears that the issue is that an older version of the protocol returned {toolResponse: {content: [...]}} instead of just {content: [...]}.

To Reproduce Steps to reproduce the behavior:

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);

Expected behavior The tool is called successfully.

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

Additional context Add any other context about the problem here.

dsp-ant commented 1 day ago

Thank you for spotting this!

I created #107 . Some servers depend on old versions of the SDK using an old version of the protocol before the initial release. There is a backwards compatibility layer , but it doesn't auto detect the protocol version, which it should. The following code will work:

const result = await client.callTool({
  name: "maps_search_places",
  arguments: { query: "bookstores near 94552" },
},CompatibilityCallToolResultSchema );

against old versions.