← Documentation
@opencommerceprotocol/bridge-ucp

UCP Bridge

Convert an OCP manifest into a UCP (Universal Checkout Protocol) manifest, enabling Google UCP checkout agents to discover and interact with OCP stores. Define once in OCP, bridge to Google's checkout ecosystem.

Installation

npm install @opencommerceprotocol/bridge-ucp

Usage

Two core functions: ocpToUCP() returns a manifest object, generateUCPWellKnown() returns a JSON string ready to serve.

convert.ts
import { ocpToUCP, generateUCPWellKnown } from '@opencommerceprotocol/bridge-ucp';
import type { OCPManifest } from '@opencommerceprotocol/spec';

const ocpManifest: OCPManifest = { /* your manifest */ };

// Convert to UCP manifest object
const ucpManifest = ocpToUCP(ocpManifest);

// Or generate the JSON string for serving at /.well-known/ucp
const ucpJson = generateUCPWellKnown(ocpManifest);

Serving the UCP Endpoint

Express

server.ts
import express from 'express';
import { generateUCPWellKnown } from '@opencommerceprotocol/bridge-ucp';
import manifest from './.well-known/ocp.json';

const app = express();

app.get('/.well-known/ucp', (req, res) => {
  res.setHeader('Content-Type', 'application/json');
  res.send(generateUCPWellKnown(manifest));
});

Hono (Cloudflare Workers)

worker.ts
import { Hono } from 'hono';
import { ocpToUCP } from '@opencommerceprotocol/bridge-ucp';
import manifest from './.well-known/ocp.json';

const app = new Hono();
app.get('/.well-known/ucp', (c) => c.json(ocpToUCP(manifest)));

Field Mapping

How OCP manifest fields map to UCP manifest fields:

merchant.namename
merchant.urlurl
merchant.logologo
merchant.descriptiondescription
capabilities.catalogcapabilities[{ type: 'Catalog' }]
capabilities.searchcapabilities[{ type: 'Search' }]
capabilities.cartcapabilities[{ type: 'Cart' }]
capabilities.checkoutcapabilities[{ type: 'Checkout' }] + checkout.mode
capabilities.orderscapabilities[{ type: 'OrderTracking' }]
payments.handlerspayments.methods
payments.currenciespayments.currencies
discovery.feedcatalog.feed
discovery.feed_formatcatalog.format

UCPManifest Type

types.ts
interface UCPManifest {
  '@context': string;    // 'https://schema.googleapis.com/ucp/v1'
  '@type': string;       // 'UniversalCheckoutProvider'
  name: string;
  url: string;
  logo?: string;
  description?: string;
  capabilities: UCPCapability[];
  payments: {
    methods: string[];
    currencies: string[];
  };
  catalog?: {
    feed: string;
    format: string;
  };
  checkout?: {
    mode: string;        // 'full' | 'redirect' | 'escalate'
    url?: string;
  };
  ocp_source?: string;   // link back to the OCP manifest
}

interface UCPCapability {
  type: string;          // 'Catalog' | 'Search' | 'Cart' | 'Checkout' | 'OrderTracking'
  enabled: boolean;
  endpoint?: string;
}

OCP Manifest Declaration

Declare the UCP endpoint in your OCP manifest so agents can discover it:

/.well-known/ocp.json (excerpt)
{
  "bridge": {
    "ucp": "https://mystore.com/.well-known/ucp"
  }
}

CLI Alternative

Generate the UCP manifest without writing code:

npx @opencommerceprotocol/cli bridge --protocol ucp --manifest .well-known/ocp.json

Next Steps