Skip to content

Calling a nonexistent tool should trigger a JSON-RPC Error #1510

@chemicL

Description

@chemicL

Describe the bug
When a client attempts to call a tool that does not exist the specification requires that a protocol error is raised as a JSON-RPC Error. Instead, the current SDK returns a JSON-RPC Result with isError = true.

To Reproduce
Steps to reproduce the behavior:

  1. Call a missing tool

Expected behavior
As per the specification, the result should be:

{
  "jsonrpc": "2.0",
  "id": 3,
  "error": {
    "code": -32602,
    "message": "Unknown tool: nonexistent_tool"
  }
}

while actually it's

{
    "jsonrpc": "2.0",
    "id": "3",
    "result": {
      "content": [
        {
          "type": "text",
          "text": "MCP error -32602: Tool nonexistent_tool not found"
        }
      ],
      "isError": true
    }
  }

Additional context
https://github.com/modelcontextprotocol/typescript-sdk/blob/main/packages/server/src/server/mcp.ts#L201-L204
https://github.com/modelcontextprotocol/typescript-sdk/blob/main/packages/server/src/server/mcp.ts#L211-L227
are at fault.

Metadata

Metadata

Assignees

No one assigned

    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