@x402check/mcp
An MCP server that lets any AI agent check a counterparty before money moves, with x402check, and pay for x402 resources only after the payee is cleared. It is a stdio server built on the official @modelcontextprotocol/sdk.
Each check screens the counterparty against the OFAC SDN list, phishing and drainer feeds, look-alike domains and on-chain facts. It can also simulate the transaction (API v0.3), and a typed model reads the content the agent acted on. The server verifies every verdict's ES256 attestation against did:web:x402check.xyz before the agent sees an action.
Every check is paid. There is no free tier, and the agent never handles money. The server pays one of two ways:
- From prepaid credits (
X402CHECK_CREDIT_TOKEN): $0.001 a check, or $0.005 when a transaction is simulated, with no payment round trip. Buy a token with POST https://x402check.xyz/v1/credits or the SDK's buyCredits.
- Per call via x402 (
X402CHECK_PAYER_KEY): from a wallet you configure, at the payment network's price ($0.0035 on Base), with a per-payment cap and a total budget.
Install
Claude Code
Without X402CHECK_CREDIT_TOKEN or X402CHECK_PAYER_KEY, the server still starts. Every check then returns not_verified, with instructions to configure one of them. x402check_pay needs X402CHECK_PAYER_KEY: credits pay for checks, never for resources.
Claude Desktop
Add the server to claude_desktop_config.json:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
- Windows:
%APPDATA%\Claude\claude_desktop_config.json
Any other MCP client
Run npx -y @x402check/mcp, or x402check-mcp after npm install -g @x402check/mcp, as a stdio server. The server needs Node.js 22 or later, on its latest security release (22.23.4, 24.22.1 or 26.12.1 or later as of 2026-10-21): it holds a payer key and talks to servers it does not know.
From a local checkout
Then register the built entry point with an absolute path. Quote it if it contains spaces.
Configuration
Security: the payer key is a hot key
- Use a dedicated wallet that holds only a small USDC balance on Base, for example a few dollars. Never use a wallet that holds anything else. The server signs payments to x402check without asking anyone: for its own checks, and for resources on x402check's own site (
X402CHECK_BASE_URL). Payments to any other payee, including a site that names x402check's pay_to, are signed only after x402check allows them (or the user approves a warning).
- A check is paid only to x402check, and never more than a check costs (at most $0.01, above every published price). A 402 from the API origin that names another payee, or asks for more, is not paid (
untrusted_check_payee, over_check_price): a hijacked API domain cannot collect from the payer.
- The payer needs no ETH. The x402 "exact" scheme is gasless for the payer: it signs a USDC transfer authorization (EIP-3009), and the facilitator settles it.
- Spending is bounded.
X402CHECK_MAX_PAYMENT_USD caps each payment (x402 spend controls). X402CHECK_BUDGET_USD caps the total for the process: the payer's, and separately what checks spend from prepaid credits.
- A signed authorization is short-lived. It is valid for at most 15 minutes (the 402's
maxTimeoutSeconds, capped at 900), so a payee that holds one back can settle it only within that window.
- The key is never logged or echoed. It lives only inside the signer, and every tool output is scrubbed of it. At startup, stderr shows the payer's public address and limits, never the key.
- The credit token is a bearer secret, like an API key. Anyone who holds it can spend its balance. It is never logged or echoed, and every tool output is scrubbed of it. Keep the balance small and top it up as needed.
- Solana payment is not built in, to keep the dependency surface of a key-holding process small.
@x402check/client accepts any x402-paying fetch, including a Solana one. The runtime dependencies are the MCP SDK, the x402 and viem packages, zod, and undici (Node.js's own HTTP client, which pins resource connections to checked addresses).
How an agent should use it
The server's instructions and the tool description tell the agent the following:
- Call
x402check_check before it sends funds, signs a token approval, permit or order, or pays an x402 invoice.
- Check the real counterparty: the recipient, spender, operator or
pay_to, not the token contract.
- Pass the chain, the site, and the content it acted on (
context), verbatim.
- Pass
transaction (EVM from, to, value, data) to have the transaction simulated.
- Then follow the action:
The tool does not accept caller assertions (screening, authorization), because claims such as "already screened" are not evidence.
What the agent reads
The tool also returns structuredContent, which conforms to the tool's outputSchema, and the same JSON in a second text block. It holds these fields:
action, reasons, and next (with not_verified);
tier, score, categories and jti, present only when the verdict is trusted;
attestation: { verified, failures, issuer, expires_at };
payment, which depends on how the check was paid:
- per call: the settlement receipt
{ settled, network, transaction, payer } and the payer's { spent_usd, budget_usd };
- from credits:
{ credits_charged_usd, credits_balance_usd }, and the text shows Paid from prepaid credits: $0.001 (balance $0.499);
error: { code, status, message, field?, index?, retry_after?, payment_required? };
result: the API result, with its jws. Its evidence is normalized, so values not in their expected format are dropped.
A failed call (402, 422, 413, 503, network error or timeout) also sets isError: true.
Paying x402 resources: x402check_pay
x402check_check tells an agent what to do; x402check_pay does it. The agent never holds the key, and the key signs a payment only after a verified allow for exactly that payment.
- The server requests the resource. If it does not answer 402, the response is returned as is: nothing is checked or paid.
- On a 402, the payer picks the option it would pay: USDC on an EVM network, Base first. The per-payment cap, the budget, the authorization's lifetime and the agent's
max_usd apply first, so no check is bought for a payment that cannot be made.
- Right before signing, x402check checks that exact option: the payee (
pay_to), network, asset and amount, and the resource's site. The server also passes the agent's context and the 402's own description, which is untrusted text. The ES256 attestation is verified against the pinned issuer and bound to that request (request_hash, payment, domain, chain, freshness).
- The check runs inside the x402 client's
onBeforePaymentCreation hook, on the same object that is then signed. There is no window between the check and the signature for the payee to change.
- x402check's own
pay_to is paid without a check only when the resource is on x402check's own API origin (X402CHECK_BASE_URL). Named by any other site, it is checked like any payee.
- Then the action decides:
allow: the payment is signed, and the resource is returned with its settlement receipt.
warn: the user is asked in the client (MCP elicitation). The request shows the site, the amount, the payee and the reasons. The payment is signed only if they approve. A client without elicitation cannot approve, and neither can the agent: nothing is paid.
block, not_verified: nothing is signed, and the agent is told not to pay that payee any other way.
- One payment per call. The query string and fragment are not sent to x402check, because they may carry the caller's secrets.
- Cancellation. When the MCP client cancels the call (or its request times out), the server stops: the check in flight is aborted, a pending question to the user is withdrawn, and nothing is signed afterwards, even if the user approves late. A signed authorization is sent only if the call is still live. If the cancellation comes after the payment was sent, the request in flight is aborted and stderr says what may still be settled: payee, amount, network, nonce and expiry. The client never receives that result, so check the payer's balance before paying again.
- Limits:
- https URLs on public hosts only. IP literals in private, loopback, link-local, CGNAT, multicast, reserved, documentation or IPv6 transition ranges (IPv4-mapped, NAT64, 6to4, Teredo, site-local) are refused as written. Host names are resolved, and a name with any such address is refused. The connection uses exactly the addresses that were checked, so a name cannot be re-pointed in between (DNS rebinding);
- x402 version 2 challenges only: a version 1 challenge is refused as such (
unsupported_x402_version);
- a signed authorization is valid for at most 15 minutes: a 402 that asks for longer is refused before anything is checked or signed (
authorization_too_long);
- redirects are not followed; a response that shows one was followed is refused, and its body is not shown;
- a resource is asked for gzip or deflate only. A response in any other content coding, Brotli included, is refused from its headers before any of it is decoded (
unrequested_encoding). Node.js's Brotli decoder before 22.23.4, 24.22.1 and 26.12.1 writes out of bounds on a crafted stream (CVE-2026-111497), and a resource can be any server;
- payment headers cannot be passed in;
- a request times out after
X402CHECK_TIMEOUT_MS, and so does reading its body. A 402's body is read at most 64 KiB, within the same time limit; a larger or slower one is refused (challenge_too_large, challenge_timeout), since x402 version 2 challenges travel in the PAYMENT-REQUIRED header;
- the body is capped at 16 KiB of text and stripped of control, format and line-separator characters, and a binary body is not shown;
- the response's
Location is shown only as the origin and path of an http(s) URL, and its Content-Type only as a media type such as application/json. Any other value is not shown.
Arguments: url, method (GET by default), body, headers, max_usd, context. The result's outcome is one of these:
Measured:
- One real payment through the tool in production. The built server was driven over stdio, as an MCP client drives it. A paid x402check call, to our own
pay_to, settled on Base in 3.6 s with 0.2.0 and 4.8 s with 0.3.0 (eval/mcp-pay.ts). That payee is x402check's own address on x402check's own site, a trusted payee that is not checked: this run proves the payment path only. The check path is measured on real merchants' payees below; a paid run against a third-party resource is still to do.
- Payees of real x402 merchants. A random sample of 25 (seed 402) was drawn from the Coinbase x402 Bazaar, and each was checked against production as the tool checks it (
eval/pay-guard.ts). Nothing was paid to them.
- 25/25 were allowed: 100%, 95% CI 86.7–100%.
- 12 had little or no on-chain history and were allowed with a "new address" note, not stopped.
- An earlier run, published as 24/25 with seed 402, was drawn with seed 0 by a flag-parsing bug in the eval (fixed).
Security properties
- Attestations are always verified, and bound to the call. The server checks the ES256 signature with the key in the pinned issuer's
did:web document, never with a jwks_url or a header key.
- That key must also be one of the pinned keys (
X402CHECK_PINNED_KEYS; by default x402check's own). Whoever controls the issuer's domain or deployment cannot swap in a key of their own.
- The server recomputes the signed
request_hash over the exact request it sent. Any field altered or dropped in transit is detected, context (the injected content) and interaction.unlimited included.
- The attestation must also match the call's wallet, audience, interaction type, payment, analyzed domain and chain, and whether a transaction was simulated.
- It must have been issued within the last 5 minutes (plus 5 minutes of clock skew), so an older attestation for the same address cannot be replayed.
- The verdict comes from the signed claims. A response body whose tier, score or categories differ from them is rejected.
- A missing or invalid attestation turns any verdict into
not_verified.
- Fail-closed. Every error path, and
checked: false, becomes not_verified. So does any output that could not be represented safely.
- Response data cannot steer the agent. The signature does not cover evidence, so every evidence value shown must match its expected format: digits, addresses, enums, dates, hostnames or identifiers. Anything else, such as instruction-like text planted in a field, is dropped. The same applies to error details and categories. All strings are also stripped of control, bidi, zero-width, tag and line-separator characters, so nothing can forge a line or hide text.
- Signed is not the same as safe to read. A caller chooses some values the provider signs, such as
aud (any string up to 256 characters). x402check_verify_attestation therefore shows every claim only in its expected format: the audience as an http(s) URL, a DID or a host name, the payment binding field by field, and so on. Anything else reads (not shown: unexpected format), in the text and in structuredContent, for valid and invalid attestations alike.
- A third party's
Location and Content-Type headers are shown only as a URL's origin and path, and as a media type.
- Why a payment was refused is recorded by the server's own code at the moment it refuses, never read from an error message, which can carry the 402's own fields.
- Outputs conform to their
outputSchema on every path, including errors, and never carry the payer key or the credit token.
- stdout carries MCP messages only. Diagnostics go to stderr, and an invalid configuration exits non-zero at startup.
What the address checks do not cover
- With a custom
fetch (ServerConfig.fetch, for embedding), resource host names are not resolved by this server. That fetch must refuse private destinations and content codings it did not ask for itself, and it must honor redirect: "manual". A response that shows a followed redirect is still refused.
- x402check's own API and DID document are fetched with Node.js's fetch over TLS, and decoded as the installed Node.js decodes them. Only resources go through the content-coding refusal.
- Translation prefixes an operator chose (a network-specific NAT64 prefix, for example) look like ordinary public addresses, and so do public addresses that a local firewall or VPN routes to internal services.
- The address is checked, not the service. An internal service published on a public address, with a valid certificate, is reachable like any public site.
Limits
x402check reports what the lists, the chain, the simulation and the content in front of it reveal. It cannot flag an unknown drainer that is simply sent funds (0/30 in the held-out evaluation), and it mostly misses unlisted phishing domains when no feed has them (0–4 of 60). Sanctions screening covers direct OFAC listing only. x402check_methodology returns the full list, and docs/EVIDENCE.md has the measurements.
Programmatic use
The package also exports the server factory, so you can connect it to another transport:
Two options exist only in code:
fetch: the fetch for API calls, DID resolution and x402check_pay's resource requests (tests, proxies). It receives redirect: "manual" for resources and must honor it. With it, resource host names are not resolved by this server (see above).
log: where diagnostics go, such as a payment sent for a call the client then cancelled. The default is stderr. They never carry secrets.
Development
In this repository, @x402check/client is a file:../client dependency. The published package depends on the npm release instead, "@x402check/client": "^<version>" (the signing guard, @x402check/client/guard, is what x402check_pay runs). This release needs @x402check/client 0.4.0 or later: the pinned attestation keys (X402CHECK_KEY_THUMBPRINTS, the guard's pinnedKeys) arrived there. A prepublishOnly guard refuses to publish while any dependency still points at a local path.
MIT © Caio Vicentino