Skip to content

Keep the code and message of MCP JSON-RPC errors - #161

Open
AdityaPradhan01 wants to merge 1 commit into
prooflinedev:mainfrom
AdityaPradhan01:mcp-jsonrpc-errors
Open

AdityaPradhan01 wants to merge 1 commit into
prooflinedev:mainfrom
AdityaPradhan01:mcp-jsonrpc-errors

Conversation

@AdityaPradhan01

Copy link
Copy Markdown

When /mcp answers a tool call with a JSON-RPC error object, _decode raises the fixed Invalid or refused MCP response. and drops the error's code and message. A caller can't tell -32602 Invalid params (fix your arguments) from a broken server.

This change keeps a well-formed error: ProoflineError with type urn:proofline:sdk:mcp (unchanged), title="JSON-RPC error <code>" and detail=<message>. The API token is redacted from the message with the same redacted helper that problem documents use. These cases still raise the fixed refusal:

  • the error isn't an object
  • its code isn't an integer, or is a bool
  • its message isn't a string
  • the response carries both error and result

Tool calls still never retry.

BearerAuth gains a read-only token property, so the MCP layer can redact without a new constructor argument on McpTools and its subclasses.

Tests: test_mcp_jsonrpc_error_keeps_code_and_redacted_message (sync and async) fails on main and passes here. The full suite, ruff, mypy, the generate check and the contract check pass. README updated.

A JSON-RPC error response from the MCP endpoint (for example -32602
Invalid params) was reported only as the fixed 'Invalid or refused MCP
response.', so callers could not tell a bad argument from a broken
server. A well-formed error now raises ProoflineError with the code in
title and the server message in detail, with the API token redacted.
Malformed errors, and responses carrying both error and result, keep
the fixed refusal. Tool calls still never retry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SnJtMTbFz8FeAHg5pLrzkN

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant