Skip to content

[Agent][MCP] A tool error reported by an MCP server never reaches the model #2534

Description

@tacman

Follow-up to #2497, split out from my comment there as suggested.

Problem. When an MCP server reports a tool execution error (a CallToolResult with isError: true, which is what the SDK sends when a tool throws Mcp\Exception\ToolCallException), the model never sees the server's message. It only gets:

An error occurred while executing tool "demo_movie_details".

MCP puts tool errors inside the result so the model can see them and fix the call. Here the text is lost.

Cause. McpToolbox::invoke() throws ToolCallException::returnedError(). That exception doesn't implement ToolExecutionExceptionInterface, so AbstractToolbox wraps it in ToolExecutionException::executionFailed(), and FaultTolerantToolbox replaces it with the generic message.

Expected. The server's error text is the tool call result the model receives. Transport and connection failures (callFailed(), listFailed()) should stay hidden from the model, as they are now.

Reproducer. In the demo, give an agent { mcp_server: ... } pointing at a server whose tool throws Mcp\Exception\ToolCallException('No movie with slug "nope".'). The model receives the generic message instead.

A correction to my #2497 comment. The cases I tested there (a missing required argument, a wrong argument type) take a different path. The SDK rejects schema violations as a JSON-RPC -32602 error rather than an isError result, so they arrive as callFailed() and are masked for that reason. Whether invalid-params errors should also reach the model is a separate question, and I've left it out of the fix for this issue.

Activity

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

    AgentIssues & PRs about the AI Agent component

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions