This directory contains a reference implementation of a Universal Commerce Protocol (UCP) server built with Node.js, Hono and Zod. It demonstrates how to implement the UCP specifications for shopping, checkout, and order management.
- Node.js (v20 or higher recommended)
- npm (Node Package Manager)
-
Clone this repo
git clone https://github.com/Universal-Commerce-Protocol/samples.git cd samples/rest/nodejs -
Install Dependencies
Run the following command in this directory to install the required Node.js packages:
npm install
-
Database Setup
The server uses SQLite for persistence. Ensure the
databasesdirectory exists. The server will automatically initialize the database files (products.dbandtransactions.db) and tables on the first run.If the
databasesdirectory does not exist, create it:mkdir -p databases
Note: For the server to function fully (e.g., to create a checkout), you may need to populate
products.dbwith sample product data, as the server expects products to exist for validation.
To start the server in development mode (with hot reloading):
npm run devTo build and start the server for production:
npm run build
npm startThe server will start on port 3000 by default. You can access the discovery endpoint at:
http://localhost:3000/.well-known/ucp
To verify that this server implementation complies with the UCP specifications, use the official UCP Conformance Test Suite.
-
Get the Conformance Tests
Clone the conformance repository:
git clone https://github.com/Universal-Commerce-Protocol/conformance.git cd conformance -
Run the Tests
Follow the instructions in the conformance repository to install its dependencies. Then, run the tests against this local server implementation.
Assuming the conformance suite uses a configuration file or environment variables to target the server, ensure it is pointing to:
http://localhost:3000
src/api: Contains the implementation of UCP services (Discovery, Checkout, Order).src/data: Database access layer (SQLite).src/models: TypeScript types and Zod schemas (some generated from specs).src/utils: Helper utilities for validation and logging.databases: Directory where SQLite database files are stored.