surfcad-mcp 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1 +1,71 @@
1
- # surfcad-mcp\nMCP server for SurfCAD. Coming soon.
1
+ # surfcad-mcp
2
+
3
+ Stdio [Model Context Protocol](https://modelcontextprotocol.io/) server for the SurfCAD browser agent bridge. Each tool maps to one `window.surfcad` command from the shipped command catalog (`data/commands.json`). The server pairs to your open SurfCAD tab through the **M1** loopback WebSocket relay (`ws://127.0.0.1:17341` by default).
4
+
5
+ ## Install and run
6
+
7
+ ```bash
8
+ npx surfcad-mcp
9
+ ```
10
+
11
+ The process speaks MCP over **stdio**. Pair it to a running SurfCAD tab (see below), then your MCP client can call bridge tools (`status`, `set_script`, `run`, …) plus a `pair` helper.
12
+
13
+ Environment variables:
14
+
15
+ | Variable | Purpose |
16
+ | --- | --- |
17
+ | `SURFCAD_PAIRING_CODE` | 6-character code from the SurfCAD **Local agent** panel (optional if you use the `pair` tool). |
18
+ | `SURFCAD_AGENT_BRIDGE_WS_URL` | Relay URL (default `ws://127.0.0.1:17341`). |
19
+
20
+ ## Pair with SurfCAD (Local agent)
21
+
22
+ 1. Run SurfCAD with the agent bridge on (`npm run dev` in the [SurfCAD repo](https://github.com/artur0x0/surfcad), or open the app with `?agent=1` / `localStorage surfcadAgent=1`).
23
+ 2. Open the **profile** menu → **Local agent** → **Show pairing code** and leave the tab open.
24
+ 3. Start `surfcad-mcp` with that code in `SURFCAD_PAIRING_CODE`, or call the MCP **`pair`** tool with `{ "code": "ABCDEF" }`.
25
+ 4. Click **Allow connection** in SurfCAD when prompted.
26
+
27
+ The Vite dev/preview server starts the relay automatically. Nothing pairs silently — you must show the code and approve the connection.
28
+
29
+ ## MCP client config (Cursor / Claude Desktop)
30
+
31
+ ```json
32
+ {
33
+ "mcpServers": {
34
+ "surfcad": {
35
+ "command": "npx",
36
+ "args": ["-y", "surfcad-mcp"],
37
+ "env": {
38
+ "SURFCAD_PAIRING_CODE": "ABCDEF"
39
+ }
40
+ }
41
+ }
42
+ }
43
+ ```
44
+
45
+ In Cursor, add the same block under **Settings → MCP** or your project `.cursor/mcp.json`.
46
+
47
+ ## Safety and consent
48
+
49
+ - **Commerce:** Agents cannot place orders or drive checkout. Quote/cart/checkout controls are not exposed as MCP tools.
50
+ - **Git on real repos:** Writes may return `real_repo_blocked` until the user consents in the app.
51
+ - **Destructive git operations:** Need explicit approval; the bridge returns `confirm_required` unless args include `confirm: true` after the user has confirmed in SurfCAD.
52
+
53
+ Bridge refusals (`real_repo_blocked`, `confirm_required`, `not_paired`, user deny, etc.) are returned as structured JSON in MCP tool errors.
54
+
55
+ ## Monorepo maintenance
56
+
57
+ In the [SurfCAD monorepo](https://github.com/artur0x0/surfcad), `npm run export:agent` regenerates `data/commands.json` from `src/agent/commands.json`. CI fails if that copy is stale (`test/commandsFreshness.test.mjs`). Before publishing, run `export:agent` and `npm run smoke:pack` in this package.
58
+
59
+ Agent-oriented guide: [`docs/agent/SKILL.md`](https://github.com/artur0x0/surfcad/blob/main/docs/agent/SKILL.md). Scripted demo from a full checkout: `npm run demo:mcp` at the repo root.
60
+
61
+ ## Releasing to npm
62
+
63
+ The [`surfcad-mcp`](https://www.npmjs.com/package/surfcad-mcp) package is published from GitHub Actions (workflow [`.github/workflows/publish-mcp.yml`](../../.github/workflows/publish-mcp.yml)) using [npm Trusted Publishing](https://docs.npmjs.com/trusted-publishers) (OIDC). The trusted publisher is configured on npm for this repository and workflow file — no `NPM_TOKEN` is stored in GitHub.
64
+
65
+ Ways to release a new version:
66
+
67
+ 1. **Version bump on `main`** — In a PR, bump `version` in `packages/surfcad-mcp/package.json`. After merge, when the **CI** workflow completes successfully on `main` and the version differs from the parent commit, publish runs automatically (skipped if that version is already on npm).
68
+ 2. **Git tag** — Push a tag `surfcad-mcp-vX.Y.Z` that exactly matches the `version` field at that commit (for example `surfcad-mcp-v0.2.0` for `"version": "0.2.0"`).
69
+ 3. **Manual** — In GitHub → Actions → **Publish surfcad-mcp** → **Run workflow** on branch `main`.
70
+
71
+ Before bumping, run `npm run export:agent` at the repo root if the command catalog changed, and `npm test` plus `npm run smoke:pack` in this package.
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import { runSurfcadMcpServer } from '../src/server.mjs';
3
+
4
+ runSurfcadMcpServer().catch((err) => {
5
+ console.error(err);
6
+ process.exit(1);
7
+ });