MCP payment tools
The Pay MCP server gives an MCP host a controlled way to discover Pay-enabled APIs, inspect and fund an account, publish provider skills, sell local inference, and call paid HTTP endpoints. It runs over stdio and applies the caller's account, network, file access, spending, destination, payment permission, and approval rules to each call. See the agent protocol integrations overview, ACP payment middleware, managed MCP service providers, CLI payment operations, and runtime inference marketplace selling pages for related agent payment paths.
MCP server boundary
Server startup
The MCP server is the local bridge between an MCP host and Pay's payment runtime. The pay mcp command starts a stdio session, keeps it alive until the session ends, and sends logs to stderr so protocol messages on stdout stay valid.
The stdio bridge also normalizes a known empty server/discover probe by adding the protocol metadata that the MCP library requires. Other JSON-RPC messages pass through unchanged. The server identifies itself as Pay and advertises tools through the MCP server capability.
References: rust/…/lib.rs• L26-67 rust/…/lib.rs• L69-119 rust/…/server.rs• L260-275
Caller scope
The caller scope is the per-request view of the account and permissions that payment tools may use. It keeps local file access separate from hosted access and places an approval gate in front of each signing operation.
The scope can fix the network, select a named account, and provide an RPC endpoint for non-mainnet work. It also defines which network destinations curl may reach. A local session can read the user's accounts and files and retain localhost or development access. A hosted session can provide its own tenant context and must use a public-only destination policy, so it cannot sell inference on the user's machine.
Each call can also carry fail-closed payment permissions. These permissions restrict payment origins, networks, assets, recipients, and amounts before a credential is signed. Per-origin rules can refine a cap, but they do not add an origin that the main origin list does not allow.
Hosted spending rules can run before the MCP client's prompt. They can enforce a per-call ceiling and a daily cap. They reject recurring payments because future pulls cannot be recorded safely under that policy. A reservation is released if signing fails and kept only after a signature is produced.
References: rust/…/context.rs• L16-64 rust/…/context.rs• L91-141 rust/…/permissions.rs• L15-43 rust/…/permissions.rs• L185-221 rust/…/policy.rs• L157-241 rust/…/policy.rs• L292-329 rust/…/server.rs• L49-55
Payment permissions
MCP payment permissions are an optional strict YAML policy for local calls and a hosted policy for tenant calls. They convert allowed origins, Solana networks, assets, payment caps, and recipient wallets into checks that run against the payment challenge before signing.
The checks cover direct MPP and x402 charges, x402 allowance limits, batch settlement payments and escrow, and the deposit needed to open an MPP session. Recipient limits apply to the primary destination and every split leg. Session checks also return the approved payout so the session opener uses the same destinations that the policy reviewed. Unsupported MPP subscription payments are rejected when this permission layer is enabled. Native SOL and unknown assets do not become USD-valued payments by assumption.
Hosted permissions allow mainnet known stablecoins. A tenant can also provide an approved recipient list; when it does, every payment destination must be on that list. Amount limits still come from the hosted spending policy.
References: rust/…/permissions.rs• L15-43 rust/…/permissions.rs• L185-221 rust/…/permissions.rs• L224-392 rust/…/policy.rs• L196-241
Tool surface
The server exposes one MCP tool surface with shared instructions for capability checks, provider selection, payment handling, and failure reporting. Local servers also expose sell_inference; hosted servers hide that route and remove it from their instructions because they have no local worker to run.
Hosted servers also keep catalog detail requests on the public internet. Local servers may use the wider outbound policy needed for local catalog data.
| Tool | Purpose |
|---|---|
list_catalog | Answer broad Pay capability questions with a compact category view. |
search_catalog | Rank providers and endpoints for a specific task. |
get_catalog_entry | Turn one provider choice into a detailed call plan. |
create_skill | Validate a provider skill and optionally prepare it for publication. |
get_balance | Show wallet and program-backed credit balances for the active account and network. |
topup | Create a funding QR code and return the funding address. |
sell_inference | Publish a paid local inference endpoint and manage its worker. |
curl | Send free or paid HTTP requests and handle payment challenges. |
References: rust/…/server.rs• L15-55 rust/…/server.rs• L57-257 rust/…/server.rs• L260-275 rust/…/mod.rs• L1-8
Catalog and skill tools
Catalog discovery
The catalog is the agent's map of Pay-enabled providers. list_catalog is the first tool for questions about what Pay can do. It returns providers grouped by category by default and can include expanded service metadata when the user needs it.
search_catalog follows a known capability with a concrete task. It ranks providers and returns endpoint candidates with URLs, methods, price ranges, and match reasons. It can refresh the catalog or bypass the CDN cache when the local copy may be stale. The agent should choose an endpoint only when it clearly fits the task. If the result is incomplete or close candidates remain, it should inspect one provider or ask the user before paying.
Hosted catalog searches apply a public-only outbound rule while loading endpoint details. This prevents catalog data from directing a hosted server to local or private network targets.
References: rust/…/server.rs• L94-134 rust/…/list_catalog.rs• L7-32 rust/…/list_catalog.rs• L76-159 rust/…/search_catalog.rs• L10-35 rust/…/search_catalog.rs• L85-119 rust/…/search_catalog.rs• L135-220
Provider inspection
get_catalog_entry turns a selected provider into a precise call plan. It returns endpoint methods, paths, usage notes, complete Pay URLs, and price ranges. The agent should copy the returned endpoint url into curl instead of replacing it with the upstream service URL.
The tool loads missing endpoint details under the server's outbound policy. This lets local servers inspect their configured catalog sources while hosted servers stay on public destinations. The step lets the agent check the request shape and likely cost before the wallet signs. It also limits the risk that a broad search result selects the wrong endpoint.
References: rust/…/server.rs• L136-150 rust/…/get_catalog_entry.rs• L14-70 rust/…/get_catalog_entry.rs• L73-127
Skill authoring
create_skill validates a complete provider PAY.md entry before it enters the pay-skills registry. The check covers frontmatter, endpoint shape, category, HTTPS service URLs, pricing precision, and the expectation that priced endpoints return HTTP 402.
The optional write is allowed only for the registry's provider path layouts and only when the parent directory matches the provider name. A hosted server cannot write the file because it has no access to the user's files. The tool validates provider facts but does not discover them. A valid entry still needs the normal catalog check and endpoint probe before agents can rely on it.
References: rust/…/server.rs• L228-257 rust/…/create_skill.rs• L7-20 rust/…/create_skill.rs• L27-136 rust/…/create_skill.rs• L139-240
Account and funding tools
Balance checks
get_balance checks whether the selected Pay account has usable funds for a paid call. Mainnet is the default network, but the caller scope can force another network or account. The result reports supported stablecoin balances and program-backed USD credits.
Missing accounts or public keys are setup errors, not empty balances. When both balance sources are available and empty, a local server guides the agent to offer either topup or sell_inference; a hosted server offers only topup.
References: rust/…/server.rs• L152-168 rust/…/get_balance.rs• L6-24 rust/…/get_balance.rs• L25-108
Top-up actions
topup prepares a funding action for a mainnet Pay account. It resolves a named account or supplied address, creates a target URL, renders a PNG QR code, and returns the funding address with instructions. It does not buy funds, send a transaction, or confirm that a transfer arrived. The image is returned to the MCP client; a local session also saves a temporary PNG path, while a hosted session does not write to disk.
The user selects one of these paths:
mobile_walletcreates a Solana Pay USDC request. The amount defaults to 5 USDC. An amount of zero leaves the amount open.onrampcreates a QR target for Coinbase, PayPal, or Venmo. The user completes the purchase and transfer with that provider.
References: rust/…/server.rs• L170-188 rust/…/topup.rs• L16-87 rust/…/topup.rs• L94-187 rust/…/topup.rs• L190-229
Inference selling
sell_inference is the local counterpart to topup. It publishes a paid OpenAI-compatible endpoint on pay-connect, starts a local pay sell serve worker, and sends buyer earnings to the active Pay account. It is available only to local MCP sessions.
Creation requires either a flat per-request price or per-token prices with a per-request maximum. The endpoint has an earn cap from $0.01 to $2.00. If the caller omits the cap, the tool asks through MCP elicitation; accepting that form both chooses the cap and consents to publish the endpoint. The worker uses an empty directory with tools refused by default. A chosen working directory or enabled tools gives buyers more access and is shown in the consent message.
The same tool reports status, changes pricing, or stops an endpoint. Stopping deletes the remote endpoint while keeping earnings already settled. Hosted sessions cannot use this tool because they have no local machine to serve from.
References: rust/…/server.rs• L190-226 rust/…/sell_inference.rs• L24-132 rust/…/sell_inference.rs• L134-155 rust/…/sell_inference.rs• L251-397 rust/…/sell_inference.rs• L400-505 rust/…/sell_inference.rs• L635-728
Approval and paid request flow
MCP elicitation
MCP elicitation is an approval request shown by the connected MCP client. The local policy prefers a platform prompt such as Touch ID, Windows Hello, or polkit when one is available. It uses MCP elicitation when no local prompt is available or when PAY_FORCE_ELICITATION=1 is set. Hosted policy checks can deny a payment before the client sees a prompt.
Payment elicitation includes the amount and reason and declares a required approved boolean. Accept approves unless the response explicitly carries approved: false. Decline, cancel, unsupported actions, transport errors, and timeouts fail closed as AuthDenied. Each round trip has a five-minute outer timeout.
Hosted approval chains apply the spending policy first and the client's prompt second when the client supports elicitation. A hosted client without prompt support cannot approve a raw wallet proof because that proof has no amount for the spending policy to bound. Policy reservations are released when the signing operation fails, so a declined or failed operation does not consume the daily allowance.
File bodies use a separate elicitation step. The request names the file, byte count, method, and destination. Pay reads the file only after approval and rejects it if the file changes before the request is sent or retried.
Hardware-wallet recovery can also use elicitation. When the selected Ledger is not ready, the client can ask the user to connect it or choose an available configured account before any payment is signed.
References: rust/…/context.rs• L51-63 rust/…/context.rs• L117-139 rust/…/auth.rs• L40-80 rust/…/auth.rs• L83-183 rust/…/auth.rs• L196-317 rust/…/policy.rs• L196-329 rust/…/curl.rs• L300-328 rust/…/curl.rs• L1018-1087
Paid curl execution
curl is the MCP HTTP tool for free endpoints and Pay gateway endpoints. It accepts a URL, method, headers, and either an inline body or a local file. It checks cached catalog method, path, media type, and JSON schema rules before sending when catalog data is available. Local files must be inside an MCP-declared root and must pass file approval before they become request bodies.
When a request returns HTTP 402, the tool selects a supported offer that the active account can fund. Before signing, optional MCP permissions check the challenge's origin, network, asset, amount, and every payment destination. Hosted calls also reject a payment challenge issued by a different origin from the requested URL.
The tool can handle MPP charge, x402 exact, x402 allowance, x402 batch settlement, wallet sign-in, MPP session opening, and subscription activation. Permission-enabled calls reject MPP subscriptions. Wallet sign-in has its own approval; if sign-in does not grant access and the challenge offers a payment fallback, the tool asks for a second approval before paying.
It can attach a valid cached wallet sign-in credential for the selected account before the first request. Payment permissions can reject a method before signing. Otherwise the caller's approval gate signs the needed credential and the tool retries the original request. MPP charge retries reuse the same payment attempt material when the earlier result is unresolved, which avoids signing a second charge. A second 402 or an unknown payment scheme is an error.
The tool reuses valid subscription, MPP session, and batch authorization within one MCP connection. Session authorizations are isolated by payer, HTTP method, and route. Requests on one session channel are serialized, stale authorization is removed after failed reuse, and batch state advances only after a completed response carries a valid settlement receipt. Batch escrow is checked separately from the request price. A corrective batch challenge can resynchronize the channel and retry once.
The response keeps content useful to the MCP client. Text and JSON stay inline up to a size limit. Images use image content. Audio, video, and PDFs use file resource links, while other binary or oversized text is written to a temporary file. Large identifiable base64 media inside JSON is also extracted to files, with the JSON retaining a compact placeholder; extracted images remain visible as image content. Multipart local uploads use the separate filesystem-authorized pay fetch path.
The diagram shows how discovery becomes an approved request and then an MCP result.
flowchart LR
A[User task] --> B[list_catalog or search_catalog]
B --> C[get_catalog_entry]
C --> D[curl with exact Pay URL]
D --> E{Free or cached authorization?}
E -->|Yes| F[Send request]
E -->|No and HTTP 402| G[Choose fundable offer]
G --> H[Check origin and payment permissions]
H --> I[Apply caller payment policy]
I --> J{Allowed?}
J -->|No| K[Return denial]
J -->|Yes| L[Request approval]
L --> M{Approved?}
M -->|No| N[Return denial]
M -->|Yes| O[Sign credential]
O --> P[Retry request]
F --> Q[Return MCP content]
P --> Q
References: rust/…/server.rs• L57-93 rust/…/curl.rs• L95-114 rust/…/curl.rs• L222-297 rust/…/curl.rs• L1111-1223 rust/…/curl.rs• L1225-1669 rust/…/curl.rs• L1672-1802
Elicitation coverage
Protocol coverage
The approval module has direct unit coverage for payment prompt content, the required approval field, hardware-account choices, file-upload prompts, and fail-closed decision mapping. Accept succeeds unless the content explicitly denies approval. Decline, cancel, unsupported actions, timeout, and transport failure become denial.
The end-to-end test pairs an in-process MCP client and server over a duplex transport. It checks that a synchronous AuthGate::authenticate call reaches the client's elicitation handler and covers accepted, declined, and cancelled responses. These transport tests are currently ignored because rmcp 3.5 stalls on the nested duplex elicitation response. The test-only MCP client feature keeps this support out of the production build.
The HTTP end-to-end suite adds real MCP initialization and tools/call coverage for curl. It checks normal and error HTTP results, text and binary response mapping, hosted file restrictions, and cleanup when a blocking request stalls or panics. It does not make the ignored nested elicitation round trip active; payment approval coverage remains bounded by the protocol tests and the payment branches in curl.
References: rust/…/auth.rs• L320-527 rust/…/elicitation_e2e.rs• L1-11 rust/…/elicitation_e2e.rs• L31-107 rust/…/elicitation_e2e.rs• L110-160 rust/…/curl_http_e2e.rs• L1-18 rust/…/curl_http_e2e.rs• L198-370 rust/…/curl_http_e2e.rs• L400-489 rust/…/Cargo.toml• L29-35
Request coverage
The paid curl path passes the caller's approval override into every supported payment branch. Coverage includes MPP, x402 exact, x402 allowance, x402 batch settlement, wallet sign-in, MPP session opening, and subscription activation. Payment permissions also cover recipient splits, session payouts, and batch escrow. File sharing remains a separate approval because consent to send data is different from consent to sign payment.
The coverage boundary is deliberate. Free requests and requests served by valid cached authorization need no new wallet approval. A recognized paid challenge must pass the selected permission policy and approval gate. Wallet sign-in needs interactive approval because it proves wallet identity rather than stating a bounded payment amount. Batch settlement also needs channel state, escrow permission, and a valid receipt before its local watermark changes. An unknown or repeated challenge returns an error instead of claiming success. An unresolved MPP attempt reuses its payment material rather than creating a second charge.
References: rust/…/curl.rs• L1152-1165 rust/…/curl.rs• L1225-1669 rust/…/curl.rs• L1717-1802 rust/…/permissions.rs• L273-392 rust/…/elicitation_e2e.rs• L68-112
Change checklist
When these files or sections are changed, remember to consider these:
- Keep tool names, descriptions, shared instructions, and local versus hosted tool exposure aligned.
- Keep
pay mcpstartup aligned with the stdio transport and discovery-probe compatibility behavior. - Keep the per-call scope aligned with account selection, forced network, RPC lookup, signer choice, file access, payment permissions, approval handling, and outbound destination policy.
- Keep hosted spending limits ahead of client prompts and preserve daily-cap recording.
- Keep policy reservations released on declined or failed signing and retained only after a signature is produced.
- Keep file approval separate from wallet approval and preserve declared-root, snapshot, and retry rules.
- Keep catalog endpoint URLs as Pay URLs from discovery through
curl. - Keep catalog detail loading under the correct local or hosted outbound policy.
- Keep permission checks aligned across MPP charges, x402 variants, session deposits and splits, batch request amounts, batch escrow, and approved recipients.
- Keep payment challenges tied to the requested origin in hosted public-only sessions.
- Pass the same approval override into every payment challenge branch and each elicited local action.
- Keep cached wallet credentials scoped to the selected account.
- Keep MPP attempt material stable across unresolved retries so a lost response cannot cause a second charge.
- Keep MPP session keys scoped to payer, method, and route and remove cached authorization after failed reuse.
- Keep x402 batch state serialized and advance its watermark only from a valid served-response receipt, including corrective challenge handling.
- Keep balance guidance consistent with whether
sell_inferenceis exposed. - Keep local inference consent aligned with the earn cap, recipient, worker isolation, and endpoint lifecycle.
- Keep response media routing aligned with MCP content types, temporary-file limits, and embedded media extraction.
- Keep real MCP HTTP end-to-end coverage aligned with hosted file behavior, response content types, and supervised worker cleanup.
- Keep the ignored duplex tests and test-only MCP client feature aligned with transport behavior before treating end-to-end elicitation as active.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The MCP client cannot show elicitation and no local approval prompt is available | A payment or local publish action cannot obtain consent | Use an MCP client with elicitation support or provide a local approval method. Do not bypass the gate. |
| The caller declines, cancels, times out, or returns an unsupported approval result | Signing or the paid request stops with an authorization error | Treat every non-accept result as denial and ask before retrying. |
| A hosted policy rejects the amount, payment method, recurring payment, per-call ceiling, or daily cap | The paid request stops before signing | Use a request and policy that can record the intended payment. |
| A payment permission file has unknown fields, conflicting amount settings, or an invalid network, asset, origin, recipient, or cap | The permission policy cannot be compiled, or the payment is denied | Use the strict permission schema and validate each configured value. |
| A payment challenge names a recipient or split wallet outside the approved recipient list | The payment is blocked before signing | Approve every intended destination or use a provider challenge with allowed recipients. |
| A hosted request targets a destination outside its public-only network policy, or its challenge comes from another origin | The HTTP request or payment is blocked before the provider call | Use a public destination and pay only the requested origin. |
| A body file has no declared root, is outside a root, is a symlink, exceeds 64 MiB, or changes after approval | The body is rejected before the request or payment | Declare the correct root and retry with the reviewed file. |
| The selected network has no account or public key | Balance and payment preparation fail | Run setup and select an account for the intended network. |
topup lacks an on-ramp provider or receives an invalid amount or QR scale | No funding QR result is produced | Use a supported provider and a finite non-negative amount with a scale from 1 to 32. |
sell_inference is called from a hosted session | No local endpoint can be created | Run the local pay mcp server when serving inference. |
| Inference creation omits pricing, mixes pricing modes, or omits a cap for per-token pricing | The endpoint is not published | Choose one valid pricing mode and provide its required maximum. |
| Inference creation omits the earn cap without elicitation support | The endpoint is not published | Ask the user for a cap from $0.01 to $2.00 through a client with elicitation. |
| Discovery returns a stale or unsuitable endpoint, or hosted detail loading targets a private host | The agent may prepare the wrong paid call, or discovery fails | Refresh discovery, inspect the selected provider, and use the exact Pay URL from a permitted destination. |
| A cached subscription or MPP authorization is rejected | The request needs a fresh challenge or fails after stale state is removed | Let the tool discard stale authorization and complete a new approval flow. |
| A hosted wallet sign-in challenge reaches a client without prompt support | Wallet identity cannot be proved and no silent raw proof is accepted | Use an MCP client that supports elicitation or use a direct payment offer. |
| A batch settlement receipt is missing or invalid, or the escrow exceeds permission | The channel watermark does not advance, or the payment is denied | Retry the same cumulative credential only after a valid receipt and keep escrow within policy. |
| A paid retry returns another 402 or an unknown scheme | The tool returns an error instead of unverified success | Check the provider offer, account funds, network, and supported payment protocol. |
| The in-process duplex elicitation test hits the known rmcp transport hang | The end-to-end test can hang instead of reporting a result | Keep the transport tests ignored until the MCP dependency supports the round trip. |
| A real MCP HTTP worker stalls or panics during a blocking request | The supervised test worker is terminated and the request does not return a normal tool result | Keep the subprocess deadline and worker reaping checks in the HTTP end-to-end boundary. |
Key files
| File | Why to read it |
|---|---|
| rust/…/lib.rs | Shows the stdio server lifecycle and discovery-probe compatibility bridge. |
| rust/…/context.rs | Defines per-call account, network, file, destination, payment-permission, and approval scope. |
| rust/…/permissions.rs | Defines payment permission configuration, recipient checks, and challenge checks for local and hosted calls. |
| rust/…/policy.rs | Defines hosted spending limits, approval order, and reservation release. |
| rust/…/server.rs | Defines the MCP tool surface, routing guidance, and local versus hosted capabilities. |
| rust/…/auth.rs | Defines MCP elicitation, file consent, hardware-account choice, and fail-closed approval mapping. |
| rust/…/curl.rs | Shows request validation, file consent, origin enforcement, payment challenge handling, cached authorization, retries, settlement state, and MCP response content. |
| rust/…/list_catalog.rs | Shows the compact category view used for capability questions. |
| rust/…/search_catalog.rs | Shows ranked provider and endpoint selection, refresh behavior, and outbound policy for actionable tasks. |
| rust/…/get_catalog_entry.rs | Shows how a provider becomes an exact paid-call plan under the outbound policy. |
| rust/…/create_skill.rs | Shows provider skill validation, local write access, and the publication boundary. |
| rust/…/get_balance.rs | Shows account, network, wallet-token, credit, and funding guidance resolution. |
| rust/…/topup.rs | Shows mobile-wallet and on-ramp funding actions and QR response content. |
| rust/…/sell_inference.rs | Shows local inference publishing, consent, worker isolation, earnings, and lifecycle actions. |
| rust/…/elicitation_e2e.rs | Shows the intended client/server elicitation round trip and its current transport limit. |
| rust/…/curl_http_e2e.rs | Shows real MCP initialization and curl response, hosted-file, and worker-supervision coverage. |