Skip to content

Unknown tool error always says "Unknown tool: invalid_tool_name" instead of the name that was called #1346

Open

Description

@davsclaus

The error for a tools/call with an unknown tool name has a fixed message, Unknown tool: invalid_tool_name, whatever name was called:

// McpAsyncServer.java (and McpStatelessAsyncServer.java)
return Mono.error(McpError.builder(McpSchema.ErrorCodes.INVALID_PARAMS)
    .message("Unknown tool: invalid_tool_name")
    .data("Tool not found: " + callToolRequest.name())
    .build());

A call to delete_order, which the server does not have, gets:

{"code": -32602, "message": "Unknown tool: invalid_tool_name", "data": "Tool not found: delete_order"}

The text looks like it was taken from the error example in the MCP specification, where invalid_tool_name is a placeholder. Clients and logs usually show only message, so the name of the tool is lost, and it looks as if the tool were called invalid_tool_name.

Expected: the message names the tool that was called, such as Unknown tool: delete_order, in both McpAsyncServer and McpStatelessAsyncServer. data can stay as it is.

Seen with mcp-core 2.2.0, and still in main (779893c).

Claude Code on behalf of Claus Ibsen

Activity

  1. Shanmukh-l33t commented on Nov 23, 2026

    @Shanmukh-l33t

    Confirmed on main (779893c). Root cause: the tools/call handlers in McpAsyncServer (toolsCallRequestHandler) and McpStatelessAsyncServer both build the unknown-tool error with the literal .message("Unknown tool: invalid_tool_name"), while .data(...) already uses callToolRequest.name().

    Change shape: two one-line edits, .message("Unknown tool: " + callToolRequest.name()) in both classes. data is unchanged. Nothing else is touched.

    Tests: one new regression test per server (McpAsyncServerUnknownToolTests, McpStatelessAsyncServerUnknownToolTests, in mcp-test because mcp-core has no JSON implementation on its test classpath). Each calls an unknown tool delete_order and asserts code -32602, message Unknown tool: delete_order and data Tool not found: delete_order.

    • Before the fix: 2 run, 2 failures (expected: "Unknown tool: delete_order" but was: "Unknown tool: invalid_tool_name").
    • After the fix: 2 run, 0 failures, 0 errors. Command: ./mvnw -o -pl mcp-core,mcp-test -am -Dtest='McpAsyncServerUnknownToolTests,McpStatelessAsyncServerUnknownToolTests' -Dsurefire.failIfNoSpecifiedTests=false test (JDK 17, spring-javaformat validate passes). I did not run the full suite, which needs Docker and npx.

    Branch (no PR opened, since this issue is not assigned or marked help wanted): Shanmukh-l33t/java-sdk@modelcontextprotocol:main...fix/1346-unknown-tool-name

    Happy for a maintainer to take the diff as is or let me know if I should open a PR.

    AI assistance was used to prepare this change and comment; I reviewed the result.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions