mpp
Rust SDK for the Machine Payments Protocol
MPP (the Machine Payments Protocol) is an open standard for machine-to-machine payments, co-authored by Tempo and Stripe. Paying for a resource over HTTP typically requires API keys, billing accounts, or checkout flows set up ahead of time. MPP lets any client, including an AI agent, an app, or a person, pay as part of the HTTP exchange using the native 402 Payment Required response.
This crate is the Rust SDK for MPP. It supports developers building either side of a paid HTTP exchange: servers that charge for access with Tempo or Stripe, and clients that automatically handle 402 payment challenges. Typical scenarios include gating an API behind per-call payments or building an agent that pays for tools or data as it works. See the quickstart for server and client patterns.
MPP SDKs
MPP has official SDKs in multiple languages:
| Language | Repository |
|---|---|
| Rust | mpp-rs (this repository) |
| Go | tempoxyz/mpp-go |
| Python | tempoxyz/pympp |
| TypeScript | wevm/mppx |
| Ruby | stripe/mpp-rb |
Install
Quick Start
Server (Tempo)
use ;
let mpp = create?;
let challenge = mpp.charge?;
let receipt = mpp.verify_credential.await?;
Server (Stripe)
use ;
let mpp = create_stripe?;
let challenge = mpp.stripe_charge?;
let receipt = mpp.verify_credential.await?;
Client (Tempo)
use ;
use ClientBuilder;
let provider = new?;
let client = new
.with
.build;
// Requests now handle 402 automatically
let resp = client.get.send.await?;
Client (Stripe)
use ;
use CreateTokenResult;
let provider = new;
let resp = new
.get
.send_with_payment
.await?;
WebSocket
use ;
// Server: parse incoming WS message, send challenge/receipt
let msg: WsMessage = from_str?;
if let Credential = msg
// Client: detect challenge, send credential
let msg: WsServerMessage = from_str?;
if let Challenge = msg
WSS (WebSocket Secure) is handled at the connection layer. The transport itself is protocol-agnostic. On the server, terminate TLS via a reverse proxy (nginx, Cloudflare) or use axum-server with rustls. On the client, tokio-tungstenite supports wss:// URLs via its native-tls or rustls features:
= { = "0.26", = ["rustls-tls-webpki-roots"] }
Feature Flags
| Feature | Description |
|---|---|
client |
Client-side payment providers (PaymentProvider trait, Fetch extension) |
server |
Server-side payment verification (ChargeMethod trait) |
tempo |
Tempo blockchain support (includes evm) |
stripe |
Stripe payment support via SPTs |
evm |
Shared EVM utilities (Address, U256, parsing) |
middleware |
reqwest-middleware support with PaymentMiddleware (implies client) |
tower |
Tower middleware for server-side integration |
axum |
Axum extractor support for server-side convenience |
ws |
WebSocket transport for bidirectional session payments |
utils |
Hex/random utilities for development and testing |
Payment Methods
MPP supports multiple payment methods through one protocol: Tempo, Stripe, Lightning, Card, and custom methods. The server advertises which methods it accepts, and the client chooses which one to pay with. This SDK implements Tempo (charge and session intents) and Stripe (charge intent via Shared Payment Tokens).
Protocol
Built on the "Payment" HTTP Authentication Scheme. The source specifications are maintained in tempoxyz/mpp-specs. See mpp.dev/protocol for the protocol overview or paymentauth.org for the wire format.
Contributing
git clone https://github.com/tempoxyz/mpp-rs
cd mpp-rs
cargo test
Security
See SECURITY.md for reporting vulnerabilities.
License
Licensed under either of Apache License, Version 2.0 or MIT License at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in these crates by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.