surfcad-mcp 0.1.0 → 0.2.1
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 +41 -7
- package/data/commands.json +1404 -171
- package/package.json +1 -1
- package/src/bridge/bridgePage.mjs +132 -0
- package/src/bridge/bridgePopup.mjs +261 -0
- package/src/bridge/localAddress.mjs +55 -0
- package/src/bridge/relayHub.mjs +462 -0
- package/src/bridge/relayServer.mjs +268 -0
- package/src/errors.mjs +24 -1
- package/src/nodeClient.mjs +27 -6
- package/src/relay.mjs +267 -59
- package/src/server.mjs +95 -7
package/README.md
CHANGED
|
@@ -8,7 +8,9 @@ Stdio [Model Context Protocol](https://modelcontextprotocol.io/) server for the
|
|
|
8
8
|
npx surfcad-mcp
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
The process speaks MCP over **stdio
|
|
11
|
+
The process speaks MCP over **stdio** and **starts the local relay** on `127.0.0.1:17341` (loopback only). If another process is already listening there (a second MCP client or the SurfCAD dev server), it reuses that relay instead of failing.
|
|
12
|
+
|
|
13
|
+
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
14
|
|
|
13
15
|
Environment variables:
|
|
14
16
|
|
|
@@ -16,15 +18,20 @@ Environment variables:
|
|
|
16
18
|
| --- | --- |
|
|
17
19
|
| `SURFCAD_PAIRING_CODE` | 6-character code from the SurfCAD **Local agent** panel (optional if you use the `pair` tool). |
|
|
18
20
|
| `SURFCAD_AGENT_BRIDGE_WS_URL` | Relay URL (default `ws://127.0.0.1:17341`). |
|
|
21
|
+
| `SURFCAD_MCP_START_RELAY` | Set to `0` to skip starting the relay (tests only). |
|
|
19
22
|
|
|
20
23
|
## Pair with SurfCAD (Local agent)
|
|
21
24
|
|
|
22
|
-
1.
|
|
25
|
+
1. Open [https://surfcad.com](https://surfcad.com) (or local dev).
|
|
23
26
|
2. Open the **profile** menu → **Local agent** → **Show pairing code** and leave the tab open.
|
|
24
|
-
3.
|
|
27
|
+
3. Add `surfcad-mcp` to your MCP client (`npx surfcad-mcp`), set `SURFCAD_PAIRING_CODE` to that code, or call the MCP **`pair`** tool with `{ "code": "ABCDEF" }`.
|
|
25
28
|
4. Click **Allow connection** in SurfCAD when prompted.
|
|
26
29
|
|
|
27
|
-
|
|
30
|
+
Nothing pairs silently — you must show the code and approve the connection.
|
|
31
|
+
|
|
32
|
+
### Safari
|
|
33
|
+
|
|
34
|
+
Safari on a Mac blocks https pages from opening `ws://127.0.0.1` directly. In Safari, **Connect Agent** also opens a small window titled **SurfCAD local agent bridge**, served by this relay at `http://127.0.0.1:17341/bridge`. It carries the connection between the tab and the relay; keep it open while the agent works. If it closes, the Local agent panel shows **Disconnected** with a **Reconnect** button, and you allow the agent again. The bridge window only talks to SurfCAD pages (https://surfcad.com, www, and local dev). If Safari blocks the window, allow pop-ups for surfcad.com and click **Reconnect**. Safari on iPhone and iPad is not supported.
|
|
28
35
|
|
|
29
36
|
## MCP client config (Cursor / Claude Desktop)
|
|
30
37
|
|
|
@@ -44,13 +51,40 @@ The Vite dev/preview server starts the relay automatically. Nothing pairs silent
|
|
|
44
51
|
|
|
45
52
|
In Cursor, add the same block under **Settings → MCP** or your project `.cursor/mcp.json`.
|
|
46
53
|
|
|
54
|
+
## Tools
|
|
55
|
+
|
|
56
|
+
Every command in `data/commands.json` is one MCP tool with the same name and argument schema, plus `pair`. Call `list_commands` for the full catalog. The parts and git tools:
|
|
57
|
+
|
|
58
|
+
| Tool | Args | What it does |
|
|
59
|
+
| --- | --- | --- |
|
|
60
|
+
| `parts` | `{}` | Part rows (`id`, `name`, `visible`) and the active part. |
|
|
61
|
+
| `create_assembly` | `{}` | Seed a new assembly. |
|
|
62
|
+
| `create_part` | `{ name?, script?, position? }` | Add a part at the assembly origin (optional `[x,y,z]` mm). In a git assembly it has no vault path until `git_save`. |
|
|
63
|
+
| `rename_part` | `{ part_id, name }` | Rename a part. A vault part moves its committed `.js` to `<name>.js` in the same folder (`-2`, `-3` on collision) and updates that part's path/name in `.surf.json` in one commit. Pending script, placement, and other edits stay for the next Save. A part with no repo path renames locally and does not commit. Unknown ids return `unknown_part`. |
|
|
64
|
+
| `part_get_transform` | `{ part }` | Read placement: `position` mm and intrinsic XYZ Euler degrees (`eulerOrder: "XYZ"`). |
|
|
65
|
+
| `part_set_transform` | `{ part, position?, rotation? }` | Set placement (undoable assembly step). |
|
|
66
|
+
| `set_active_part` | `{ part_id }` | Switch the editor and mesh to a part. `status` then reports that part. |
|
|
67
|
+
| `git_save` | `{ message }` | Same as the app's Save: paths every path-less part, then commits those scripts, dirty parts, and the `.surf.json` in one commit. |
|
|
68
|
+
| `git_add_to_repo` | `{ part_id }` | Add one part to the vault; other path-less parts are pathed and committed with it. |
|
|
69
|
+
| `git_move_to_repo` | `{ vault_name? }` | Move a local assembly into the vault. |
|
|
70
|
+
| `git_list_branches` | `{}` | Branches and the current one (read-only). |
|
|
71
|
+
| `git_branch_create` | `{ name }` | Create and switch to a branch. |
|
|
72
|
+
| `git_branch_switch` | `{ branch, confirm? }` | Switch branch; `confirm: true` when the working copy is dirty. |
|
|
73
|
+
| `git_branch_delete` | `{ branch, confirm: true }` | Delete a branch. |
|
|
74
|
+
| `git_behind_resolve` | `{ action, path?, kind? }` | Get latest: `keep`, or `reload` / `branch` with `confirm: true`. |
|
|
75
|
+
| `git_force_overwrite` | `{ confirm: true }` | Overwrite main from the conflict prompt. |
|
|
76
|
+
|
|
47
77
|
## Safety and consent
|
|
48
78
|
|
|
49
79
|
- **Commerce:** Agents cannot place orders or drive checkout. Quote/cart/checkout controls are not exposed as MCP tools.
|
|
50
|
-
- **Git on real repos:**
|
|
80
|
+
- **Git on real repos:** The first write (`git_*` writes, or `rename_part` on a vault part) opens a consent dialog in SurfCAD and returns `consent_pending` right away. Nothing is written. Ask the user to click **Allow**, then retry the same call (`details.retry_after_ms` is a suggested wait). If the user denies, or the tab is headless automation, writes return `real_repo_blocked`.
|
|
51
81
|
- **Destructive git operations:** Need explicit approval; the bridge returns `confirm_required` unless args include `confirm: true` after the user has confirmed in SurfCAD.
|
|
52
82
|
|
|
53
|
-
Bridge refusals (`real_repo_blocked`, `confirm_required`, `not_paired`, user deny, etc.) are returned as structured JSON in MCP tool errors.
|
|
83
|
+
Bridge refusals (`consent_pending`, `real_repo_blocked`, `confirm_required`, `not_paired`, user deny, etc.) are returned as structured JSON in MCP tool errors.
|
|
84
|
+
|
|
85
|
+
## Connection drops
|
|
86
|
+
|
|
87
|
+
If the SurfCAD tab or the relay goes away mid-session, tool calls return `pairing_lost` right away (with a `hint`) instead of waiting for the MCP client timeout. The server keeps re-pairing in the background with the same code. The tab reconnects by itself, so calls start working again once SurfCAD is back in Chrome, with no new code and no reload. A call made while you still need to click Allow returns `pair_pending`. The relay pings every socket every 5 s (`SURFCAD_AGENT_BRIDGE_HEARTBEAT_MS`) and logs each drop on stderr with a timestamp and reason. Pairing codes are redacted in the log. Set `SURFCAD_AGENT_BRIDGE_WS_VERBOSE=1` to also log routine pairing events.
|
|
54
88
|
|
|
55
89
|
## Monorepo maintenance
|
|
56
90
|
|
|
@@ -65,7 +99,7 @@ The [`surfcad-mcp`](https://www.npmjs.com/package/surfcad-mcp) package is publis
|
|
|
65
99
|
Ways to release a new version:
|
|
66
100
|
|
|
67
101
|
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.
|
|
102
|
+
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.1` for `"version": "0.2.1"`).
|
|
69
103
|
3. **Manual** — In GitHub → Actions → **Publish surfcad-mcp** → **Run workflow** on branch `main`.
|
|
70
104
|
|
|
71
105
|
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.
|