Introducing a new way to review your PRs.

Read the announcement

solana-foundation / pay

CLI for Agentic payments (x402, MPP, AP2).

View on GitHub

30 documents · Updated Nov 11, 2026

docs / agent-protocol-integrations

Agent protocol integrations

Rust gives agent clients a payment-aware way to use Pay services through two protocol paths. The MCP path exposes payment tools to a protocol host, while the ACP path supports agent launch, protocol relaying, and direct agent control. Both paths keep account choice, user approval, and payment retry under Pay's control. The payment CLI supplies the local launch and relay entry points.

Integration model

MCP means Model Context Protocol. ACP means Agent Client Protocol. An MCP host calls named tools, while an ACP harness or client exchanges JSON-RPC messages with an agent. Pay joins both paths to a local or tenant account and turns HTTP 402 Payment Required responses into an approved payment and a retry.

The two paths serve different boundaries:

PathAgent-facing boundaryMain capability
MCP serverA protocol host that can call toolsDiscover paid services, make paid HTTP calls, inspect funds, fund an account, and offer local inference for sale
ACP launcher and middlewareAn ACP-compatible agent harnessRoute agent inference through a paid provider and preserve ACP traffic while adding optional delivery behavior
ACP clientA caller that drives an ACP agentStart an agent, create sessions, send prompts, and consume streamed turn events

This diagram shows how an agent reaches a paid service through each protocol path.

flowchart LR
    Host[Agent host] --> MCP[Pay MCP server]
    MCP --> Service[Paid API]
    Service -->|402 challenge| MCP
    MCP --> Approval[Account and user approval]
    Approval --> MCP
    MCP -->|paid retry| Service

    Client[ACP client or harness] --> ACP[Pay ACP boundary]
    ACP --> Payer[Payer route or agent process]
    Payer --> Inference[Paid inference provider]
    Inference -->|402 challenge| Payer
    Payer -->|approved retry| Inference
    ACP --> Client

MCP server integration

The MCP server is the direct tool interface for agent hosts. pay mcp runs it over standard input and output, while the library exposes the server and context types for a caller-specific setup. The process can attach fail-closed payment permissions to its local context before it accepts calls. It also repairs one incomplete discovery probe so compatible hosts can continue protocol negotiation without changing other messages. The discovery repair adds only the missing protocol metadata and leaves valid discovery and unrelated JSON-RPC frames unchanged. rust/…/lib.rs• L19-67 rust/…/lib.rs• L69-119 rust/…/server.rs• L15-55 rust/…/context.rs• L18-45

Call context and spending policy

The call context is the identity and safety boundary for one MCP tool call. It resolves the accounts and overrides the call may use, how signatures must be approved, whether local files are available, and which network destinations are allowed. A local context uses the user's account store and process overrides. A hosted context can supply a tenant scope and restrict requests to public destinations without changing the tools. rust/…/context.rs• L18-45 rust/…/context.rs• L47-75 rust/…/context.rs• L188-237

Hosted approval adds a hard spending policy before any client prompt. The policy uses an atomic ledger to enforce a per-call ceiling and a daily cap for each subject. It rejects recurring authority and payments without a stated amount. It also refuses wallet sign-in when no MCP client can show an approval prompt because a raw sign-in proof has no amount for the policy to bound. A reservation remains only after signing succeeds, so a declined prompt or later signing failure does not consume the allowance. rust/…/policy.rs• L18-40 rust/…/policy.rs• L144-193 rust/…/policy.rs• L234-373

The MCP process can also apply a separate payment permission set to each payment challenge. A permission set can limit exact origins, Solana networks, recipients, payment amounts, and allowed assets. It validates strict YAML before use and checks MPP, x402, session deposits, and batch escrow against the compiled rules. Unsupported payment forms fail closed when these permissions are enabled. Hosted permissions are limited to mainnet and known stablecoins, while approved recipient lists cover every payment leg, including splits. rust/…/lib.rs• L19-24 rust/…/permissions.rs• L15-44 rust/…/permissions.rs• L185-221 rust/…/permissions.rs• L273-392

References: rust/…/context.rs• L18-75 rust/…/context.rs• L188-237 rust/…/policy.rs• L18-40 rust/…/policy.rs• L144-193 rust/…/policy.rs• L234-373 rust/…/lib.rs• L19-24 rust/…/permissions.rs• L15-44 rust/…/permissions.rs• L185-221 rust/…/permissions.rs• L273-392

Tool workflow

The catalog tools help an agent move from a broad question to one paid request. The normal order is to list capabilities for a feasibility question, search for a provider for an actionable task, inspect one provider when needed, and then send the exact returned endpoint to the HTTP tool. Search returns ranked candidates with endpoint and price context. Provider detail returns the full endpoint list and exact URLs. This keeps provider choice tied to current catalog data instead of agent memory. See MCP payment tools for the tool-level contract.

The HTTP tool is the main payment action. It accepts normal request data, checks cached service rules when available, handles recognized MPP or x402 challenge types, and returns the final service response to the host. The balance tool reports stablecoin and program-credit funds for the active account. The top-up tool prepares a QR image and funding details for either a Solana mobile-wallet transfer or a selected on-ramp; it does not move funds. The inference-selling tool can publish a bounded paid endpoint and start a local worker, but only in a local MCP session. The provider tool validates a skill before publication. Hosted deployments can use the shared tools without a local inference worker; see managed MCP service providers for that boundary. rust/…/server.rs• L57-188 rust/…/server.rs• L190-257 rust/…/topup.rs• L96-187 rust/…/sell_inference.rs• L134-155 rust/…/sell_inference.rs• L251-398

Provider publication

The provider publication tool turns a proposed PAY.md document into a checked provider listing. It checks the frontmatter and endpoint rules, reports the metered and free endpoint count, and can write the valid document only to a contributor-ready native or proxied provider path. It does not replace the later catalog checks and endpoint probes used before a pull request. rust/…/server.rs• L228-257 rust/…/create_skill.rs• L7-20 rust/…/create_skill.rs• L27-140 rust/…/create_skill.rs• L142-243

References: rust/…/server.rs• L228-257 rust/…/create_skill.rs• L7-20 rust/…/create_skill.rs• L27-140 rust/…/create_skill.rs• L142-243

Payment and content handling

The MCP request path uses the active Pay account to build a credential when a service asks for payment. It may first attach a valid cached sign-in or MPP session authorization, then chooses a supported payment challenge and retries the original request with the proof. Session credentials are partitioned by payer, method, and route. Session-backed calls are serialized so one shared channel is not overused. For x402 batch settlement, the connection can reuse one channel and track the cumulative amount confirmed by the service. A corrective challenge can resynchronize the channel before one retry. rust/…/curl.rs• L19-73 rust/…/curl.rs• L1090-1218 rust/…/curl.rs• L1245-1368

Before payment, the tool validates cached catalog rules against the HTTP method, route, media type, and JSON body when the request is JSON. Non-JSON bodies still receive route and media-type checks. A payment challenge from a different origin than the requested URL is rejected in hosted contexts. Subscription activation is not allowed when MCP payment permissions are enabled. rust/…/curl.rs• L1102-1127 rust/…/curl.rs• L1130-1184 rust/…/curl.rs• L1245-1368

The tool accepts text or JSON request bodies and can send an approved local file as the body. The file must be inside a client-declared local root and must remain unchanged after approval. Images can be shown as image content. Audio, video, PDFs, other binary files, and oversized text can be handed back by a temporary file or resource link. JSON responses can also expose embedded base64 media as separate content. rust/…/curl.rs• L97-145 rust/…/curl.rs• L224-334 rust/…/curl.rs• L351-496 rust/…/curl.rs• L524-730

References: rust/…/curl.rs• L19-73 rust/…/curl.rs• L97-145 rust/…/curl.rs• L224-334 rust/…/curl.rs• L351-496 rust/…/curl.rs• L524-730 rust/…/curl.rs• L1090-1368

Approval boundary

Payment signing remains a user decision. When a local biometric is available, Pay prefers the platform prompt; otherwise, an MCP client that supports elicitation receives the approval request. PAY_FORCE_ELICITATION=1 can route approvals through the MCP client even when a local prompt exists. A decline, cancel, transport error, timeout, or explicit negative answer becomes an authentication denial, so the payment retry does not proceed. Hardware-wallet selection can also use elicitation before signing. rust/…/context.rs• L163-185 rust/…/curl.rs• L972-1087

Local file uploads have a second approval boundary because they share data with an external service. Pay requires the file to be inside a client-declared local root, rejects symlinks and files over 64 MiB, asks the user to approve the file, size, method, and destination, and then reads an unchanged snapshot. Payment approval can follow as a separate step if the destination returns a challenge. rust/…/curl.rs• L305-334 rust/…/curl.rs• L351-496

References: rust/…/context.rs• L163-185 rust/…/curl.rs• L305-334 rust/…/curl.rs• L351-496 rust/…/curl.rs• L972-1087

ACP integration

The ACP integration covers three roles. The launcher puts a payer route in front of an ACP-compatible harness, the middleware observes protocol frames for optional Buzz delivery, and the client library lets a caller drive an ACP agent directly. These roles use the same protocol boundary while serving different owners of the agent process.

Inference route

ACP harnesses do not need to understand Pay payment challenges. The payer route forwards an inference request, handles a 402 challenge, obtains user-approved payment, and retries the buffered request once. For a delegated MPP session, it keeps the authorization for the agent process so later completions can use the same spending session instead of opening a new one for every request. rust/…/payer_proxy.rs• L1-34 rust/…/payer_proxy.rs• L113-142

Provider choice is shared with the other agent launchers. Pay combines local providers, a running local inference gateway, and hosted catalog providers, then filters the set by protocol shape. Claude can use an Anthropic route or an OpenAI-compatible route. Codex and Goose need an OpenAI-compatible route. rust/…/mod.rs• L31-99 rust/…/mod.rs• L137-257

References: rust/…/payer_proxy.rs• L1-34 rust/…/payer_proxy.rs• L113-142 rust/…/mod.rs• L31-99 rust/…/mod.rs• L137-257

Harness contracts

Each harness receives the same Pay route but keeps its own process contract. Goose uses an OpenAI-compatible chat route. Codex receives a Responses-compatible provider entry and model catalog. Claude receives its normal launch shape and can use a message translation boundary when the selected provider speaks OpenAI format. rust/…/acp.rs• L122-180 rust/…/goose.rs• L60-115 rust/…/codex.rs• L93-178

The launcher keeps the selected account in the child process context. Network and account intent therefore reach the same payment checks used by direct Pay requests. A missing model or a provider with no compatible paid route stops the launch before the harness can make an unplanned call. rust/…/acp.rs• L131-207 rust/…/mod.rs• L547-593

References: rust/…/acp.rs• L122-207 rust/…/goose.rs• L60-115 rust/…/codex.rs• L93-178 rust/…/mod.rs• L547-593

ACP client

The ACP client is a direct control boundary for callers that need to drive an agent instead of placing Pay between an existing agent and its editor. It owns the agent's standard-input and standard-output pair, performs initialization, opens sessions, sends prompts, answers permission requests according to an explicit policy, and exposes streamed text, thought, tool-call, completion, and failure events. rust/…/client.rs• L1-7 rust/…/client.rs• L170-241 rust/…/client.rs• L243-309

The client declares no file-system or terminal capability during initialization. It permits one active prompt turn per session and reports timeouts, protocol errors, cancellation, and agent disconnects to the caller. This gives a host a bounded way to relay agent output without taking ownership of vendor-specific ACP messages. rust/…/client.rs• L226-241 rust/…/client.rs• L374-429 rust/…/client.rs• L441-513

References: rust/…/client.rs• L1-7 rust/…/client.rs• L45-96 rust/…/client.rs• L170-309 rust/…/client.rs• L374-429 rust/…/client.rs• L441-513

ACP middleware

The reusable ACP middleware observes protocol frames while forwarding the original bytes unchanged. It tracks prompt turns, collects assistant text, reads the Buzz channel and reply target from the prompt context, and identifies whether the agent completed a buzz messages send tool call. If a turn ends with text and no successful Buzz publish, the CLI can send a fallback message when Buzz credentials are available. Malformed and unknown frames are ignored for tracking and are never rewritten. See ACP payment middleware for the frame and delivery contract. rust/…/lib.rs• L1-13 rust/…/lib.rs• L21-46 rust/…/lib.rs• L113-231 rust/…/lib.rs• L234-330

The CLI enables this middleware only for a Buzz-managed launch with the relay URL and private key present. The child still owns the ACP conversation, and the middleware does not rewrite unknown or vendor-specific messages. A completed explicit Buzz send suppresses fallback delivery, while a failed send leaves fallback delivery available. rust/…/acp_middleware.rs• L10-47 rust/…/acp_middleware.rs• L74-151

References: rust/…/lib.rs• L1-13 rust/…/lib.rs• L21-46 rust/…/lib.rs• L113-231 rust/…/lib.rs• L234-330 rust/…/acp_middleware.rs• L10-47 rust/…/acp_middleware.rs• L74-151

Shared payment route

The MCP server and ACP launcher share the same account and payment foundations but use different request lifecycles. MCP pays for one tool request and returns its result to the host, while an x402 batch channel can carry several MCP requests under one cumulative settlement. ACP places a payer route between a long-running agent process and an inference service, which allows it to preserve streaming responses and session state.

The shared route has five important properties:

  • It checks the selected network and account before signing.
  • It keeps payment challenges tied to the exact resource being called and rejects a hosted challenge from another origin.
  • It applies the caller's outbound destination policy before sending the request. Local MCP can retain local development access, while hosted contexts can restrict calls to public destinations.
  • It advances an x402 batch channel only from a completed response with a valid settlement receipt. A corrective challenge can resynchronize the channel before one retry.
  • It fails closed for hosted inference that succeeds without the payment handshake required by its provider contract. rust/…/mod.rs• L460-519 rust/…/payer_proxy.rs• L203-273 rust/…/context.rs• L26-45 rust/…/curl.rs• L1102-1184 rust/…/curl.rs• L1245-1368

Change checklist

When these files or sections are changed, remember to consider these:

  • MCP tool names or tool descriptions must stay aligned with the host launch allowlists and the shared agent instructions.
  • Payment challenge support in the MCP request path must stay aligned with account selection, approval gates, cached sign-in credentials, MPP session reuse, x402 batch-channel state, and the retry result contract.
  • MCP session keys must continue to separate payer, HTTP methods, and routes. Request locking must match the gateway's channel metering rules.
  • x402 batch settlement must keep its channel cache, cumulative watermark, corrective-challenge recovery, and response-receipt rules aligned with the gateway's settlement contract.
  • MCP request-body validation must stay aligned with catalog OpenAPI rules and with the content type sent on the wire.
  • Catalog search, endpoint lookup, and the HTTP tool must keep exact endpoint URLs, pricing context, outbound policy, and next-step guidance consistent.
  • Per-call context changes must preserve the separation between local account access and hosted tenant identity, including network, account, RPC, approval, file-access, and outbound-destination scope.
  • Spending-policy changes must preserve atomic daily reservations, hard per-call ceilings, recurring-payment refusal, raw-proof approval requirements, and the ordering of policy and client approval.
  • MCP permission configuration changes must preserve strict parsing and keep origin, network, recipient, asset, amount, session-deposit, escrow, and payment-protocol checks aligned with the shared permission model.
  • Account or network context changes must propagate to balance lookup, top-up account selection, inference-selling recipients, and every payment retry.
  • Top-up method and provider changes must keep the QR target, funding address, returned metadata, and rendered image in agreement.
  • Local inference selling must keep local-only execution, explicit publish consent, the earn cap, worker isolation, endpoint state, and remote endpoint deletion aligned.
  • ACP provider dialect or endpoint changes must stay aligned with provider compatibility checks, payer paths, and each harness's model configuration.
  • ACP client capability or permission changes must preserve the no-filesystem and no-terminal initialization contract, one-turn-per-session rule, and terminal event behavior.
  • ACP frame parsing changes must preserve byte-for-byte forwarding, prompt-to-turn tracking, and the rule that a completed explicit Buzz send suppresses fallback delivery.
  • Elicitation changes must keep accepted content, explicit negative answers, declines, cancellations, transport errors, and timeouts fail-closed. The end-to-end client/server round trip must remain aligned with the sync authentication gate.
  • MCP discovery compatibility changes must add only missing metadata and preserve all valid or unrelated JSON-RPC frames.
  • Local file upload changes must preserve the separate file-sharing approval, root check, snapshot check, and payment approval boundaries.
  • Provider output-path rules must stay aligned with the pay-skills repository layout and the frontmatter provider name.
  • MCP response-content changes must preserve native handling for media and bounded handling for large text or base64 payloads.

Important failure modes

TriggerConsequenceGuard
No account or usable stablecoin is availableThe MCP call or ACP payment retry cannot sign a credentialSet up or fund the selected Pay account before the paid action
A hosted call has no usable tenant identity or scopeThe tool cannot safely choose accounts, network, approval, file access, or outbound destinationsResolve a complete CallScope before running the tool
A hosted request targets a destination outside the allowed public policyThe request stops before the service receives itUse a permitted public service or run the request in a local context when local access is required
A hosted challenge names an origin different from the requested URLPay refuses to attach payment to the redirected or unrelated serviceRequest the challenged URL directly or keep the service on the requested origin
The MCP permission file contains an unknown field, empty origin, network, or recipient list, or invalid payment limitThe MCP process refuses to build its payment permissionsUse the strict permission schema and valid network, recipient, asset, and amount values
A payment or payment split does not match an enabled MCP origin, network, recipient, asset, or amount ruleThe payment challenge is rejected before signingAdd an exact permitted rule or use a service that matches the configured scope
A session deposit or batch escrow exceeds the configured limitThe channel cannot open or increase its escrowSet a limit that covers the required deposit or use a smaller channel
The spending policy has a zero limit or the call exceeds a ceiling or daily capThe payment is denied before a signature is releasedSet a suitable per-call ceiling and daily cap for the tenant
A payment has no stated amount, requests recurring authority, or uses a non-valued asset under a hosted policyThe policy refuses it because the ledger cannot safely bound the chargeUse a priced one-time stablecoin payment or an approval path that supports the authority
A raw wallet sign-in reaches a hosted context without an MCP client promptThe sign-in proof is denied before signingConnect a client that supports elicitation and approve the sign-in
A reused MPP session authorization receives another payment challengePay removes the cached authorization and must negotiate a new sessionKeep the request on the same payer, method, and route, then retry after a fresh challenge
A batch-settlement response has no valid receiptThe channel watermark does not advance, so the next request resends the same cumulative voucher as an idempotent retryLet the gateway return its settlement receipt before treating the charge as confirmed
A batch-settlement request receives a corrective challengePay must resynchronize the cached channel before it can retryPreserve the corrective challenge and let the channel cache adopt its server watermark
A cached catalog request has an invalid method, path, media type, or JSON bodyThe request and payment stop before the service sees themUse the endpoint contract returned by the catalog
A catalog endpoint cannot be loaded under hosted outbound policySearch or provider detail returns incomplete endpoint data and does not call the private destinationUse a public catalog endpoint or inspect the service from a local context
An MCP client does not declare a root for a local uploadPay refuses to read the fileAdd the file directory as an MCP root
The file is a symlink, outside a declared root, or larger than 64 MiBPay refuses the uploadUse a regular file inside one of the client's local roots
The file changes after upload approvalPay refuses the request rather than sending unapproved bytesReview the file and retry the same request
The user declines, cancels, or times out on approvalThe payment retry stops and the request is not completedAsk the user to approve a new request when they intend to pay
The MCP client returns an explicit negative approval with an accept actionPay denies the payment rather than trusting conflicting approval dataReturn a consistent positive approval from the client
A hardware wallet is not ready and the client cannot elicit a choiceThe payment cannot select a signer and stops before signingConnect and unlock the selected wallet, or use an available configured account
A top-up on-ramp has no selected provider or an invalid QR scalePay returns no funding QR resultSelect a supported on-ramp and use a scale from 1 through 32
A hosted MCP session calls sell_inferenceThe tool refuses because no local worker can serve buyersRun the local MCP server on the machine that will host the worker
Inference selling has no valid price, consent, or earn capNo endpoint is safely publishedChoose one pricing model and confirm a cap through the user approval flow
A selling worker is not running after endpoint creationBuyers receive 503 and are not charged for unanswered requestsStart or restart pay sell serve, then check endpoint status
The selected ACP provider has no route for the harness dialectProvider selection or launch fails before inference startsSelect a provider and model that match the harness contract
An ACP client receives an unsupported agent requestThe request gets a protocol error instead of filesystem or terminal accessKeep the agent within the declared ACP capability boundary
An ACP agent disconnects or a request times outThe active turn or request ends with a failureTreat the terminal event or error as final and restart the agent when needed
A hosted inference route returns success without its required payment challengeThe payer route rejects the response instead of allowing an ungated callPublish and route the provider through its payment-enabled gateway
Buzz credentials are absent or the Buzz send command failsACP traffic still reaches the client, but no fallback message is publishedConfigure the relay and signing key, or use the agent's explicit Buzz send action
A valid provider document is given an invalid output pathThe document is validated but is not writtenUse the native or proxied providers/…/PAY.md layout

Key files

FileWhy to read it
rust/…/lib.rsMCP server process entry point, stdio transport boundary, discovery compatibility, and optional payment permission attachment
rust/…/context.rsPer-call identity, account and network scope, approval selection, file access, and outbound destination policy
rust/…/permissions.rsStrict MCP payment permission configuration and challenge, recipient, session-deposit, and batch-escrow checks
rust/…/policy.rsHosted spending limits, atomic reservations, raw-proof restrictions, and approval order for tenant calls
rust/…/server.rsAgent-facing tool set, local-versus-hosted tool boundary, catalog routing guidance, and host instructions
rust/…/curl.rsPaid HTTP request lifecycle, cached credentials, session and batch settlement reuse, origin checks, local uploads, request validation, and response handoff
rust/…/search_catalog.rsTask-to-provider ranking, endpoint lookup, price context, and selection guidance
rust/…/get_catalog_entry.rsFull provider detail, exact endpoint URL construction, and next-step guidance
rust/…/get_balance.rsActive-account stablecoin and credit balance lookup
rust/…/topup.rsFunding target selection and QR response generation
rust/…/sell_inference.rsLocal inference selling, consent, pricing, isolation, worker lifecycle, and earn cap
rust/…/auth.rsUser approval boundary for payments, hardware account choice, and local files
rust/…/create_skill.rsProvider document validation and contributor-path handling
rust/…/Cargo.tomlMCP runtime dependencies and the client-enabled elicitation test setup
rust/…/elicitation_e2e.rsEnd-to-end contract for MCP client elicitation and fail-closed authentication
rust/…/client.rsDirect ACP agent control, session prompts, permission policy, streamed turn events, and disconnect handling
rust/…/lib.rsProtocol-neutral ACP frame tracking and Buzz delivery decisions
rust/…/Cargo.tomlACP client and frame-processing library boundary
rust/…/acp.rsACP harness launch and provider/model handoff
rust/…/mod.rsShared provider discovery, compatibility, and payer route selection
rust/…/payer_proxy.rsInference forwarding, payment retry, and session route behavior
rust/…/acp_middleware.rsCLI byte relay and optional Buzz fallback publishing