The architecture of this reference implementation, from the blueprint's unmodified runtime down to the processor adapters, with the ports, the environment variables and the tests an engineer needs to run it.
The layers
Anthropic's Claude Commerce Agents blueprint is vendored by setup.sh into vendor/commerce-agents at a pinned commit and never edited. Everything this reference adds sits beside it and is imported into the blueprint's own host code. The diagram reads top to bottom, from the shopper's browser to the processor.
Inner ring: touches a model. Outer ring: model-free. Everything that makes the product safe sits on the outer ring: the provenance rule, the cart gates, the fences, the presentation contract, the skills. The full inventory with every module's purpose and line count is in the project's docs/MODULES.md; the script that produced it is in the reference.
red · talks to Claude directly (9)violet · uses a Claude-only trick (9)green · works with any AI, or none (35)
shopper's browser staff's browser
web/storefront (Next.js) web/portal (Next.js)
chat, cart panel, "Pay securely" button, payments panel, staged changes
status poll after the button is pressed
| |
v v
merchant API (FastAPI, one process per merchant; verticals/<merchant>/api/main.py)
/api/brand /api/chat /api/cart/* /api/merchant/* /checkout/* /store/checkout/* /pay/*
/.well-known/ucp /api/ucp/mcp /api/mcp /acp/* /webhooks/*
|
v
the blueprint (vendor/commerce-agents, unmodified)
ShoppingAgent and MerchantAgent turn loops, executor, gates, fences
skills registry and load_skill, presentation tools, memory
StorefrontBackend (11 required + 3 optional) MerchantBackend (16 required + 3 optional)
| |
v v
this reference
psp_commerce/integration/ one mixin per checkout model -> checkout_handoff
commerce_core/tender.py present_tender_options (the tender card)
commerce_core/merchant.py PaymentsOpsMixin (metrics, disputes, SQL tables)
psp_commerce/thirdparty/ UCP discovery, the MCP endpoint, ACP, the feed
psp_commerce/webhooks.py Stripe and Adyen signature verification
|
v
psp_commerce/gateway.py PaymentGateway protocol
verticals/registry.py gateway_for(): the real adapter when its variables are set,
the simulated gateway otherwise (GATEWAY_MODE=simulated forces it)
|
v
psp_commerce/adapters/ stripe.py adyen.py worldpay.py cybersource.py clover.py mock.py
|
v
the processor's test environment (live), or local pages served by the API (simulated)
The blueprint's runtime
The blueprint runs one model in a loop with a fixed tool list. Each round, the model writes text and asks for tool calls; an executor (ShoppingToolExecutor for the shopping side) runs each call against the merchant's backend, applies the gates, fences the results and returns them; the round that carries the follow-up chips ends the turn. The static system prompt and the tool list are built once per deployment, so the expensive part of every request is identical bytes.
The gates are code, and they hold regardless of what the model does. A cart write must name a product id that a catalog or order tool returned in this conversation; tests/test_checkout_handoff_turn.py::test_cart_write_needs_provenance shows an invented id refused before the backend sees it. Quantities and line counts are capped. Every tool result is fenced (normalized, stripped of invisible characters, labeled as data). Identity is bound at session start and no tool argument names a user.
A merchant connects by implementing two backends. StorefrontBackend (vendor/commerce-agents/shopping-agent/core/shopping_agent/backend.py) has eleven required functions: search_products, get_product_details, get_cart, add_to_cart, update_cart_item, remove_from_cart, get_preferences, get_orders, get_order, search_policies and get_fulfillment_options; and three optional ones: checkout_handoff, get_account_context and get_disclosure. MerchantBackend (vendor/commerce-agents/merchant-agent/core/merchant_agent/backend.py) has sixteen required functions: get_business_snapshot, query_metrics, get_campaign_performance, search_listings, get_listing, get_inventory_alerts, get_order_issues, get_pricing_context, stage_listing_update, stage_price_update, stage_inventory_action, stage_promotion, stage_campaign, get_pending_changes, apply_change and discard_change; and three optional ones: execute_analysis_query, get_analysis_schema and get_merchant_context. Every write on the merchant side is staged, and apply_change runs only after a person approves in the host's own tool.
Skills and load_skill
A skill is one SKILL.md file with a name, a one-line description and a page of rules. The system prompt carries only the index (name and description); when a request matches, the model calls the blueprint's load_skill tool and the body enters its context for the rest of the flow. The blueprint ships five shopping skills (search-discovery, purchase-research, planning-goals, customer-care, memory-personalization) and five merchant skills (performance-insights, inventory-operations, catalog-listings, pricing-promotions, marketing-campaigns). This reference adds tender-and-loyalty and payments-operations in psp_commerce/skills/. Both runtimes take a single skills directory, so psp_commerce/skills_dir.py assembles the blueprint's five and the reference's one per role into .skills/<role>/ (ignored by git, rebuilt when a source is newer).
The request lights one line of the index. The assistant loads that page and makes its first data read in the same round.
Presentation tools
A card is a tool call. The model chooses which card and which items; a server-side hook fills in the values. The shopping side registers present_products, present_comparison, present_plan, present_guide, present_order_status, checkout, present_suggestions and, when enabled, present_disclosure; the merchant side registers present_metrics, present_digest, present_change_preview and present_suggestions. search_products, load_skill, present_plan and present_suggestions are the blueprint's tools; no processor supplies them.
This reference adds one card through the blueprint's PresentationExtension hook: present_tender_options in commerce_core/tender.py. The model's payload carries at most a 200-character note. The enrich hook reads the cart and the customer's loyalty tier, calls the backend's psp_tender_options, and the gateway computes every reward, split, balance and points figure for that subtotal. An empty cart, or a backend with no gateway, gets a refusal instead of a card with no figures (tests/test_tender_extension.py).
checkout_handoff and the URL the model never sees
The blueprint's checkout tool renders the cart. When a backend implements checkout_handoff, the executor calls it after the model's tool call and attaches the returned CheckoutHandoff(url, label) to the card's handoffs list. The URL therefore appears in the UI event the browser renders and in no request body sent to the model. tests/test_checkout_handoff_turn.py::test_checkout_url_reaches_ui_but_never_the_model scripts a search, add and checkout turn and asserts exactly that, on the system text, the tools and the whole transcript, and on the stored transcript the host keeps for the next turn. tests/test_runtime_agnostic.py asserts the same on the model-agnostic loop.
The three run paths, and another model
The demo merchants run the blueprint's Messages API runtime (ShoppingAgent from shopping_agent_runtime, MerchantAgent from merchant_agent_runtime). scripts/console.py runs the same backend, skills and tender card on the Claude Agent SDK path. commerce_core/mcp_server.py mounts the blueprint's storefront tools through its executor beside the platform tools, the shape a hosted deployment uses.
psp_commerce/runtime/ is a rewrite of the shopping turn loop against a ModelProvider contract (provider.py: one complete() call per round, the Messages API block format as the canonical shape). providers.py implements Anthropic, an OpenAI-compatible endpoint (OpenAI, Azure, Ollama, vLLM through base_url), Gemini, and a scripted provider for tests. Everything below the model (prompt builders, tool contracts, executor, gates, skills) is the blueprint's code imported unchanged. Claude was run live; the OpenAI and Gemini providers are unit-tested against the documented wire shapes and were not run live in this repository.
The processor layer
The PaymentGateway protocol
psp_commerce/gateway.py defines PaymentGateway, a structural protocol: any class with these methods satisfies it, and nothing subclasses anything.
Group
Methods
Record returned
registry
now, merchant
MerchantAccount with its Tender list and LoyaltyProgram
Every method runs server-side in the host. None is a tool the model can call.
Adapters
psp_commerce/adapters/_base.py holds what every real adapter is built from: ProcessorClient, a small synchronous httpx client with a per-request header hook for the processor's signature scheme; Ledger, the adapter's own record of what it created and what the processor reported back; and BaseAdapter, the shared implementation of the reporting methods over psp_commerce/reporting.py. Each adapter file says in its docstring which endpoint each method maps to and what the live runs found:
One contract, six bodies. The processor-specific part of an adapter is its authentication scheme and its request bodies; everything above them (the tender card, the merchant agent's numbers, the checkout pages, the third-party endpoints) is shared.
https://apisandbox.dev.clover.com (platform REST), https://scl-sandbox.dev.clover.com (Ecommerce), https://token-sandbox.dev.clover.com (tokenization); bearer tokens; CLOVER_ENV=production for the live hosts
CLOVER_MERCHANT_ID, CLOVER_ACCESS_TOKEN
tests/test_adapters_http.py runs every adapter against a mock transport that asserts the path, the authentication header and the body, and answers with the documented response shape.
The simulated gateway
psp_commerce/adapters/mock.py defines MockGateway, an in-memory implementation of the whole protocol on top of commerce_core/gateway.py's SimulatedGateway: hosted sessions that expire after fifteen minutes, payment intents, client sessions, payment links, and a deterministic history of transactions, settlements and disputes seeded from the merchant id so demos and tests are stable. Its pages are served by the merchant API itself. It carries a simulated_processor label, and its authorize_delegated accepts only the credential providers the real adapter for that processor declares, so a simulated Adyen merchant refuses a Stripe shared payment token the same way the live adapter would.
Choosing the gateway
verticals/registry.py holds the five merchant accounts (MID-100-NORTHSTAR, MID-700-LUMEN, MID-800-AURORA, MID-900-BEACON, MID-950-ENCORE) with their tenders and loyalty programs. gateway_for(merchant_id, base_url) returns the merchant's adapter when that adapter's available() reports its variables are set and GATEWAY_MODE is anything other than simulated; a MissingCredentials error or an absent variable falls back to MockGateway. gateway_mode() names the result, and verticals/_host.py puts it on GET /api/brand as gateway_mode: simulated|live with a one-line gateway_note.
The four checkout integration models
CHECKOUT_MODEL selects the model at boot (hosted by default; server, dropin or link). psp_commerce/gateway.py::checkout_model_from_env reads it, psp_commerce/integration/__init__.py::mixin_for returns the mixin, and each merchant's build_backend composes a class with the mixin ahead of the store (type(f"LumenHome{model}", (mixin, LumenHomeStore), {}) in verticals/lumen_home/api/backend.py). Every mixin implements checkout_handoff and open_checkout; the latter feeds the cart panel through verticals/_host.py::cart_extras_for, which adds checkout_url, checkout_label, checkout_expires_at, checkout_status_url and, for drop-in, the dropin block to every cart payload.
The processor renders, collects and authorizes. The store holds no card data. This is the model the first cut of this reference assumed, and the one Clover, Adyen, Stripe and Worldpay each create with a single call.
The store renders and collects; the processor authorizes. The processor is invisible in the link and sees one authorization request. The store carries the page and, unless it uses the processor's tokenizer, the deeper PCI scope.
The store's page, the processor's component. The component collects and completes inside the processor's frame; the webhook is the signal the store trusts. Adyen's Drop-in, Stripe's embedded Checkout, CyberSource's Unified Checkout, the processor's Checkout.js, Clover's iframe and Worldpay's Checkout SDK all fit here.
The hosted model with a URL that travels. Stripe Payment Links, Adyen Pay by Link, CyberSource Pay by Link, Clover Hosted Checkout links, the processor Checkout Pages links and Worldpay Hosted Payment Pages all fit. The same link is what an agent hands a shopper when it uses the processor's own tools, which is why this model reappears in the third-party section.
Model
Mixin
What the card's button opens
Who authorizes
Demo page and completion (psp_commerce/checkout_pages.py)
hosted
HostedCheckoutMixin
the processor's page from create_checkout_session
the processor, on its page
/checkout/{cko_…}, POST /checkout/{id}/complete, GET /checkout/{id}/status
server
ServerSideCheckoutMixin
the merchant's own route /store/checkout/{pi_…}; a payment intent is created when the card is staged, and staging the same lines again reuses it
the merchant's server, through authorize_payment
POST /store/checkout/{id}/pay, GET /store/checkout/{id}/status
dropin
DropInCheckoutMixin
/store/checkout/{cs_…} with the processor's component mounted from client_key and payment_methods
the processor, from its component; the webhook confirms
POST /psp/dropin/{id}/complete, GET /psp/dropin/{id}/status
link
LinkCheckoutMixin
a processor-hosted link from create_payment_link
the processor, on the link's page
/pay/{plink_…}, POST /pay/{id}/complete, GET /pay/{id}/status
In every model the tender card's rows come from gateway.tender_options and are identical; tests/test_integration_models.py::test_tender_card_is_identical_across_models asserts it. The demo completion routes stand in for what a real processor reports by webhook; on a live adapter the merchant-owned pages still render, and the payment itself happens with the processor.
The return leg after a live payment
On the simulated gateway the hosted page is local and the storefront polls <checkout_url>/status. On a live processor the checkout URL is the processor's page on another origin, so three things change, all in commerce_core/hosted_checkout.py and verticals/_host.py.
First, the processor's return address is the merchant API's GET /checkout/return. The Stripe adapter sets success_url to /checkout/return?session_id={CHECKOUT_SESSION_ID}; the Adyen adapter sets returnUrl to /checkout/return, and Adyen appends sessionId and sessionResult. The route reads the session through gateway.get_checkout_session, which on Stripe calls GET /checkout/sessions/{id} and records the order when payment_status is paid, and on Adyen hands sessionResult to record_session_result and then calls GET /sessions/{id}?sessionResult=. The page tells the shopper whether the payment was received and links back to STORE_URL.
Second, the storefront polls checkout_status_url on the merchant API (/checkout/{id}/status for the hosted model, /pay/{id}/status for a link; status_url_for in verticals/_host.py) every 2.5 seconds after the button was pressed (web/storefront/components/CartPanel.tsx), so the store notices the payment without a reload.
Third, the note the assistant reads. install_hosted_checkout queues one note per completed session, whichever route first observes the payment (the return page, the status poll, or the demo completion route), through on_completed, which verticals/_host.py implements by appending to pending_app_events on each of the customer's live sessions. The blueprint delivers those events to the model on its next turn. tests/test_demo_paths.py::test_return_leg_notifies_the_assistant_once covers the return route with Stripe's and Adyen's parameter names and the once-only rule. A verified webhook (psp_commerce/webhooks.py) queues the same note.
The third-party layer
Every merchant serves the Universal Commerce Protocol (UCP) over the Model Context Protocol (MCP) and the Agentic Commerce Protocol (ACP) from the same StorefrontBackend and gateway its own assistant uses (psp_commerce/thirdparty/, installed by verticals/_host.py).
Adapters first, then the server and the endpoints, then verification. Each step reuses the one before it.
GET /.well-known/ucp is the discovery document: the UCP version, the shopping service's endpoint and the payment handlers the merchant accepts (com.google.pay in gateway mode naming the processor; com.stripe.payments on the Stripe merchant).
POST /api/ucp/mcp is the shopping service as JSON-RPC over HTTP in the MCP shape: initialize, ping, tools/list, tools/call and notifications. The tools are search_catalog, get_product, lookup_catalog, create_cart, get_cart, update_cart, create_checkout, update_checkout, get_checkout, cancel_checkout, complete_checkout and get_order; POST /api/mcp serves search_shop_policies_and_faqs. create_checkout stages the cart with the processor and answers with the page as continue_url; complete_checkout with a credential calls authorize_delegated.
POST /acp/checkout_sessions and its update, get, complete and cancel routes are the ACP session API; GET /acp/feed.json is the product feed.
commerce_core/mcp_server.py is a separate platform MCP server over several merchants (list_merchants, search_catalog, get_product, check_availability, create_checkout_session, get_checkout_status, get_order_status) that binds to loopback only.
scripts/platform_agent.py is the client side: scripted, or driven by Claude, an OpenAI model or Gemini through the provider contract, against these merchants or a Shopify store. Platform agents over UCP and ACP covers the whole layer, the eight ways a platform can pay, and Claude Code as a client.
The web apps and the vendored vertical apps
web/storefront and web/portal are Next.js forks of the blueprint's retail web apps. One build serves any merchant: the app reads NEXT_PUBLIC_API_URL, calls /api/brand for the store's name, mark, colors, processor, checkout model and gateway mode, and themes itself. The storefront adds the tender card (components/generative/TenderOptions.tsx) and the checkout button with its status poll (components/CartPanel.tsx); the portal adds the payments panel (components/views/PaymentsPanel.tsx). They serve Northstar Outfitters and Lumen Home.
Aurora Escapes, Beacon Wireless and Encore Seats use the blueprint's own travel, telecom and entertainment apps from vendor/commerce-agents/examples/<vertical>/storefront-web and merchant-web, pointed at this reference's API. Shopify's example runs from vendor/claude-for-commerce-examples/storefront (its own API and web app) against a real store named by SHOP_DOMAIN. Every company, brand, product and person in the five demo merchants is fictional.
scripts/run_demo.py <northstar|lumen|aurora|beacon|encore> [--all|--merchant|--api-only] starts a merchant's API and web apps, sets MERCHANT_BASE_URL and STORE_URL, and gives each web port its own Next.js build directory. The platform run scripts call it.
Ports
Merchant
Processor
API
Storefront
Portal
Shopify's example (fakestore-ai.myshopify.com)
Shopify
8004
3005
not started by the reference
Northstar Outfitters
Clover
8010
3010
3110
Lumen Home
Stripe
8016
3016
3116
Aurora Escapes
Adyen
8017
3017
3117
Beacon Wireless
Worldpay
8018
3018
3118
Encore Seats
CyberSource
8019
3019
3119
.mcp.json at the root registers lumen-home (http://localhost:8016/api/ucp/mcp) and aurora-escapes (http://localhost:8017/api/ucp/mcp) as MCP servers for Claude Code.
The tests
Sixty-nine tests run with no credentials in about ten seconds; every model call is scripted.
source .venv/bin/activate
python -m pytest -q
File
What it proves
tests/test_checkout_handoff_turn.py
the checkout URL reaches the UI event and no request to the model; an invented product id is refused
tests/test_integration_models.py
the hosted, server and drop-in models on one merchant: what the card links to, which page opens, who authorizes, and identical tender rows
tests/test_adapters_http.py
every adapter's requests and the documented responses through a mock transport; the CyberSource signature; the Stripe and Adyen webhook verifiers
tests/test_thirdparty.py
Shopify's own UcpClient and ShopifyStorefrontBackend, vendored unchanged, shop at the Stripe merchant; ACP completes with a delegated token; a credential the processor cannot charge is refused; the payment-link model
tests/test_demo_paths.py
the return leg notifies once; the cart payload names a local status URL; the MCP handshake; the platform agent script, scripted and on a scripted provider
tests/test_runtime_agnostic.py
the model-agnostic loop never sees the URL; grounding by prefetch; the OpenAI and Gemini conversions
tests/test_verticals_boot.py
every merchant boots simulated and reports its own store
the simulated gateway, the tender card, the payments view, the Clover catalog mapping, the platform MCP server
Each platform folder's test.sh runs the subset for that merchant, boots the API, checks discovery and the MCP handshake, has a scripted platform agent stage a checkout, and, when the processor's variables are set, runs scripts/psp_smoke.py against the processor's test environment.