๐Ÿ“… Historical page. This content reflects minia2a as of its publication date and is kept for the record. Current model: x402 pay-per-call in USDC on Base only, 5 free trial calls per signed wallet, no credits and no top-up rail. โ†’ See current
โ† All posts

A payment challenge inside error.data is invisible

2026-12-04 ยท what a discovery checker reads when an MCP tools/call is refused, and why a correct challenge can still fail it

An 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:

  1. tell the human or agent reading it why nothing was delivered;
  2. tell a paying client where and how much to pay;
  3. be readable by a third party that discovers your server โ€” a directory checker that never reads your docs and knows only the conventions of the ecosystem.

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.

1. The shape we returned

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.

2. Why that is the wrong sole carrier

Three properties of the MCP error path make error.data a bad place to keep the only copy:

3. Where a checker looks

The checker we integrated against (the paidmcp/directory check-endpoints.mjs, read 2026-12-04) recognises a payment requirement only in these places:

CarrierShape
Result metadataresult._meta["x402/error"]
Structured resultresult.structuredContent containing the document
Result text itema JSON text content item that parses to the document
Payment pointer{url, status:402, challenge} in one of the above
HTTP headerHTTP 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.

4. The second gate: a rejected payment must look rejected

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

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.

5. The additive fix

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.

Budget the header. The v2 document for a large advertisement (input schema, output example, extensions) is not small. The plain-HTTP door already has a line-length budget; measure the base64 length against your proxy's header limit before shipping, or a big tool's challenge will be truncated exactly where a payer needs it.

6. Rules that generalise

  1. The challenge is a document, not a status. "Payment required" is not the message; the accepts[] array is. Make sure at least one standard carrier holds it.
  2. Emit it on every carrier that costs you nothing. A header and a result _meta copy can coexist; a checker reading either succeeds.
  3. Distinguish unpaid from bad payment in a machine-readable field. Same status, different error string (or success:false) is enough โ€” prose alone is not.
  4. Do not turn a business refusal into a transport error that generic clients will retry or surface as "server down". If you must use the error path for compatibility, add the standard carriers alongside it.

7. Caveats

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.