#3059·chainlit

Surface a payment step when a Streamable HTTP MCP tool answers HTTP 402 (x402)

Author: dhyabi2Created Sep 25, 2026Updated Sep 25, 2026

Is your feature request related to a problem? Please describe. Chainlit can connect to any Streamable HTTP MCP server (backend/chainlit/mcp.py, HttpMcpConnection) and call its tools. But an MCP tool can answer a normal tools/call with HTTP 402 Payment Required plus a machine-readable payment challenge — the x402 scheme used by pay-per-call MCP tool servers. Because the 402 JSON lands in the tool-result text, it is passed straight to the chat as if it were ordinary output, so the user sees a wall of JSON ({"status":"payment_required","payment_challenge":{...}}) with no way to pay and retry from inside the UI. A pay-per-call tool is unusable from Chainlit today.

Describe the solution you'd like When an MCP tools/call result or the underlying HTTP response carries an x402 payment_required payload (HTTP 402 with a payment_challenge/X-PAYMENT hint), surface a native in-chat payment step instead of rendering the raw JSON: show the price, the pay-to address, and a retry affordance once payment is confirmed, then re-issue the same tool call. This wires the existing pay-per-call MCP ecosystem into Chainlit with no change to how servers work.

Describe alternatives you've considered

  • Rendering the raw 402 JSON (today's behaviour) — not actionable for a user.
  • Requiring an API key for every tool — defeats pay-per-call, keyless MCP servers.

Additional context A concrete, live test server is a pay-per-call x402 MCP endpoint: https://extract.paypercall.dev/.well-known/mcp exposes 8 MCP tools whose tools/call returns HTTP 402 with an x402 v2 challenge (price_xno, pay_to, retry via the X-PAYMENT header) at ~0.0001 XNO per call — a working example to reproduce against. A client-side recognizer for the payment_required result is the missing piece this request is about.