Skip to main content

Universal Commerce Protocol (UCP)

The JYT Commerce API exposes a Universal Commerce Protocol (UCP) surface that lets AI agents discover and interact with the store through a standardized, spec-compliant REST API. UCP abstracts away Medusa-specific cart semantics and gives agents a uniform checkout flow: discover → search → create session → update → complete → poll.

Why UCP?

Traditional store APIs are designed for human-operated frontends. AI agents need:

  • Self-discovery — a well-known endpoint that describes what the store can do
  • Standardized error envelopes — structured { ucp, messages } format, not raw HTTP errors
  • Status-driven sessions — explicit incomplete → ready_for_complete → complete_in_progress → completed lifecycle
  • Payment next-actions — agents receive a next_action (redirect URL or client secret) instead of having to reverse-engineer provider flows

Architecture

AI Agent


GET /.well-known/ucp ← Discovery manifest


POST /ucp/catalog/search ← Find products
POST /ucp/catalog/lookup ← Get product details


POST /ucp/checkout-sessions ← Create cart (session)
GET /ucp/checkout-sessions/:id
PUT /ucp/checkout-sessions/:id


POST /ucp/checkout-sessions/:id/complete ← Initialize payment
│ Returns next_action

GET /ucp/checkout-sessions/:id ← Poll until status = "completed"


GET /ucp/orders/:id ← Retrieve order

Key Design Decisions

DecisionRationale
UCP checkout session = Medusa cartNo duplicate state; leverages Medusa's cart engine
Async payment flowPayU/Stripe payments are redirect-based; agent polls until completion
Reuses MCP loopback proxycallStoreRoute forwards to /store/* routes, inheriting all middleware (publishable-key scoping, pricing, tax)
.well-known/ucp via middlewareMedusa's file scanner ignores dot-directories; registered as inline handler in defineMiddlewares
INR → PayU, non-INR → StripeCurrency-based provider selection

Protocol Version

Current UCP version: 2026-01-11

All responses include a ucp envelope:

{
"ucp": {
"version": "2026-01-11",
"status": "success"
},
...
}

Required Headers

All /ucp/* routes (except /.well-known/ucp) require:

HeaderDescription
UCP-AgentAgent identifier, e.g. profile="https://agent.example/profile"
Request-IdUnique request ID for tracing
x-publishable-api-keyMedusa publishable API key for sales-channel scoping

Source Files

FilePurpose
src/api/ucp/lib/context.tsPublishable key resolution, region matching, loopback URL
src/api/ucp/lib/formatter.tsMedusa cart → UCP checkout session transformation
src/api/ucp/lib/status-maps.tsCart state → UCP status mapping
src/api/ucp/lib/address-translator.tsUCP ↔ Medusa address translation + country code normalization
src/api/ucp/lib/error-formatter.tsUCP spec-compliant error envelope
src/api/ucp/lib/fulfillment.tsFulfillment methods, groups, and shipping options
src/api/ucp/lib/payment-next-action.tsPayment session → next action (redirect URL / client secret)
src/api/ucp/lib/cart-fields.tsCart field constants for query.graph
src/api/ucp/lib/shipping-options.tsSafe wrapper around listShippingOptionsForCartWorkflow
src/api/ucp/validators.tsZod schemas for all UCP request bodies