Вышел Модуль интеграций 2.0 для MedusaЧитать анонс
Agentic commerce logo

Agentic commerce

Плагин агентной коммерции для Medusa v2 с поддержкой протоколов UCP и ACP. AI-агенты могут просматривать каталог, оформлять заказ и оплачивать его на любой витрине Medusa.

npm install @financedistrict/medusa-plugin-agentic-commerce
Категория
Создано
Версия
1.1.6
Последнее обновление
1 месяц назад
Ежемесячные загрузки
Загрузка данных

@financedistrict/medusa-plugin-agentic-commerce

Make your Medusa v2 store shoppable by AI agents.

This plugin adds UCP and ACP protocol endpoints to your Medusa backend, so AI shopping agents can discover your products, create checkouts, and complete purchases — through standard HTTP APIs that require no frontend at all.

Why this matters

AI agents are becoming the next commerce channel. Just like merchants once added mobile apps alongside their websites, they'll soon need to serve autonomous agents that shop on behalf of consumers. But agents don't browse — they need structured APIs with standardized discovery, checkout flows, and payment settlement.

UCP (Universal Commerce Protocol) and ACP (Agentic Commerce Protocol) are the emerging open standards for this. This plugin implements both as native Medusa v2 modules, so your store speaks the language agents understand — in minutes, with no custom code and no frontend changes.

What you get

FeatureDescription
Dual protocol supportBoth UCP and ACP endpoints from a single plugin
Product discoveryFull-text search and direct lookup for agents to browse your catalog
Checkout sessionsCreate, update, complete, and cancel — with idempotency built in
Pluggable paymentsBring your own payment handler via the adapter interface
Order trackingAgents can retrieve order status and details
Webhook notificationsAutomatic agent callbacks on order placement
Protocol discovery and for automatic capability detection
Product feed syncScheduled job to push your catalog to agent platforms

Quick Start

1. Install

2. Configure

Run after installing or upgrading: the agent session module creates the table and the same module creates the table of the payment ledger. Checkout sessions and carts opened before this version have no row or no session secret and must be recreated by the agent.

A signed payment authorization (token, payer and nonce) can be used on one cart only. The payment ledger records it before the cart is completed, so the same authorization is refused on a second cart (ACP answers ) while the cart that holds it can still retry. Checkout completion fails when the agent session module is not registered.

3. Set Environment Variables

4. Start Your Store

npx medusa develop

Your agent APIs are now live:

Protocols

UCP (Unified Commerce Protocol)

UCP is designed for agent-to-merchant interactions. It uses a shopping-cart model where agents manage carts directly.

EndpointMethodDescription
GETProtocol discovery and capabilities, with
GETDiscovery profile for one enabled UCP version (404 when not enabled)
POSTFull-text product search
POSTDirect product lookup by ID or handle
POSTCreate a new cart
GETRetrieve cart
PUTUpdate cart (add/remove items, set address)
POSTCreate checkout session from cart
GETRetrieve checkout session
PUTUpdate checkout session
POSTComplete checkout and place order
POSTCancel checkout session
GETRetrieve order details

Required headers: , , and on every call that follows the create call (see below)

Session secret: creating a cart or checkout session returns a random response header, once. Send it as the request header on every later call for that cart or session, and on for the order it placed. The store keeps only a hash of it. The header and a Bearer token do not identify the buyer. A request without the secret gets , checked before anything is read. A wrong secret, or an unknown id, gets with , or . The secret is checked before the version pin. URLs in responses carry ids only. If a create response is lost, create a new session: a replayed create (same ) does not return the secret again.

Versions: the store serves (default: the latest version, currently ) plus every version in (default: every other known version, currently , ). The version for a request comes from the of the agent profile named in . The profile is fetched over HTTPS only, from public addresses only, with a 3 s timeout, a 128 KiB cap and no redirects, and cached for 10 minutes. At most 16 profiles are fetched at once, 4 per host and 8 per client IP (); concurrent lookups of one URL share a single fetch, and a busy answer falls back to the last known profile of that URL. Rate-limit at your edge as well.

Agent profile (default)
no header
no in current versioncurrent version
unreachable or not HTTPScurrent version + warning log
profile fetcher busycurrent version + warning log, or the session version with , or the session version
no or malformed current version + warning log
unknown version
known version the store disabled
enabled versionthat versionthat version

Other FD store plugins serve the current version when is missing; this plugin keeps its original .

A checkout session or cart created for a declared version stays on it. A later request that declares a different version gets ; a request whose profile cannot be resolved keeps the session's version. deviates from the UCP spec on purpose: agents built before version negotiation keep working. Warnings are logged as JSON with the key . In , cart and catalog routes answer .

Complete checkout: each entry carries a . With the Prism provider, is , or omitted; is , , or omitted; is or omitted. Any other value returns , and the signed amount must still match the cart's Prism quote. A failed payment returns ; responses under 500 are cached per for 24 hours, so retry with a new key.

ACP (Agent Commerce Protocol)

ACP is designed for platform-to-merchant interactions. It uses a session-based model where the platform manages the checkout flow.

EndpointMethodDescription
GETProtocol discovery and capabilities
POSTCreate checkout session
GETRetrieve checkout session
POSTUpdate checkout session
POSTComplete checkout
POSTCancel checkout session
GETRetrieve order
GETRetrieve product feed

Required headers: ,

A checkout session belongs to the API key that created it. answers unless the order was placed by a session that API key opened.

Payment Handlers

Payment is handled through a pluggable adapter system. Each adapter implements the interface and registers as a Medusa module.

Using the Prism Payment Handler

For x402 stablecoin payments (USDC, FDUSD, etc.), use the companion package:

See @financedistrict/medusa-plugin-prism-payment for setup instructions.

Building a Custom Payment Handler

Implement the interface:

Register it as a Medusa module and reference it in :

Architecture

How Adapter Resolution Works

Medusa v2 modules have isolated DI containers. The plugin resolves payment handler adapters from the request-scoped container () via middleware — not from the module's constructor. This ensures all modules are registered and accessible at request time.

Workflows

The plugin provides four reusable workflows that orchestrate the checkout process:

WorkflowDescription
Validates cart, resolves region, prepares payment
Handles item/address changes, re-prepares payment
Completes payment, creates order
Cancels session and releases resources

Import them in your custom code:

Configuration

Plugin Options

OptionTypeDefaultDescription
API key for ACP Bearer token authentication
HMAC-SHA256 key for request signing. Set it in production: with no key, outbound webhook signatures can be computed by anyone and inbound headers are rejected
Public URL of your storefront
Store name in protocol responses
Store description for discovery
requiredMedusa payment provider that settles agent payments, for example
Allows for local testing. It approves every payment, so it also needs or and no
Module keys of payment handler adapters
latest ()Current UCP version, served when the agent declares none. Set to keep the root profile of 0.x releases
every known version except Further UCP versions served on request; the current version is removed from this list
How an unusable agent profile is handled (see UCP above)
ACP protocol version to advertise

An unknown version or negotiation value stops the store at boot. So does a missing , or the system provider outside the local-testing case above.

Medusa's own and any other caller of cannot complete an agent cart: a validate hook lets it complete only inside the plugin's checkout completion. Medusa allows one handler per workflow hook, so a store that registers its own fails at boot with this plugin; move that check to another hook or step. The hook also runs for a cart that already has an order, so a repeated native complete of an agent cart answers .

The plugin records on the agent session that the payment provider is about to be called, through the hook of . A failure after that point holds the payment for review instead of freeing the cart for another credential. Medusa allows one handler per workflow hook, so a store or another plugin that registers its own handler fails at boot with this plugin.

Environment Variables

VariableMaps to

Exported Utilities

Protocol Compliance

Types and formatters are audited against the official protocol specifications:

  • UCP , — catalog, cart, checkout, fulfillment, payment, order, discovery; — checkout, fulfillment, payment, order, discovery
  • ACP — checkout sessions, delegate payment, capabilities

Versioning

This package follows semver. While pre-1.0:

  • Protocol spec changes → minor bump (e.g., 0.1.x → 0.2.0)
  • Medusa compatibility changes → patch bump (e.g., 0.1.0 → 0.1.1)
  • Bug fixes → patch bump

The companion declares this package as a peer dependency with a range (e.g., ), so incompatible combinations are caught at install time.

Requirements

  • Medusa v2 (2.x)
  • Node.js >= 20
  • PostgreSQL (standard Medusa requirement)

License

MIT


Built by Finance District