Hostile clients and L402 MCP gates: a checklist

An L402 gate puts a Lightning payment in front of an MCP server or tool: no token gets a 402 with a macaroon and an invoice, and a token (the macaroon plus the payment's preimage) gets the call. The paying client is usually an agent you do not control, so assume some clients will replay, forge, flood and send garbage. Each item below names a case, what the gate should do, and how to check it. Last checked: 12 October 2026.

Tokens

Invoices

Headers and bodies

How to check

Point these at your own route and port. The first should print 401; the second 431 or 400. For a replay, send one valid token twice: the second call must get 401.

curl -s -o /dev/null -w '%{http_code}\n' -X POST -H 'Authorization: L402 not-a-token' -H 'Content-Type: application/json' --data '{}' http://127.0.0.1:3000/mcp
curl -s -o /dev/null -w '%{http_code}\n' -H "Authorization: L402 $(head -c 40000 /dev/zero | tr '\0' A)" http://127.0.0.1:3000/mcp

The paying side

A gate that refuses bad clients is half the picture; the agent that pays also has to refuse bad sellers. Payer Safety Tests sends mock 402 quotes with a changed price, a different payee or an amount over the cap, to check that your payer code refuses them. Local only, no real funds. Three of its hostile sellers are free to try first: the free sample. To check the tool definitions behind a gate, the free MCP Safety Lint runs offline.

Related: MCP conformance vs safety, DNS rebinding in local MCP servers, Testing an agent's spend guard against a hostile 402 seller and where to list a paid API or MCP server.