Skip to content
Skills Library
Programming · Building & coding

mpp-client-fetch

/mpp-client-fetch

Implement MPP client-side payment handling with mppx.fetch(). Use when building AI agents or automated clients that consume 402-protected APIs, handling the transparent challenge-response payment flow.

Licence
MIT
Last repository change
14.09.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
4
Deprecation

No signals detected. Repository changed on 14.09.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Implement MPP client-side payment handling with mppx.fetch(). Use when building AI agents or automated clients that consume 402-protected APIs, handling the transparent challenge-response payment flow.

Original author description

Implement MPP client-side payment handling with mppx.fetch(). Use when building AI agents or automated clients that consume 402-protected APIs, handling the transparent challenge-response payment flow.

How it works

  1. Before writing code
  2. Conceptual Architecture
Original SKILL.md headings · 116 lines, 557 words
SKILL.md preview
---
name: mpp-client-fetch
description: Implement MPP client-side payment handling with mppx.fetch(). Use when building AI agents or automated clients that consume 402-protected APIs, handling the transparent challenge-response payment flow.
allowed-tools: Read, Write, Edit, Bash, Grep, Glob, WebSearch, WebFetch
---

# MPP Client — mppx.fetch()

## Before writing code

**Fetch live docs**:
1. Fetch `https://www.npmjs.com/package/mppx` for the current client API and wallet configuration
2. Web-search `mppx client fetch payment wallet configuration` for client-side setup patterns
3. Web-search `site:github.com stripe-samples machine-payments client` for official client sample code
4. Fetch `https://mpp.dev/overview` for the client-side protocol flow description

## Conceptual Architecture

### What mppx.fetch() Does

`mppx.fetch()` is a drop-in replacement for the standard `fetch()` API that transparently handles the full HTTP 402 payment flow:

1. **Request** — Client sends a normal HTTP request
2. **402 Detection** — If server responds with 402, the client parses the `WWW-Authenticate: Payment` challenge
3. **Payment Fulfillment** — Client automatically pays using the configured wallet/payment method
4. **Credential Submission** — Client retries the request with `Authorization: Payment` credential
5. **Receipt Capture** — Client captures the `Payment-Receipt` header from the response
6. **Transparent Return** — Returns the final 200 response as if the payment never happened

The developer's code sees only the final successful response — all payment negotiation is handled internally.

### Client Configuration

```typescript
import { mppx } from 'mppx/client';

// Configure once
const client = mppx.create({
  wallet: {
    privateKey: process.env.WALLET_PRIVATE_KEY,  // For Tempo/crypto payments
  },
  // OR for Stripe SPT payments:
  stripe: {
    sharedPaymentToken: sptToken,  // Obtained from SPT provisioning
  },
});

// Use like fetch()
const response = await client.fetch('https://api.example.com/paid-resource');
const data = await response.json();
```

### Payment Method Selection

When a server supports multiple payment methods, the client selects based on:
- Configured wallet capabilities
- Method preference order
- Available balance (for crypto methods)
- SPT availability (for Stripe methods)

### Spending Controls

Clients should implement spending controls:
- **Per-request limit** — Maximum amount for a single payment
- **Session budget** — Maximum total spend per session
- **Daily/hourly caps** — Rate-based spending limits
- **Allowlisted domains** — Only pay specific services

### Receipt Handling

After a successful payment, the `Payment-Receipt` header contains:
- Payment status
- Method used
- Timestamp
- Reference identifier

Clients should log receipts for accounting and dispute resolution.

### Error Handling

| Scenario | Behavior |
|----------|----------|
| Insufficient balance | Throw error with details |
| Unsupported payment method | Throw error listing supported methods |
| Challenge expired | Retry with fresh request |
| Network error during payment | Do not retry payment (risk of double-pay) |
| Server returns non-402 error | Pass through as normal fetch error |

### CLI Usage

The `mppx` CLI provides a quick way to test payments:

```bash
npx mppx https://api.example.com/paid-resource
```

### Multi-Method Client

A client can be configured with multiple payment methods:

```typescript
const client = mppx.create({
  methods: [
    { type: 'tempo', wallet: { privateKey: process.env.WALLET_KEY } },
    { type: 'stripe', spt: { token: sptToken } },
  ],
  preference: ['tempo', 'stripe'],  // Try Tempo first, fall back to Stripe
});
```

### Best Practices

- Never hardcode wallet private keys or SPTs — use environment variables
- Implement spending limits to prevent runaway costs
- Log all payments with amounts and service URLs for auditing
- Handle payment failures gracefully — distinguish between "can't pay" and "won't pay"
- Cache successful payment sessions where the protocol supports it
- Implement circuit breakers for services that consistently fail

Fetch the latest mppx client documentation for exact configuration options, wallet setup, and error types before implementing.

Versions

The database has no other skills named mpp-client-fetch.

Database snapshot: 13.11.2026 · package version 10774fdb2cb1 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 3 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100mpp
    Build with MPP (Machine Payments Protocol), open machine-to-machine payments over HTTP 402. Use for paid APIs, payment-gated endpoints, agent payment flows, MCP tool payments, or metered billing. Covers mppx (TS), pympp, and mpp Rust SDKs.
  • 100mpp-setup
    Scaffold an MPP project — install mppx SDK, configure payment methods, set up server middleware, and create a basic paid API endpoint. Use when starting a new MPP machine payments project from scratch.
  • 100mpp-server-middleware
    Implement MPP server-side middleware for Hono, Express, Next.js, and Elysia. Use when protecting API routes with HTTP 402 payment gates, configuring payment methods, or setting up the Mppx server instance.
  • 100mppx
    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.
  • 95lightning-amp-mpp
    Multi-Path Payments (MPP) — split a payment across multiple parallel routes; same payment hash, payment_secret binds parts. AMP (Atomic Multipath) — variant where each part has different hash; receiver derives shared secret. USE WHEN: implementing payment splitting, debugging…
  • 95pay-with-any-token
    Pay HTTP 402 payment challenges using tokens via the Tempo CLI and Uniswap Trading API. Use when the user encounters a 402 Payment Required response, needs to fulfill a machine payment, mentions "MPP", "Tempo payment", "pay for API access", "HTTP 402", "x402", "machine payment…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.