feat: x402 payment support — signature caching and JSON-RPC 402 retry#119
Merged
Conversation
- Cache x402 payment signature at session level, reuse across tool calls - On JSON-RPC 402 error, invalidate cache, sign fresh payment, retry once - Extract payment requirements from SDK error via extractPaymentRequiredFromError - Inject payment in both PAYMENT-SIGNATURE header and _meta["x402/payment"] body
Per the x402 MCP transport spec, payment-required is now signaled as a tool result (isError: true + structuredContent/content[0].text with PaymentRequired) instead of a JSON-RPC 402 error. This matches the @x402/mcp client implementation. - Replace extractPaymentRequiredFromError with extractPaymentRequiredFromResult - Rename extractAcceptFromErrorData to extractAcceptFromPaymentRequired - Bridge inspects tool results instead of catching thrown errors - Remove JSON-RPC 402 error unwrapping code (no longer needed)
jancurn
approved these changes
Mar 26, 2026
Collaborator
Author
|
@jancurn Thank you for approve - I will merge this once we release the Apify MCP server with the x402 support. |
Member
|
Why wait and not merge right away? |
Collaborator
Author
oke, let's merge it 😎 Let's keep the momentum going 🧙 |
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.
Summary
PAYMENT-SIGNATUREHTTP header andparams._meta["x402/payment"]JSON-RPC bodyHow it works
_meta.x402metadata, caches itisError: true+structuredContentwithx402Version/accepts): bridge invalidates cache, signs fresh from theacceptsarray, retries oncePAYMENT-REQUIREDheaderx402 MCP transport spec compatibility
Payment-required responses follow the x402 MCP transport spec used by
@x402/mcp:isError: truestructuredContentcontains thePaymentRequiredobject (x402Version,accepts,resource)content[0].textcontains the same as JSON string (fallback)extractPaymentRequiredFromResult, NOT via JSON-RPC error codes