# MCP endpoint (/mcp)

Code: `worker/mcp.js`. Tool wording: `config/copy.json` → `tools`.

## Transport

Streamable HTTP, single endpoint `POST /mcp`, JSON responses (`application/json`); no SSE stream is opened because every tool answers at once. `GET` and `DELETE` return 405. A present `Origin` header that is not this site's origin (or in `MCP_ALLOWED_ORIGINS`) gets 403. No sessions; `Mcp-Session-Id` is ignored.

- Current spec 2026-07-28 (stateless): https://modelcontextprotocol.io/specification/2026-07-28/basic/transports . Every request carries `_meta["io.modelcontextprotocol/protocolVersion"]`; the `MCP-Protocol-Version`, `Mcp-Method` and (for tools/call) `Mcp-Name` headers must match the body, otherwise 400 with -32020 (HeaderMismatch). Unsupported versions: 400 with -32022 and `{supported, requested}`. `server/discover` is implemented. Results carry `resultType: "complete"`; tools/list and server/discover carry `ttlMs` and `cacheScope: "public"`.
- Earlier versions 2025-03-26, 2025-06-18, 2025-11-25 (initialize handshake): https://modelcontextprotocol.io/specification/2025-06-18/basic/transports . The server answers `initialize` with the client's version if supported (else 2025-11-25), accepts `notifications/initialized` with 202, then tools/list and tools/call.

## Tools

| Tool | Input | Output |
|---|---|---|
| verify_delivery_receipt | `receipt`, optional `file_sha256` | `{valid, state, reasons}` (structuredContent) |
| lookup_delivery_receipt | any of `receipt_id`, `file_sha256`, `seller` | `{entries, count}` |
| log_stats | none | /stats object |
| publish_delivery_receipt | `receipt`, optional `seller_link`, `buyer_link` | the new log entry; seller-only/invalid → isError |

Descriptions are plain statements of what the tool does (no instructions to the model). They live in `config/copy.json`.

## Registry (not published)

Draft: `docs/server.json` (schema 2025-12-11, `remotes: [{type: "streamable-http", url}]`). Publishing to the official MCP Registry needs:
1. A public HTTPS URL for /mcp (the registry does not host or check it).
2. The namespace `com.wayreceipt/*` requires proving control of `wayreceipt.com`: a DNS TXT record `v=MCPv1; k=ed25519; p=<base64 public key>` at the apex (`mcp-publisher login dns`), or HTTP auth with `https://wayreceipt.com/.well-known/mcp-registry-auth` (`mcp-publisher login http`). We do not own wayreceipt.com, so a human must buy the domain (cost) or pick another namespace (e.g. a GitHub-based `io.github.<user>/...`, which needs a GitHub account; our GitHub signup was blocked).
3. `mcp-publisher publish`. The registry is in preview.
Docs: https://github.com/modelcontextprotocol/registry/tree/main/docs/modelcontextprotocol-io (remote-servers.mdx, authentication.mdx).
