Skip to content

feat: use facilitator for real on-chain settlement in withX402 MCP middleware#16

Merged
adacapo21 merged 1 commit intomainfrom
feat/mcp-facilitator-settlement
Apr 3, 2026
Merged

feat: use facilitator for real on-chain settlement in withX402 MCP middleware#16
adacapo21 merged 1 commit intomainfrom
feat/mcp-facilitator-settlement

Conversation

@adacapo21
Copy link
Copy Markdown
Member

Summary

  • withX402 in the MCP middleware was calling the local verifyPayment function (signature format + business rules check only) — no on-chain settlement ever occurred
  • Replace with processPayment from facilitator.ts which runs the full flow: POST /verify → execute handler → POST /settle (broadcasts transferWithAuthorization on-chain)
  • checkPayment updated to use verifyWithFacilitator for consistency
  • Settlement tx hash is logged to stderr when available

Test plan

  • Call a paid MCP tool with a valid paymentSignature
  • Confirm settlement tx appears on Base Sepolia (testnet) or Base mainnet
  • Confirm tx hash is logged to stderr
  • Call with invalid/missing signature — verify 402 still returned correctly

Recreated from #15 which was accidentally closed

…ddleware

Replace local-only verifyPayment call in withX402 and checkPayment with
processPayment/verifyWithFacilitator from facilitator.ts. Previously the
middleware only validated the EIP-3009 signature format locally — no
on-chain settlement occurred. Now the full flow runs:
  1. verifyWithFacilitator (POST /verify to x402.org/facilitator)
  2. execute handler
  3. settleWithFacilitator (POST /settle → broadcasts transferWithAuthorization on-chain)

Settlement tx hash is logged to stderr when available.
@adacapo21 adacapo21 merged commit 395d014 into main Apr 3, 2026
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.

1 participant