Skip to main content

AI shopping agents

A buyer can ask an AI agent to shop for them. With the MCP endpoint in the Checkout SDK, that agent can find your products, build a cart and prepare a checkout in your store, then give the buyer a link to COPE’s checkout page. The buyer accepts your terms and pays there themselves. An agent cannot accept terms or pay on the buyer’s behalf. The endpoint runs on your server, under your domain, with your publishable key. It speaks the Model Context Protocol (MCP), which AI agents use to call tools.

Requirements

  • A COPE publishable key (cope_pk_live_...).
  • The success and cancel URLs you use for checkout, registered as redirect URLs in the COPE dashboard.
  • A server that runs Node.js 20 or later, Bun, Deno, Cloudflare Workers or a Next.js route handler.

Install

Create a cart key

The endpoint gives agents an encrypted handle for each cart, so an agent never holds the cart’s secret. Create a 32-byte key for that once, and store it as a server-side secret:
Keep this key out of browsers and source control. Anyone holding it can open and change the carts its handles point to.

Mount the endpoint

On Node.js:
On Bun, Deno, Cloudflare Workers or a Next.js route handler, use the fetch handler instead. It does not need @modelcontextprotocol/node:
Agents then connect to https://shop.example.com/mcp.

Options

Tools

When a tool fails, its result includes a guidance string telling the agent what to do next.

Rotate the cart key

  1. Add a new key at the front of cartRefKeys and deploy. New handles use it, and existing handles still work.
  2. After your longest-lived carts have expired, remove the old key and deploy again.

Security

  • The endpoint uses only your publishable key, the same key your storefront already exposes.
  • Terms, consents and payment happen on COPE’s checkout page, in the buyer’s own browser.