fix(python/mcp): gate tool output on settlement success#2356
Merged
phdargen merged 2 commits intoMay 18, 2026
Merged
Conversation
The MCP payment wrappers in server_sync.py and server_async.py called
facilitator.settle() but never branched on settle_result.success before
returning the wrapped tool's output. A signed EIP-3009 authorization
could be replayed indefinitely: verify passed each time, the tool ran,
settle returned success=False with AuthorizationAlreadyUsed, and the
wrapper returned the tool output stamped with the failed settlement
response in _meta.
Mirror the success check from the non-MCP path in server.py and route
to the existing _create_settlement_failed_result_{sync,async} helpers
on failure. Add regression tests covering the success=False branch
(distinct from the existing exception-path test) and assert that
on_after_settlement does not fire on failure.
Also fix a stale signature on the test mock's
_create_payment_required_response_real that was missing the extensions
parameter, which had been masking other test failures.
|
@apmcdermott is attempting to deploy a commit to the Coinbase Team on Vercel. A member of the Team first needs to authorize it. |
…ettlement-success-check
phdargen
approved these changes
May 18, 2026
Collaborator
phdargen
left a comment
There was a problem hiding this comment.
Looks great, thank you @apmcdermott
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The MCP payment wrappers in
python/x402/mcp/server_sync.pyandserver_async.pycallfacilitator.settle()but don't branch onsettle_result.successbefore returning the wrapped tool's output. Add the missing check so a failed settlement returns a structured 402 error result, matching the HTTP server path atpython/x402/server.py:225-243.Tests
python/x402/mcp/tests/test_server.py::test_create_payment_wrapper_settlement_returns_failurepython/x402/mcp/tests/test_server_async.py::test_create_payment_wrapper_async_settlement_returns_failurepython/x402/tests/unit/mcp/test_server_wrappers.py— verifies the settlement-failure helpers preserve extensionsChecklist