# MPP

Use MPP (Machine Payments Protocol) to accept payments from agents.

[MPP, the Machine Payments Protocol](https://mpp.dev), is an open protocol that lets agents pay for your APIs and services programmatically without a checkout UI, co-authored by Stripe and Tempo.

When an agent requests your API or service, your server returns an HTTP `402` response with payment details. The agent authorizes the payment, retries the request, and gets access to the paid resource along with a receipt.

A diagram showing the MPP payment flow between agent, server, and Stripe (See full diagram at https://docs.stripe.com/payments/machine/mpp)

```text
[Agent] -- Request paid resource without payment --> [Server]
[Server] -- HTTP 402 with payment requirements --> [Agent]
[Agent] -- Retry request with payment credential --> [Server]
[Server] -- POST /v1/payment_intents to record payment --> [Stripe]
[Server] -- Return requested resource --> [Agent]
```

## Before you begin

1. [Create a Stripe profile](https://docs.stripe.com/get-started/account/profile.md) in the Stripe Dashboard.
2. Store your profile’s `profile_` ID. You use this value as the `networkId` to [create your endpoint](https://docs.stripe.com/payments/machine/mpp.md#create-your-endpoint).

## Use a coding agent

You can build an API that uses MPP with a single prompt to your coding agent:

```bash
Read https://docs.stripe.com/payments/machine/mpp.md?lang=node, and monetize my API using MPP to charge 0.50 USD per API call.

Run `npx mppx@latest validate http://localhost:4242` to iteratively validate the implementation as you develop.
```

To build the integration yourself, follow the steps in this guide to install the dependencies, create an endpoint that returns an HTTP `402` challenge and verifies payments, add payment methods such as cards or stablecoins, and test the full flow.

Use this approach if you want more control over your server implementation or want to understand each part of the integration.

You can also review the app’s [complete source code](https://github.com/stripe-samples/machine-payments) on GitHub.

## Install dependencies

Install the required dependencies:

```bash
npm install mppx stripe
```

## Create your endpoint

Create an endpoint that checks for a 0.50 USD payment on each request and returns an HTTP `402` challenge if no payment is present. If it verifies a payment, it returns a receipt.

#### Node.js

```node
import crypto from 'crypto';
import StripeClient from 'stripe';
import { Mppx, stripe } from 'mppx/server';

// Secret used to secure payment challenges
// https://mpp.dev/protocol/challenges#challenge-binding
const mppSecretKey = crypto.createHmac("sha256", process.env.STRIPE_SECRET_KEY!).update("mpp-challenge-signing").digest("base64");

const stripeClient = new StripeClient(process.env.STRIPE_SECRET_KEY!);

const stripeMachinePayments = stripe.create({
  client: stripeClient,
  networkId: process.env.STRIPE_PROFILE_ID!,
  livemode: !process.env.STRIPE_SECRET_KEY!.includes('_test_')
});

const mppx = Mppx.create({
  methods: stripeMachinePayments.defaultMethods(),
  secretKey: mppSecretKey,
});

export async function handler(request: Request) {
  const response = await mppx.charge({ amount: '0.50' })(request);

  if (response.status === 402) return response.challenge;

  return response.withReceipt(Response.json({ data: '...' }));
}
```

## Start accepting payments

Use MPP to accept payments from agents with a variety of payment methods, including cards through [Shared Payment Tokens (SPTs)](https://docs.stripe.com/agentic-commerce/concepts/shared-payment-tokens.md) and [stablecoin payments](https://docs.stripe.com/payments/stablecoin-payments.md).

See [availability requirements for SPTs and stablecoin payments](https://docs.stripe.com/payments/machine.md#availability) to learn more.

By default, the endpoint you create supports SPTs. Make sure that you also add support for stablecoin payments to support agents with crypto wallets and charge for payments as low as 0.01 USDC.

##### Create a deposit address

Agents with stablecoins send payments to this onchain address on supported blockchains, such as Tempo. Stripe automatically offramps these payments and settles them into your Stripe balance.

```bash
curl https://api.stripe.com/v1/crypto/deposit_addresses \
  -u "$STRIPE_SECRET_KEY:" \
  -H "Stripe-Version: 2026-05-27.preview" \
  -d network=tempo
```

Create a deposit address and store the returned address as `TEMPO_DEPOSIT_ADDRESS` in your server’s environment variables.

You can create deposit addresses as often as you want, but we recommend that you keep these calls off your core request path.

##### Update your endpoint

Add the deposit address to your `stripeMachinePayments` configuration:

#### Node.js

```node
const stripeMachinePayments = stripe.create({
  client: stripeClient,
  networkId: process.env.STRIPE_PROFILE_ID!,
  livemode: !process.env.STRIPE_SECRET_KEY!.includes('_test_'),
  depositAddresses: {
    tempo: process.env.TEMPO_DEPOSIT_ADDRESS!
  },
});
```

The existing code works without other changes. `defaultMethods()` adds Tempo, and the existing `mppx.charge()` handler offers both SPT and Tempo payments at the same 0.50 USD amount. You can charge different amounts by payment method by using `mppx.compose()`.

## Test your endpoint

### Test with mppx validate

Run `mppx validate` to automatically verify your implementation end-to-end. The command tests discovery, challenge formats, error handling, and the full payment flow.

```bash
npx mppx@latest validate http://localhost:4242
```

We recommend running `validate` against both a sandbox and live mode version of your server. In a sandbox, the CLI automatically completes roundtrip test transactions against your server. In live mode, the CLI can also complete roundtrip transactions with real funds.

### Test manually

You can also test each step individually. First, verify your server returns a `402` with the payment requirements:

#### SPT

> Stripe requires a minimum 0.50 USD charge (or the equivalent amount) for card payments made with SPT.

Use the [link-cli](https://link.com/agents) to issue a test SPT for your account. The `link-cli` is a tool that can provision one-time shared payment token credentials using your Link account. Follow the instructions at [link.com/agents](https://link.com/agents) to install the `link-cli` skills or register it as an MCP server in your preferred agent.

To test with the `link-cli` manually, directly invoke its commands:

```bash
npx @stripe/link-cli auth login
```

```bash
npx @stripe/link-cli mpp pay http://localhost:4242/paid \
  -X POST \
  -d '{}' \
  --context "Testing machine payments integration on Stripe MPP using the link-cli on http://localhost:4242/paid"
```

In the [Dashboard](https://dashboard.stripe.com), go to **Payments** to see the transaction.

#### Crypto

Use the [Tempo CLI](https://tempo.xyz/developers/docs/cli) to send a payment from the command line. If your server uses a live mode deposit address, this command moves real funds.

```bash
curl -fsSL https://tempo.xyz/install | bash
tempo wallet login
tempo wallet fund
tempo request -X POST --json '{}' http://localhost:4242/paid
```

After a successful payment, the server returns the content. In the [Dashboard](https://dashboard.stripe.com), go to **Payments** to see the transaction.

### Test with a Stripe sandbox

To test in a sandbox:

1. Configure your server to use your sandbox Stripe API key.
2. Create a Stripe profile for your sandbox and use the `profile_test_` ID.
3. Create a Tempo deposit address in your sandbox account:

```bash
curl https://api.stripe.com/v1/crypto/deposit_addresses \
  -u "$STRIPE_SECRET_KEY:" \
  -H "Stripe-Version: 2026-05-27.preview" \
  -d network=tempo
```

Store the returned address as your `TEMPO_DEPOSIT_ADDRESS` environment variable. The configuration above detects your sandbox API key and sets `livemode` to `false`. mppx’s `stripe.create` automatically configures Tempo testnet.
