mppx
TypeScript SDK for the "Payment" HTTP Authentication Scheme. Full 402 flow: challenge → credential → receipt.
What I can accomplish
- Add
402 payment handling to a client with Fetch.polyfill or Fetch.from.
- Protect HTTP routes with server-side MPP Challenges and Receipt responses.
- Accept one-time Tempo stablecoin payments with
tempo.charge.
- Accept metered Tempo stablecoin payments with
tempo.session.
- Accept one-time card payments with
stripe.charge.
- Verify Credentials directly for custom transports or background workflows.
- Wrap MCP clients and servers so tool calls can require payment.
Required inputs
- Client integrations need a signing account and one or more client payment methods.
- Server integrations need a recipient, currency, amount, and
MPP_SECRET_KEY.
- Tempo examples use chain ID
4217 unless a page explicitly covers Moderato testnet.
- Stripe examples need a configured Stripe account and Shared Payment Token flow.
- MCP integrations need the MCP client or server object to wrap.
Constraints
- Keep
MPP_SECRET_KEY server-side and out of logs.
- Never commit private keys or wallet seeds.
- Treat runtime
402 Challenges as authoritative for current payment terms.
- Return
id and opaque unchanged when responding to a Challenge.
- Use
USDC.e for Tempo bridged USDC examples, not generic USDC.
Client
import { Mppx, tempo } from 'mppx/client'
// Polyfills globalThis.fetch to handle 402 automatically
Mppx.create({
methods: [tempo({ account })],
})
const res = await fetch('https://api.example.com/resource')
Without polyfilling:
const mppx = Mppx.create({
methods: [tempo({ account })],
polyfill: false,
})
const res = await mppx.fetch('https://api.example.com/resource')
Server
import { Mppx, tempo } from 'mppx/server'
const mppx = Mppx.create({
methods: [tempo({ currency: '0x...', recipient: '0x...' })],
secretKey: process.env.MPP_SECRET_KEY,
})
async function handler(request: Request): Promise<Response> {
const result = await mppx.charge({ amount: '1.00' })(request)
if (result.status === 402) return result.challenge
return result.withReceipt(Response.json({ data: '...' }))
}
Methods
| Method |
Intent |
Description |
tempo.charge |
charge |
One-time stablecoin payment (TIP-20 token transfer on Tempo) |
tempo.session |
session |
Streaming payments via payment channels on Tempo |
stripe.charge |
charge |
One-time payment via Stripe |
tempo() returns [tempo.charge, tempo.session] as a tuple. Use tempo.charge() or tempo.session() individually if you only need one intent.
Exports
| Path |
Purpose |
mppx |
Core primitives (Challenge, Credential, Method, Receipt, PaymentRequest) |
mppx/client |
Mppx, tempo, stripe, session, Transport |
mppx/server |
Mppx, tempo, stripe, Transport, Store, NodeListener |
mppx/hono |
Hono middleware |
mppx/express |
Express middleware |
mppx/nextjs |
Next.js middleware |
mppx/elysia |
Elysia middleware |
CLI
mppx includes a CLI for making paid requests during development:
npx mppx account create # create wallet
npx mppx mpp.dev/api/ping/paid # make paid request
npx mppx example.com -v # verbose output
References
1---2name: mppx3description: TypeScript SDK for the Payment HTTP Authentication Scheme. Handles 402 Payment Required flows with Tempo, Stripe, and other payment methods. Use when integrating payments or mppx into a client or server application.4---56# mppx78TypeScript SDK for the "Payment" HTTP Authentication Scheme. Full 402 flow: challenge → credential → receipt.910## What I can accomplish1112- Add `402` payment handling to a client with `Fetch.polyfill` or `Fetch.from`.13- Protect HTTP routes with server-side MPP Challenges and Receipt responses.14- Accept one-time Tempo stablecoin payments with `tempo.charge`.15- Accept metered Tempo stablecoin payments with `tempo.session`.16- Accept one-time card payments with `stripe.charge`.17- Verify Credentials directly for custom transports or background workflows.18- Wrap MCP clients and servers so tool calls can require payment.1920## Required inputs2122- Client integrations need a signing account and one or more client payment methods.23- Server integrations need a recipient, currency, amount, and `MPP_SECRET_KEY`.24- Tempo examples use chain ID `4217` unless a page explicitly covers Moderato testnet.25- Stripe examples need a configured Stripe account and Shared Payment Token flow.26- MCP integrations need the MCP client or server object to wrap.2728## Constraints2930- Keep `MPP_SECRET_KEY` server-side and out of logs.31- Never commit private keys or wallet seeds.32- Treat runtime `402` Challenges as authoritative for current payment terms.33- Return `id` and `opaque` unchanged when responding to a Challenge.34- Use `USDC.e` for Tempo bridged USDC examples, not generic USDC.3536## Client3738```ts39import { Mppx, tempo } from 'mppx/client'4041// Polyfills globalThis.fetch to handle 402 automatically42Mppx.create({43 methods: [tempo({ account })],44})4546const res = await fetch('https://api.example.com/resource')47```4849Without polyfilling:5051```ts52const mppx = Mppx.create({53 methods: [tempo({ account })],54 polyfill: false,55})5657const res = await mppx.fetch('https://api.example.com/resource')58```5960## Server6162```ts63import { Mppx, tempo } from 'mppx/server'6465const mppx = Mppx.create({66 methods: [tempo({ currency: '0x...', recipient: '0x...' })],67 secretKey: process.env.MPP_SECRET_KEY,68})6970async function handler(request: Request): Promise<Response> {71 const result = await mppx.charge({ amount: '1.00' })(request)72 if (result.status === 402) return result.challenge73 return result.withReceipt(Response.json({ data: '...' }))74}75```7677## Methods7879| Method | Intent | Description |80|---|---|---|81| `tempo.charge` | `charge` | One-time stablecoin payment (TIP-20 token transfer on Tempo) |82| `tempo.session` | `session` | Streaming payments via payment channels on Tempo |83| `stripe.charge` | `charge` | One-time payment via Stripe |8485`tempo()` returns `[tempo.charge, tempo.session]` as a tuple. Use `tempo.charge()` or `tempo.session()` individually if you only need one intent.8687## Exports8889| Path | Purpose |90|---|---|91| `mppx` | Core primitives (`Challenge`, `Credential`, `Method`, `Receipt`, `PaymentRequest`) |92| `mppx/client` | `Mppx`, `tempo`, `stripe`, `session`, `Transport` |93| `mppx/server` | `Mppx`, `tempo`, `stripe`, `Transport`, `Store`, `NodeListener` |94| `mppx/hono` | Hono middleware |95| `mppx/express` | Express middleware |96| `mppx/nextjs` | Next.js middleware |97| `mppx/elysia` | Elysia middleware |9899## CLI100101`mppx` includes a CLI for making paid requests during development:102103```sh104npx mppx account create # create wallet105npx mppx mpp.dev/api/ping/paid # make paid request106npx mppx example.com -v # verbose output107```108109## References110111- [TypeScript SDK docs](https://mpp.dev/sdk/typescript)112- [Client quickstart](https://mpp.dev/quickstart/client)113- [Server quickstart](https://mpp.dev/quickstart/server)114- [mppx repository](https://github.com/wevm/mppx)115- [IETF Specification](https://paymentauth.org)116- [Tempo docs](https://docs.tempo.xyz)