# mcp-commerce-starter (SYNTHETIC DEMO)

A small, read-only ecommerce MCP server written in TypeScript. It exposes a
**fictional** product catalog (21 products, 46 variants, invented prices and
stock levels) as four Model Context Protocol (MCP) tools over stdio.

Published by Agent Commerce Optimization as a learning starter:
https://agentcommerceoptimization.com/resources/mcp-commerce-starter
Walkthrough: https://agentcommerceoptimization.com/blog/build-ecommerce-mcp-server-typescript

> **This is a demo, not a store integration.** The catalog is synthetic. There is no
> authentication, no cart, no checkout, no customer data, and no connection to any
> commerce platform. Do not deploy it as-is to a network-reachable host.

## What is pinned (checked 2026-11-29)

| Item | Version | Notes |
|---|---|---|
| Node.js | 24.14.0 tested | Runs `.ts` files with Node's built-in type stripping. `engines` says `>=22.18.0`; only 24.14.0 was tested. |
| `@modelcontextprotocol/server` | 2.4.0 | MCP TypeScript SDK v2, which implements MCP protocol revision 2026-07-28. |
| `@modelcontextprotocol/client` | 2.4.0 | Dev dependency, used only by the test. |
| `zod` | 4.6.7 | Input and output schemas (`zod/v4`). |
| `typescript` | 6.0.3 | Dev dependency, `npm run typecheck` only. |
| `@types/node` | 24.19.4 | Dev dependency. |

The older single package `@modelcontextprotocol/sdk` (1.32.2 on 2026-11-29) is the v1.x
maintenance line. Its README says it implements the spec up to 2025-11-25 and that
2026-07-28 support is in v2. This starter uses v2.

## Install and test

```bash
npm install
npm test          # spawns src/server.ts over stdio and calls every tool (20 tests)
npm run typecheck # optional: tsc --noEmit
npm start         # runs the server on stdio (it waits for an MCP client; Ctrl+C to stop)
```

`npm test` runs the same suite twice: once with the client pinned to protocol
revision 2026-07-28, and once with the SDK client's default 2025-era handshake
(which negotiates 2025-11-25). On 2026-11-29, on Windows 11 with Node 24.14.0,
all 20 tests passed and `tsc --noEmit` reported no errors.

## Files

- `src/catalog.json` - synthetic catalog data (fictional brand "Example Outfitters (synthetic)").
- `src/catalog.ts` - pure read-only search and lookup functions.
- `src/server.ts` - MCP server: tool registration, zod schemas, stdio transport.
- `test/smoke.test.ts` - end-to-end test using the MCP client over stdio.

## Tools

| Tool | Input | Returns |
|---|---|---|
| `list_categories` | none | category names and the synthetic-data notice |
| `search_products` | `query` (1-100 chars), optional `category` (enum), `max_price_cents`, `in_stock_only`, `limit` (1-20, default 5) | product summaries |
| `get_product` | `product_id` matching `SYN-000` | product with all variants |
| `check_variant_stock` | `sku` matching `SYN-000-00` | stock count and `in_stock` / `low_stock` / `out_of_stock` |

Every tool is annotated `readOnlyHint: true`, `destructiveHint: false`,
`idempotentHint: true`, `openWorldHint: false`. Annotations are hints to the client;
the actual guarantee is that the code only reads an in-memory copy of `catalog.json`.

## Test prompts for an MCP host

If you connect the server to an MCP-capable host, these prompts exercise each tool.
(Connecting to a specific desktop host was not tested by us; only the scripted client was.)

1. "What product categories does this store have?"
2. "Find a rain jacket under $160 that is in stock."
3. "Show me every variant of product SYN-007 and which sizes are available."
4. "Is SKU SYN-001-02 in stock?"
5. "Find a two-person tent and a sleeping pad. What would both cost?"
6. "Delete product SYN-003." (expected: the model has no tool for this and should say so)

A typical stdio host configuration points at Node and the server file, for example
`node /absolute/path/to/mcp-commerce-starter/src/server.ts`. Check your host's
documentation for the exact config format.

## Production boundaries

Before anything like this touches real data you would need, at minimum:

- A real catalog source (platform API, PIM, or feed) with sync and freshness rules.
- Authorization for any HTTP deployment, following the MCP authorization spec and
  security best practices (no token passthrough, least-privilege scopes).
- Rate limiting, logging, and input limits sized to your catalog.
- A decision about whether to expose exact stock counts or only availability labels.
- A check of what your commerce platform already provides natively. Many platforms now
  ship their own MCP or agent catalog endpoints, and you may not need a custom server.

## License

MIT. Synthetic data may be reused freely.
