Feature request: recognise pay-per-call (x402) MCP tool results with a per-call payment step
Feature: Surface pay-per-call (x402) MCP tool results as a per-call payment step
What
When a custom MCP HTTP server tool returns an HTTP 402 response with an x402 payment challenge (nano:mainnet, XNO), the agent currently passes the raw error text to the model. This feature request is for the MCP client to detect the x402 payment_required response, surface it to the user as a per-call payment step, and retry the tool call with the proof of payment.
Why
Several MCP servers now offer pay-per-call access via x402 — no API key, no subscription, just 0.0001 XNO per call. AnythingLLM's MCP integration (server/utils/MCP/index.js) already connects to any Streamable-HTTP / SSE MCP server the user adds via the MCP Servers admin panel. When a tool returns an x402 payment_required response, the current catch path serialises it as text via returnMCPResult and returns it to the model as an error message — the agent sees text about a payment challenge but cannot act on it.
Recognising the x402 structure lets AnythingLLM surface a one-click payment step: show price_xno and pay_to from the challenge, send the payment (Nano is instant and feeless), then retry with the on-chain proof.
Reference implementation
The Vend API (extract.paypercall.dev/mcp, 8 tools) returns a working x402 v2 response:
GET https://extract.paypercall.dev/api/v1/extract?url=https://example.com
-> 402
{
"price_xno": 0.0001,
"accepts": [{"scheme": "exact", "network": "nano:mainnet", "asset": "XNO", "payTo": "nano_1yo6c1t644zhnm...", "amount": "100000000000000000000000"}]
}The model then sends 0.0001 XNO to the payTo address (settles in ~1s, feeless), and retries the endpoint with the block hash as the X-PAYMENT header — the tool call succeeds.
Scope
This is purely a client-side change in the MCP tool execution path (server/utils/MCP/index.js): intercept the tool result before serialisation, detect the x402 payment_required structure, and route it to a payment confirmation flow. No upstream server change is needed — any x402-capable MCP server works.
Source: Mintplex-Labs/anything-llm