Agent Commerce Integration Pack
Add safe commerce to an MCP server or agent API: trusted catalogue reads and server-side price resolution with price-tampering and unaudited-product guards. Buyer authorizes payment; no autonomous charging.
File Structure 7 files
Documentation Preview README excerpt
Agent Commerce Integration Pack
Add safe commerce to an MCP server or agent HTTP API: let agents search a
catalogue, understand a product, and prepare a verified checkout link — without
ever being able to tamper with the price or silently charge a customer.
This is the battle-tested pattern behind a live, registry-listed commerce MCP
server, generalized into drop-in TypeScript modules.
The core problem it solves
If you let an agent pass a price (or a Stripe price id, amount, currency, or
product name) into your checkout call, you have a price-tampering hole: an
agent (or a malicious prompt) can buy a $199 product for $0.01. The fix is simple
but must be enforced everywhere: **resolve price server-side from trusted catalogue
data and reject any client-supplied money fields.** This pack encodes that rule.
Features
- CatalogRepository — a shared read layer over a trusted catalogue JSON:
search, filter (domain/tags/max price), resolve by id or slug.
- createCheckoutLink — resolves the trusted price id server-side, creates a
short-lived Stripe Checkout Session with a real expiry, and rejects any
client-supplied price/amount/currency/stripe_price_id/product_name.
- Sellability gate — products flagged
unaudited/deprecated/not-sellable
can never be purchased through the agent path (enforced in code).
- Redirect allowlist — success/cancel URLs must be on an allowlisted host.
- Idempotency — an idempotency key prevents duplicate sessions.
- Guardrail tests — Vitest cases that prove price tampering is rejected and
unaudited products can't be checked out.
Requirements
- Node.js 18+
- A Stripe account + secret key (for the live checkout path)
Quick start
npm install
npm test
import { CatalogRepository } from './src/catalog.js';
import { createCheckoutLink } from './src/checkout.js';
const repo = new CatalogRepository(catalogJson);
const res = await createCheckoutLink(repo, { STRIPE_SECRET_KEY, CHECKOUT_ALLOWED_REDIRECT_HOSTS: 'yourstore.com' }, {
productIdOrSlug: 'store:widget',
// NOTE: no price/amount/currency accepted — resolved server-side.
});
console.log(res.checkout_url, res.expires_at);
File tree
src/
catalog.ts # CatalogRepository: search / filter / resolve (trusted data)
*... continues with setup instructions, usage examples, and more.*