How x402 Works with MCP
When an MCP tool requires payment, the flow is:- Client calls a tool on the MCP server
- Server responds with 402 including payment requirements (scheme, network, amount, asset, payTo)
- Client processes payment through the specified payment network
- Client retries the tool call with a payment receipt in the header
- Server validates payment and executes the tool
x402 MCP Validator
The validator connects to an MCP server end-to-end and returns a structured snapshot:.start()
Connects to an MCP server, discovers capabilities, probes for x402 payment support, validates payment requirements, measures latency, and returns a structured snapshot.
| Key | Type | Description | Required |
|---|---|---|---|
endpoint | string | MCP server URL | Yes |
timeout | number | Connection timeout in ms (default 10000) | No |
{ status, messages, categories, entries }
.compare()
Compares two snapshots from .start() and returns a structured diff with added, removed, and modified items per section.
| Key | Type | Description | Required |
|---|---|---|---|
before | object | Snapshot from a previous .start() call | Yes |
after | object | Snapshot from a later .start() call | Yes |
{ status, messages, hasChanges, diff }
Categories
The validator classifies each server with 12 boolean flags:| Flag | Description |
|---|---|
isReachable | Server responded to HEAD request |
supportsMcp | MCP handshake completed |
hasTools | Server exposes at least one tool |
hasResources | Server exposes at least one resource |
hasPrompts | Server exposes at least one prompt |
supportsX402 | At least one tool returned a 402 payment error |
hasValidPaymentRequirements | At least one payment option passed validation |
supportsExactScheme | Has payment options with scheme: 'exact' |
supportsEvm | Has payment options with network: 'eip155:*' |
supportsSolana | Has payment options with network: 'solana:*' |
supportsTasks | Server advertises tasks capability |
supportsMcpApps | Server advertises mcpApps capability |
Validation Pipeline
The validator processes an MCP server in six sequential steps:Validation Codes
The validator uses structured error codes organized by category:VAL -- Input Validation
VAL -- Input Validation
Codes
VAL-001 through VAL-015 cover input parameter validation for both .start() and .compare() methods. Examples: missing endpoint, invalid URL format, missing snapshots for comparison.CON -- MCP Connection
CON -- MCP Connection
Codes
CON-001 through CON-011 cover server connectivity and MCP handshake issues. Examples: server not reachable, handshake failed, tools/list request failed.PAY -- Payment Validation
PAY -- Payment Validation
Codes
PAY-001 through PAY-102 cover x402 payment requirement validation in detail. Checks include: x402 version, resource format, accepts array, scheme, network prefix, amount format, asset address, payTo address with checksum validation, and timeout values.PRB -- Probe
PRB -- Probe
Codes
PRB-004 and PRB-005 cover probe-level issues like unexpected exceptions and no tools available.AUTH -- OAuth
AUTH -- OAuth
Codes
AUTH-002 through AUTH-011 cover OAuth discovery including metadata, PKCE support, protected resource metadata, client registration, and scope detection.CMP -- Comparison
CMP -- Comparison
Codes
CMP-001 through CMP-003 cover snapshot comparison integrity: different server endpoints, missing timestamps, and chronological ordering.Links
- GitHub: FlowMCP/x402-mcp-validator
- x402 Spec: x402.org
- npm:
npm install x402-mcp-validator