Express middleware for payment-gated MCP servers — multi-network X402 support with automatic routing, simulation, and JSON-RPC 402 compliance.
x402-mcp-middleware is an early-stage JavaScript project in the AI payments / x402 ecosystem, focused on mcp, middleware, payments, x402. It currently has 6 GitHub stars and 1 forks, and sits alongside related tools like provider, awesome-fintech, pinion-os, agenti, tdm-integration-kit, TDM-Agent-Integration-Kit.
Express middleware for X402 payment-enabled MCP (Model Context Protocol) servers.
x402-mcp-middleware provides drop-in middleware for building payment-enabled MCP servers. v2 introduces multi-network support and MCP-spec compliance, enabling servers to accept payments from multiple blockchains while transmitting payment data via JSON-RPC _meta fields.
_meta for payment transmission| Document | Description |
|---|---|
| docs/index.md | Documentation index and navigation |
| docs/v1/README.md | Legacy v1 documentation (frozen) |
| docs/v2/README.md | v2 documentation - Multi-network, MCP-spec compliant |
import { X402Middleware } from 'x402-mcp-middleware/v2'
Server Configuration (Multi-Network):
const middleware = await X402Middleware.create( {
x402V2ExactEvmConfiguration: {
contractCatalog: {
'usdc-base-sepolia': {
paymentNetworkId: 'eip155:84532',
address: '0x036CbD53842c5426634e7929541eC2318f3dCF7e',
decimals: 6,
domainName: 'USDC',
domainVersion: '2'
},
'usdc-avalanche-fuji': {
paymentNetworkId: 'eip155:43113',
address: '0x5425890298aed601595a70AB815c96711a31Bc65',
decimals: 6,
domainName: 'USDC',
domainVersion: '2'
}
},
paymentOptionCatalog: {
'base-usdc-10k': { contractId: 'usdc-base-sepolia', amount: '10000', payTo: '{{facilitator}}' },
'avax-usdc-10k': { contractId: 'usdc-avalanche-fuji', amount: '10000', payTo: '{{facilitator}}' }
},
restrictedCalls: [
{
method: 'tools/call',
name: 'premium_tool',
acceptedPaymentOptionIdList: [ 'base-usdc-10k', 'avax-usdc-10k' ]
}
]
},
server: {
payToAddressMap: { facilitator: '0x...' },
providerUrlByPaymentNetworkId: {
'eip155:84532': process.env.BASE_SEPOLIA_RPC,
'eip155:43113': process.env.AVALANCHE_FUJI_RPC
},
facilitatorPrivateKeyByPaymentNetworkId: {
'eip155:84532': process.env.FACILITATOR_KEY,
'eip155:43113': process.env.FACILITATOR_KEY
}
}
} )
app.use( middleware.mcp() )
MCP Protocol Flow:
Client → tools/call (no payment)
Server → JSON-RPC error 402 + accepts[]
Client → tools/call + _meta["x402/payment"]
Server → Validate → Simulate → Settle
Server → result + _meta["x402/payment-response"]
import { X402Middleware } from 'x402-mcp-middleware/legacy'
x402-mcp-middleware/
src/
v1/ # v1 implementation (frozen)
v2/ # v2 implementation (multi-network)
legacy/ # Legacy entry point (re-exports v1)
docs/
index.md # Documentation index
v1/ # v1 documentation
v2/ # v2 documentation
tests/
v1/ # v1 tests
v2/ # v2 tests
| Version | Status | Import Path | Multi-Network | MCP-Spec |
|---|---|---|---|---|
| v1 | Frozen | x402-mcp-middleware/legacy |
No | No |
| v2 | Stable | x402-mcp-middleware/v2 |
Yes | Yes |
# GitHub CI tests (no blockchain)
npm run test:ci
# E2E tests (requires .env)
npm run test:v2:server # In terminal 1
npm run test:v2:client # In terminal 2
Contributions are welcome! If you encounter bugs, have feature suggestions, or want to improve the module, feel free to open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
x402 service provider tooling for Azeth — gate Hono endpoints behind x402 payments
A curated collection of open source fintech libraries and resources.
Client SDK, Claude plugin and skill framework for the Pinion protocol. x402 micropayments on Base.
Give any AI agent a crypto wallet. Agents deserve access to money. Pay x402 APIs, receive USDC, check balances — autonomously. Works with Claude, LangChain, AutoGen, CrewAI, and any MCP client. EVM + Solana.
Developer integration tools for adding TDM payments to AI agents, apps, and workflows. CLI, MCP server, and copy-paste examples
Developer integration tools for adding TDM payments to AI agents, apps, and workflows. CLI, MCP server, and copy-paste examples
An open SDK for agentic payments. Let AI agents make payments, hold funds, and move money across chains with policy enforcement and human approval built in.
Golang SDK for A2A Protocol
Client SDK for the Vybe x402 API. Pay-per-call USDC over HTTP and prepaid-credit WebSocket streaming for Vybe's Solana analytics API. Built for AI agents.
Rust SDK for the Machine Payments Protocol
Building blocks for Agentic payments (x402, MPP, AP2) for TypeScript, Rust, Go, Python, Ruby, PHP, Lua, Kotlin and Swift.
Opinionated React Native crypto x AI chat app boilerplate with embedded wallet support, conversational AI, and dynamic UI component injection