Skip to content

feat: send x402 payment via MCP _meta alongside HTTP header#76

Merged
MQ37 merged 2 commits intomainfrom
feat/x402-meta-payment
Mar 15, 2026
Merged

feat: send x402 payment via MCP _meta alongside HTTP header#76
MQ37 merged 2 commits intomainfrom
feat/x402-meta-payment

Conversation

@MQ37
Copy link
Collaborator

@MQ37 MQ37 commented Mar 14, 2026

Summary

  • Send x402 payment in both the HTTP PAYMENT-SIGNATURE header and params._meta["x402/payment"] on tools/call JSON-RPC requests — server decides which channel to consume
  • Thread optional _meta parameter through the full tool call chain (IMcpClientSessionClient → bridge IPC → McpClient → SDK)
  • Batch requests skip _meta injection (header-only fallback) since a single payment cannot safely apply to multiple tool calls

Changes

File What changed
src/lib/types.ts Added optional meta param to callTool, callToolWithTask, callToolDetached
src/core/mcp-client.ts Forward _meta to SDK callTool and callToolStream
src/lib/session-client.ts Forward _meta through IPC requests to bridge
src/bridge/index.ts Extract _meta from IPC params, pass to McpClient
src/lib/x402/fetch-middleware.ts injectPayment() now injects into both HTTP header and JSON-RPC body _meta

Testing

Manually verified against local x402 demo server (localhost:4021/mcp):

  • Free tool call: no payment attached ✅
  • Paid tool call: payment in both HTTP header and _meta["x402/payment"], paymentVerified: true
  • Decoded base64 header matches _meta payload exactly (same signature, nonce, authorization) ✅

MQ37 and others added 2 commits March 13, 2026 21:00
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
@MQ37 MQ37 merged commit 1967977 into main Mar 15, 2026
6 checks passed
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.

3 participants