Skip to content

MCP: Return a tool error when a command fails during execution #2680

Open

Description

@erichare

A request error raised while a command runs reaches the client as a bare JSON-RPC error. Calling find with an unsupported filter operator shows it.

{"name": "find", "arguments": {"keyspace": "mcp_e2e", "collection": "books", "filter": {"year": {"$bogus": 1}}}}
{"jsonrpc": "2.0", "id": 1, "error": {"code": -32603, "message": "Internal error"}}

The server log records a FilterException for the call, so the server knows this is a request error with a code and a message. An agent sees "Internal error" and has nothing to correct. Other request errors in the same run, such as an unknown collection, came back as tool errors with the full Data API error body.

#2653 converts failures raised before the command runs. handleSetupFailure in McpResource covers validation and context setup. A failure from meteredCommandProcessor.processCommand inside executeCommand has no matching conversion, so it leaves the tool method as an exception and the framework reports an internal error.

This ticket is done when a request error raised during execution returns isError: true with the Data API error in structuredContent.errors, and a test covers the unsupported filter operator. Authentication failures, protocol errors, and cancellation should keep their current handling, the same as on the setup path.

Observed on 3467041f7 against DSE 6.9.21. I have not compared the response from the same command over HTTP.

Activity

  1. erichare commented on Nov 19, 2026

    @erichare
    ContributorAuthor

    The cause is different from what I wrote above. CommandProcessor does turn the filter error into an error result. MeteredCommandProcessor then builds the filter clause again to choose the sort_type metric tag, and the second failure replaces the result. So the fix belongs in the shared metrics code and is based on main, not on the MCP stack. The HTTP API has the same failure but its exception mapper hides it, apart from the missing timer.

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