generated by tools/build-site.mjs from docs/AGENT-ACCESS.md # Agent access: MCP adapter and HTTPS API AI agents can use PartPier without a browser. You can connect them in two ways: - **MCP adapter.** `js/partpier-mcp.mjs` is a stdio MCP server in a single file. It needs Node.js 22 and has no dependencies. The site serves it at `/js/partpier-mcp.mjs`. - **HTTPS.** Call the `/api/v1` routes directly. The portal uses the same routes. The adapter adds no permissions of its own. The service checks every request exactly as it checks a portal request. The adapter only reaches a fixed list of public, sign-in and customer routes. It never calls staff routes. | File | Purpose | | --- | --- | | `js/partpier-mcp.mjs` | The adapter. With no command it serves MCP. It also has `login`, `logout`, `tools`, `call` and `manifest` commands. | | `js/partpier-agent.json` | A machine-readable manifest. It lists the service, the adapter's SHA-256, the auth flow, request limits and every tool with its REST route. | | `server/tests/agent-mcp.test.mjs` | Tests that run the adapter against the real in-memory service. | Service: `https://partpier-preview.brainclub.com`. Set `PARTPIER_URL` to use another origin. It must be `https`; plain `http` is allowed for `localhost` only. ## 1. Install ```sh mkdir -p ~/.local/share/partpier && cd ~/.local/share/partpier curl -fsSO https://partpier-preview.brainclub.com/js/partpier-mcp.mjs curl -fsS https://partpier-preview.brainclub.com/js/partpier-agent.json | node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>console.log(JSON.parse(s).adapter.sha256))' shasum -a 256 partpier-mcp.mjs # the two hashes must match node partpier-mcp.mjs --version ``` Add it to an MCP client as a local stdio server. The command is `node` and the argument is the absolute path to the file: ```json { "mcpServers": { "partpier": { "command": "node", "args": ["/Users/you/.local/share/partpier/partpier-mcp.mjs"] } } } ``` Claude Code: `claude mcp add partpier -- node /Users/you/.local/share/partpier/partpier-mcp.mjs`. | Environment name | Meaning | | --- | --- | | `PARTPIER_URL` | Service origin. Default: `https://partpier-preview.brainclub.com`. | | `PARTPIER_SESSION_FILE` | Where `login` stores the session. Default: `$XDG_CONFIG_HOME/partpier/session.json`, or `~/.config/partpier/session.json`. | | `PARTPIER_SESSION` | A customer session token supplied by a trusted environment, such as a secrets manager. It overrides the file. Never put it in shared configuration. | ## 2. Authentication and consent **Public tools need no account.** These are catalogue search, models, drawings, brief drafting, the intake assistant and the public quote request. **Customer tools need a customer session.** Use the existing one-time email code sign-in in one of three ways. 1. **Trusted terminal (recommended).** The user runs `node partpier-mcp.mjs login` in their own terminal. It asks for the email and the code and stores the session. The code never passes through the agent. - The command refuses to run without an interactive terminal. - The session file is written with mode `0600` in a `0700` directory. - The file records the origin that issued the session. The token is only ever sent to that origin. - The adapter refuses a session file that other users can read. - The adapter reads the file again on each call, so a login in another terminal works without restarting the client. - `node partpier-mcp.mjs logout` ends the session and deletes the file. 2. **In the conversation.** Call `sign_in_start`, then `sign_in_verify` with the emailed code. The code passes through the conversation. It is single-use, expires after 10 minutes and allows 5 tries. The adapter keeps the session in memory only. 3. **Trusted environment.** Set `PARTPIER_SESSION` to a token the environment already holds. The adapter never returns a session token or sign-in code in tool output, CLI output or logs. It writes nothing to stderr while serving. **Staff accounts are refused.** A session whose kind is not `customer` is signed out on the service and dropped. This applies whether it came from `sign_in_verify`, `login` or the environment. The route allowlist (`routeAllowed`) excludes these routes: - every `/api/v1/admin/*` route and view-as - invites, member changes and export - decline, withdraw and cancel - file uploads **Consent.** The service records the declarations as the user's own. The agent must show the user what will be sent and get their answer. It must never infer consent. | Tool | What the user confirms | How the adapter enforces it | | --- | --- | --- | | `send_public_quote_request` | The recipient (PartPier), the request, the intended use, civil use, the sanctions line and the privacy notice (`/privacy/`) | `privacy_ack`, `end_use.civil_use_confirmed` and `end_use.sanctions_confirmed` must be `true`. If the client supports MCP elicitation, the user also sees a confirmation prompt, and a decline sends nothing. | | `submit_quote_request` | The end-use declaration on the draft | Uses the same elicitation prompt when the client supports it. The service refuses a draft without the confirmations. | | `accept_quote` | **A binding order** for the offer total | Needs an elicitation prompt that the user accepts. In `call` mode it needs `yes` typed at an interactive terminal. Without either, the tool returns `approval_required` and points the user to `/account/`. The service also applies the member's approval limit, the sanctions review and role permissions. | Supported destinations are the 32 European countries in `data/delivery.json`. Russia and Belarus are refused with the sanctions line. Each quantity break is a whole number from 1 to 1000, up to 6 breaks, in ascending order. The public enquiry endpoint enforces the same destination list and the 1–1000 unit range. ## 3. Tools | Tool | Session | Effect | REST route | | --- | --- | --- | --- | | `search_catalogue` | none | read | `GET /api/v1/catalogue/configurations?q=&model=&material=&process=&max-x=&max-y=&max-z=&dim-=&page=` | | `get_catalogue_model` | none | read | `GET /api/v1/catalogue/models[/:id]` | | `get_configuration_drawing` | none | read | `GET /api/v1/catalogue/configuration-drawing?code=&material=` | | `draft_brief` | none | local | (none; composes a brief offline and lists missing details) | | `ask_brief_assistant` | none | read | `POST /api/v1/assistant/brief` | | `send_public_quote_request` | none | write, confirmed | `POST /api/v1/public/requests` | | `sign_in_start`, `sign_in_verify`, `sign_out` | none | session | `POST /api/v1/auth/start`, `/verify`, `/signout` | | `whoami` | customer | read | `GET /api/v1/me` | | `list_projects`, `create_project` | customer | read, write | `GET`, `POST /api/v1/orgs/:org/projects` | | `list_sketches`, `save_sketch` | customer | read, write | `GET`, `POST /api/v1/orgs/:org/projects/:id/sketches` | | `create_configuration` | customer | write | `POST /api/v1/orgs/:org/configurations` | | `list_parts`, `create_part` | customer | read, write | `GET`, `POST /api/v1/orgs/:org/parts` | | `draft_quote_request` | customer | write | `POST /api/v1/orgs/:org/quote-requests` | | `list_quote_requests`, `get_quote_request` | customer | read | `GET /api/v1/orgs/:org/quote-requests[/:id]` | | `submit_quote_request` | customer | write, confirmed | `POST /api/v1/orgs/:org/quote-requests/:id/submit` | | `accept_quote` | customer | **commitment** | `POST /api/v1/orgs/:org/quote-requests/:id/accept` | | `list_orders` | customer | read | `GET /api/v1/orgs/:org/orders` | | `get_order_status` | customer | read | `GET /api/v1/orgs/:org/orders/:id` and `GET /api/v1/orgs/:org/fulfilment/linked/orders/:id` | `org_id` is optional when the user belongs to one workspace. With several workspaces, the tool lists them and asks for one. The drawing tool returns: - the lettered dimensions with their ranges - the envelope and volume - the measured mass - four small SVG views: isometric, front, side and top `save_sketch` accepts the editor's sketch configuration (`schemas/project-sketch.json`, `docs/SKETCH.md`). The service rebuilds and measures it. An identical sketch returns the saved one. **Idempotency.** Every write sends an `Idempotency-Key`. You can pass `idempotency_key` (a UUID) yourself. Otherwise the adapter derives one from the tool, origin, workspace and arguments, so the same call made again returns the first answer. The service replays a successful response for 24 hours. It keys the replay by the signed-in user, or by the IP hash for public requests. After a network failure or a `502`, `503` or `504`, the adapter retries a keyed write once with the same key. A response lost after the service committed the write therefore replays the original order or reference. The tests check this. To create two identical records on purpose, pass a fresh key. **Errors.** A failed call returns `isError: true` with `{"error":{"code","message","fields"?,"retry_after_s"?}}`. Common codes: - `unauthenticated`: sign in again - `forbidden`: a staff session, or a missing role permission - `not_found`: also returned for another organisation's records - `validation_failed` - `refused_destination` - `illegal_transition` - `approval_required` - `over_approval_limit` - `rate_limited`: honour `retry_after_s` - `not_allowed`: the route is outside the adapter's allowlist ## 4. Without MCP: the command line ```sh node partpier-mcp.mjs tools # every tool with its JSON input schema node partpier-mcp.mjs call search_catalogue '{"q":"oak spool"}' node partpier-mcp.mjs call get_configuration_drawing '{"code":"PP-PCS-A60-B17-C3","material":"petg"}' node partpier-mcp.mjs call draft_brief '{"product":"Oak cable spool","quantities":[10,50],"destination_country":"LV"}' node partpier-mcp.mjs login # interactive terminal only node partpier-mcp.mjs call list_orders '{}' ``` `call` prints the result as JSON and exits with status 1 on an error. Declarations count as confirmed through the explicit argument fields. Placing an order needs `yes` typed at an interactive terminal. ## 5. HTTPS directly Rules for direct calls: - Every non-GET request must send `Origin: https://partpier-preview.brainclub.com`. Without it the service returns `403`. - Send JSON bodies. The service refuses unknown fields. - Send `Idempotency-Key: ` on writes you may retry. - The session is the `__Host-pp_sid` cookie. Keep the cookie jar private (`umask 077`) and delete it after use. The write examples below are **real requests** to the preview service. Run them only with a real user's consent. ```sh B=https://partpier-preview.brainclub.com H=(-H "Origin: $B" -H 'Content-Type: application/json') # Catalogue and drawings (public) curl -s "$B/api/v1/catalogue/configurations?q=oak&material=oak&page=1" curl -s "$B/api/v1/catalogue/models/panel-corner-sleeve" curl -s "$B/api/v1/catalogue/configuration-drawing?code=PP-PCS-A60-B17-C3&material=petg" # Brief assistant (public, rate-limited) curl -s "${H[@]}" -X POST "$B/api/v1/assistant/brief" \ -d '{"messages":[{"role":"user","content":"I need 50 oak cable spools, 40 mm across."}]}' # Public quote request: explicit end use, privacy acknowledgement, a supported destination, quantities 1–1000 curl -s "${H[@]}" -H "Idempotency-Key: $(uuidgen | tr A-Z a-z)" -X POST "$B/api/v1/public/requests" -d '{ "email":"buyer@example.com","name":"A Buyer","company":null,"country":"LV", "message":"Product: Oak cable spool\nDimensions: 40 mm diameter, 30 mm span, 6 mm bore", "items":[{"model_id":"thread-spool","part_code":"PP-TSP-F40-S30-D6","params":null,"quantities":[10,50]}], "end_use":{"category":"other","description":"Winding cable in a workshop","civil_use_confirmed":true,"sanctions_confirmed":true}, "privacy_ack":true}' # → 202 {"ref":"PP-R-2611-0001","received_at":"…"} # Customer sign-in: the code arrives by email umask 077; J=$(mktemp) curl -s "${H[@]}" -X POST "$B/api/v1/auth/start" -d '{"email":"buyer@example.com"}' curl -s "${H[@]}" -c "$J" -X POST "$B/api/v1/auth/verify" -d '{"email":"buyer@example.com","code":"123456"}' curl -s -b "$J" "$B/api/v1/me" # memberships[].org.id is $ORG # Workspace: project, sketch, part, quote draft, submit curl -s "${H[@]}" -b "$J" -H "Idempotency-Key: $(uuidgen | tr A-Z a-z)" -X POST "$B/api/v1/orgs/$ORG/projects" -d '{"name":"Drill press guard"}' curl -s "${H[@]}" -b "$J" -X POST "$B/api/v1/orgs/$ORG/projects/$PROJECT/sketches" -d '{"configuration":{…editor configuration…}}' curl -s "${H[@]}" -b "$J" -X POST "$B/api/v1/orgs/$ORG/parts" -d "{\"name\":\"Guard plate\",\"project_id\":\"$PROJECT\",\"source\":{\"sketch_id\":\"$SKETCH\"},\"material\":\"oak\"}" curl -s "${H[@]}" -b "$J" -X POST "$B/api/v1/orgs/$ORG/quote-requests" -d "{\"project_id\":\"$PROJECT\",\"destination_country\":\"LV\", \"end_use\":{\"category\":\"industrial_machinery\",\"description\":\"Guard plate for a workshop drill press\",\"civil_use_confirmed\":true,\"sanctions_confirmed\":true}, \"lines\":[{\"part_id\":\"$PART\",\"quantities\":[1,10]}]}" curl -s "${H[@]}" -b "$J" -X POST "$B/api/v1/orgs/$ORG/quote-requests/$QUOTE/submit" -d '{}' # Offer, order and delivery status curl -s -b "$J" "$B/api/v1/orgs/$ORG/quote-requests/$QUOTE" # .offer once quoted curl -s -b "$J" "$B/api/v1/orgs/$ORG/orders" curl -s -b "$J" "$B/api/v1/orgs/$ORG/orders/$ORDER" # status + customer-visible events curl -s -b "$J" "$B/api/v1/orgs/$ORG/fulfilment/linked/orders/$ORDER" # dispatches: carrier, tracking_ref # Accepting an offer places a binding order. Only on the user's explicit instruction: # POST /api/v1/orgs/$ORG/quote-requests/$QUOTE/accept {"choices":[{"line_id":"…","quantity":10}],"po_number":null} curl -s "${H[@]}" -b "$J" -X POST "$B/api/v1/auth/signout" -d '{}'; rm -f "$J" ``` Shapes are defined in `schemas/*.json` and `docs/API.md`. Validation rules are in `js/api/rules.js`. ## 6. Testing and maintenance ```sh cd server && node --test tests/agent-mcp.test.mjs ``` The tests run the adapter on in-memory stdio against `createApp` with the memory store and memory mail sink. They do not touch the network. They check: - The adapter's destinations, sanctions line, end-use categories and quantity limits against `data/delivery.json`, `schemas/public-request.json` and `js/api/rules.js`. The manifest must equal `node js/partpier-mcp.mjs manifest`. Every allowed route must exist in `server/http/router.mjs`, and staff routes must be outside the allowlist. - That the file starts with `node` alone: initialize, tools/list, parse and method errors, a local tool and an unauthenticated call. They also check that the site serves the adapter and manifest from `/js/`. - Public tools: search, the drawing's dimensions and views, the brief, refused destinations and quantities, a declined prompt that sends nothing, and an idempotent public request that stores one row and sends no mail. - Customer tools: in-chat sign-in, project, sketch, part from a sketch, configuration and part, quote draft, and submit after confirmation. Staff then quote through the fixture, not the adapter. An order cannot be placed without an elicitation prompt. A declined prompt places nothing. An approved order survives a lost response with one order. The test also checks order status, delivery, organisation scoping, sign-out, and that no token or code appears in MCP output. - Staff sessions from the chat or the environment are refused and ended on the service. - The session file: binding to its origin, refusal of `0644`, and removal on sign-out. After changing the adapter, regenerate the manifest so its SHA-256 matches: ```sh node js/partpier-mcp.mjs manifest > js/partpier-agent.json ``` When `data/delivery.json`, the end-use categories or the quantity limits change, update the constants at the top of the adapter. The first test fails until they match.