feat: send x402 payment via MCP _meta alongside HTTP header#76
Merged
Conversation
Add dual-channel x402 payment delivery so servers can consume payment from either the HTTP PAYMENT-SIGNATURE header or the MCP _meta field on tools/call JSON-RPC requests. - Thread optional _meta parameter through IMcpClient, SessionClient, bridge IPC, and McpClient to the SDK callTool/callToolStream APIs - Fetch middleware now injects the same signed payment payload into both the HTTP header (base64) and params._meta["x402/payment"] (JSON) - Batch requests skip _meta injection (header-only) since a single payment cannot safely apply to multiple tool calls
jancurn
approved these changes
Mar 15, 2026
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-SIGNATUREheader andparams._meta["x402/payment"]ontools/callJSON-RPC requests — server decides which channel to consume_metaparameter through the full tool call chain (IMcpClient→SessionClient→ bridge IPC →McpClient→ SDK)_metainjection (header-only fallback) since a single payment cannot safely apply to multiple tool callsChanges
src/lib/types.tsmetaparam tocallTool,callToolWithTask,callToolDetachedsrc/core/mcp-client.ts_metato SDKcallToolandcallToolStreamsrc/lib/session-client.ts_metathrough IPC requests to bridgesrc/bridge/index.ts_metafrom IPC params, pass toMcpClientsrc/lib/x402/fetch-middleware.tsinjectPayment()now injects into both HTTP header and JSON-RPC body_metaTesting
Manually verified against local x402 demo server (
localhost:4021/mcp):_meta["x402/payment"],paymentVerified: true✅_metapayload exactly (same signature, nonce, authorization) ✅