error.data is invisibletools/call is refused, and why a correct challenge can still fail itAn MCP server that sells its tools per call over x402 has to answer an unpaid tools/call. The refusal has to do three separate jobs, and it is easy to get the third one wrong while the first two are perfectly done:
We measured a case on 2026-12-04 where jobs 1 and 2 were done correctly โ a complete, valid x402 v2 PaymentRequired document โ and job 3 still failed, because of where that document was placed. This post is the shape of that failure, the places a checker actually looks, and two additive fixes that leave JSON-RPC semantics alone.
An unpaid tools/call answered HTTP 200 with a JSON-RPC error object, and the full challenge under error.data:
POST /mcp {"jsonrpc":"2.0","id":2,"method":"tools/call",
"params":{"name":"x402-format-bytes","arguments":{}}}
HTTP/1.1 200 OK
{"jsonrpc":"2.0","id":2,
"error":{"code":402,
"message":"free trial is wallet-based or disabled โ pay via x402",
"data":{"x402Version":2,
"accepts":[{"scheme":"exact","network":"eip155:8453",
"amount":"10000", // 0.01 USDC, 6 decimals
"asset":"0x8333...2913",
"payTo":"0xAb62...A7Bf",
"maxTimeoutSeconds":120}],
"resource":{"url":"https://minia2a.uk/mcp", ...},
"error":"Payment required"}}}
Everything needed to pay is there. The status code is 200, the transport succeeded, and the document is the same one the HTTP door returns. A client written against this server works.
Three properties of the MCP error path make error.data a bad place to keep the only copy:
code and message; data is whatever the server puts there. There is no standard key for a payment document, so a generic client โ and a generic checker โ cannot assume data.accepts means anything.isError:true; a refusal that a client can act on is a business outcome, not a transport fault. Clients that classify on method rather than reading data will report "server error" and stop.message only. The text above is accurate, but an LLM host that shows the user the error string has no payment terms to act on.The checker we integrated against (the paidmcp/directory check-endpoints.mjs, read 2026-12-04) recognises a payment requirement only in these places:
| Carrier | Shape |
|---|---|
| Result metadata | result._meta["x402/error"] |
| Structured result | result.structuredContent containing the document |
| Result text item | a JSON text content item that parses to the document |
| Payment pointer | {url, status:402, challenge} in one of the above |
| HTTP header | HTTP 402 + PAYMENT-REQUIRED (v2, base64 document) or a v1 JSON body |
Its own comment says the list exists because these are the places standard x402 clients look. Our answer matched none of them: HTTP 200, JSON-RPC error, challenge at error.data. Measured against our listing entry:
FAIL minia2a unpaid tools/call "x402-format-bytes" did not return an x402
payment requirement in a standard format (HTTP 200)
initialize and tools/list passed โ every listed tool name was present โ and the directory entry itself validated. The single failing test was the refusal shape, not the service.
The same checker has a second test: it sends a well-formed payment payload with an all-zero signature, and requires the answer to be either
error differs from the unpaid one, orx402/payment-response (success:false).Otherwise it grades the server as having accepted an invalid signature. Ours did reject it โ correctly โ but the rejection looked like this:
POST /mcp tools/call with _meta["x402/payment"] = zero-signature payload
HTTP/1.1 200 OK
{"error":{"code":402,
"message":"payment verification failed",
"data":"payment could not be verified"}}
(no PAYMENT-REQUIRED header)
No header, no result, and an error the checker could not compare against the unpaid one. From outside, "rejected your payment" and "never looked at your payment" are the same bytes. The server was right and the checker was right; the refusal surface was under-specified.
The smallest change that satisfies the third job is to keep the status code, keep the JSON-RPC body, and add the challenge as a response header โ the document, base64-encoded, exactly what the HTTP door already emits:
// Go, gin โ unpaid tools/call branch. Body unchanged; one header added.
c.Header("PAYMENT-REQUIRED", gateway.BuildPaymentRequiredHeader(challenge))
c.JSON(http.StatusOK, gin.H{
"jsonrpc": "2.0", "id": id,
"error": gin.H{"code": 402, "message": msg, "data": challenge},
})
For the verification-failure branch, build the same challenge with a different error string so the two refusals are distinguishable without reading prose:
ch := gateway.Build402Challenge(serviceID, priceCents, payTo, "base")
ch["error"] = "payment verification failed: " + reason
c.Header("PAYMENT-REQUIRED", gateway.BuildPaymentRequiredHeader(ch))
Two properties make this safe where a status-code change is not: a JSON-RPC client still sees the same envelope and the same error.data, so nothing that already works breaks; and the header travels through the CORS layer as long as access-control-expose-headers names it.
accepts[] array is. Make sure at least one standard carrier holds it._meta copy can coexist; a checker reading either succeeds.error string (or success:false) is enough โ prose alone is not.This is one checker's reading, dated 2026-12-04; directories implement this differently and the ecosystem is young. If you own both ends of the connection, error.data is a perfectly good carrier and costs you nothing. The failure mode above only exists where a third party, following conventions rather than your documentation, has to decide whether your server is payable. That is exactly the situation a listing puts you in.