Skip to content

feat(python): handle McpError(-32042) for MCP payment challenges#1876

Open
Bortlesboat wants to merge 1 commit intocoinbase:mainfrom
Bortlesboat:feat/mcp-mcperror-32042-python
Open

feat(python): handle McpError(-32042) for MCP payment challenges#1876
Bortlesboat wants to merge 1 commit intocoinbase:mainfrom
Bortlesboat:feat/mcp-mcperror-32042-python

Conversation

@Bortlesboat
Copy link
Copy Markdown
Contributor

Description

Ports TypeScript PR #1728 to the Python SDK. When an MCP server throws a -32042 error (SEP-1036 UrlElicitationRequired) with payment requirements in error.data, the Python client now catches and processes payment automatically — matching the TypeScript behavior.

Changes

  • Add JSONRPC_PAYMENT_REQUIRED_CODE = -32042 constant to types.py
  • Update extract_payment_required_from_error() and is_payment_required_error() in utils.py to handle both 402 and -32042 codes, including namespaced data.x402 payloads
  • Wrap call_tool() and get_tool_payment_requirements() in both async and sync clients with try/except for McpError(-32042)
  • Add 26 test cases covering extraction, detection, async client, sync client, and backward compatibility

Tests

python -m uv run pytest mcp/tests/test_mcperror.py -v
======================== 26 passed in 0.10s ========================

All existing MCP tests continue to pass (21 server tests, 19 server_sync tests).

Port TypeScript PR coinbase#1728 to Python SDK. When an MCP server throws
-32042 (SEP-1036 UrlElicitationRequired) with payment requirements
in error.data, the client now catches and processes payment
automatically.

Adds JSONRPC_PAYMENT_REQUIRED_CODE constant, updates error extraction
utilities, and wraps both async and sync client call_tool methods.
@cb-heimdall
Copy link
Copy Markdown

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 30, 2026

@Bortlesboat is attempting to deploy a commit to the Coinbase Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions bot added sdk Changes to core v2 packages python labels Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python sdk Changes to core v2 packages

Development

Successfully merging this pull request may close these issues.

2 participants