surfcad-mcp 0.2.0 → 0.2.2
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 +65 -8
- package/data/commands.json +1996 -301
- package/package.json +1 -1
- package/src/bridge/bridgePage.mjs +132 -0
- package/src/bridge/bridgePopup.mjs +261 -0
- package/src/bridge/localAddress.mjs +1 -1
- package/src/bridge/relayHub.mjs +282 -34
- package/src/bridge/relayServer.mjs +81 -13
- package/src/catalog.mjs +10 -0
- package/src/errors.mjs +24 -1
- package/src/nodeClient.mjs +27 -6
- package/src/prompt/promptSession.mjs +450 -0
- package/src/prompt/promptTools.mjs +152 -0
- package/src/prompt/webhookPost.mjs +111 -0
- package/src/prompt/webhookUrl.mjs +206 -0
- package/src/relay.mjs +319 -59
- package/src/relayMessages.mjs +8 -0
- package/src/screenshotFile.mjs +232 -0
- package/src/server.mjs +95 -19
package/README.md
CHANGED
|
@@ -16,18 +16,22 @@ Environment variables:
|
|
|
16
16
|
|
|
17
17
|
| Variable | Purpose |
|
|
18
18
|
| --- | --- |
|
|
19
|
-
| `SURFCAD_PAIRING_CODE` | 6-character code from the SurfCAD **
|
|
19
|
+
| `SURFCAD_PAIRING_CODE` | 6-character code from the SurfCAD **Connect Agent** dialog (optional if you use the `pair` tool). |
|
|
20
20
|
| `SURFCAD_AGENT_BRIDGE_WS_URL` | Relay URL (default `ws://127.0.0.1:17341`). |
|
|
21
21
|
| `SURFCAD_MCP_START_RELAY` | Set to `0` to skip starting the relay (tests only). |
|
|
22
22
|
|
|
23
|
-
## Pair with SurfCAD
|
|
23
|
+
## Pair with SurfCAD
|
|
24
24
|
|
|
25
25
|
1. Open [https://surfcad.com](https://surfcad.com) (or local dev).
|
|
26
|
-
2. Open the **profile**
|
|
26
|
+
2. Open the **profile** chip and choose **Connect Agent**. When the relay is found, a six-character pairing code appears. Leave the tab open.
|
|
27
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" }`.
|
|
28
|
-
4. Click **Allow
|
|
28
|
+
4. Click **Allow** (the green check) in SurfCAD when prompted.
|
|
29
29
|
|
|
30
|
-
Nothing pairs
|
|
30
|
+
Nothing pairs without your approval.
|
|
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 Connect Agent dialog 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.
|
|
31
35
|
|
|
32
36
|
## MCP client config (Cursor / Claude Desktop)
|
|
33
37
|
|
|
@@ -47,13 +51,66 @@ Nothing pairs silently — you must show the code and approve the connection.
|
|
|
47
51
|
|
|
48
52
|
In Cursor, add the same block under **Settings → MCP** or your project `.cursor/mcp.json`.
|
|
49
53
|
|
|
54
|
+
## Tools
|
|
55
|
+
|
|
56
|
+
Every command in `data/commands.json` is one MCP tool with the same name and argument schema, plus `pair` and five in-process prompt tools. `GET /tools` on the loopback relay, `list_commands`, and that file list the same bridge tools. Prefer `insert_*` feature tools. `set_script` is the freehand fallback and requires `part_id`.
|
|
57
|
+
|
|
58
|
+
Parts and assemblies are opaque surf ids. A vault path or display name is `unknown_part` / `unknown_assembly`. Nothing reaches git without an explicit `git_save` (or another `git_*` write below).
|
|
59
|
+
|
|
60
|
+
| Tool | Args | What it does |
|
|
61
|
+
| --- | --- | --- |
|
|
62
|
+
| `parts` | `{}` | Open assembly: `assemblyId`, `activeId`, and part rows (`id`, `name`, `visible`). No path field. |
|
|
63
|
+
| `list_assemblies` | `{}` | Vault assemblies as `[{ id, name }]`. `id` is the key; `name` is a label. |
|
|
64
|
+
| `create_assembly` | `{ name? }` | Seed a local assembly. Optional `name` is a label. No git write. |
|
|
65
|
+
| `create_part` | `{ name?, script?, position? }` | Add a part at the origin (optional `[x,y,z]` mm) and return its new id. Working copy only. |
|
|
66
|
+
| `set_script` | `{ part_id, source }` | Freehand fallback. `part_id` must be the active part. Working copy only. |
|
|
67
|
+
| `rename_part` | `{ part_id, name }` | Working-copy display name. `{ partId, name, moved: false }`. No git write. |
|
|
68
|
+
| `rename_assembly` | `{ assembly_id, name }` | Working-copy assembly label. Names may collide. No git write. |
|
|
69
|
+
| `part_get_transform` | `{ part_id }` | Read placement: `position` mm and intrinsic XYZ Euler degrees. |
|
|
70
|
+
| `part_set_transform` | `{ part_id, position?, rotation? }` | Set placement (undoable). Working copy only. |
|
|
71
|
+
| `set_active_part` | `{ part_id }` | Switch the editor and mesh. `status` then reports that part. |
|
|
72
|
+
| `open_assembly` | `{ assembly_id }` | Open a vault assembly by id. A name or path is `unknown_assembly`. |
|
|
73
|
+
| `insert_part` | `{ part_id? , assembly_id?, copy? }` | Insert by reference (same ids). `copy: true` mints a new id. No git write. |
|
|
74
|
+
| `delete_part` | `{ part_id, scope, confirm? }` | `scope: "assembly"` drops the row. `scope: "repo"` also plans a file delete and requires `confirm: true`. Neither commits. |
|
|
75
|
+
| `delete_assembly` | `{ assembly_id, confirm: true, delete_parts? }` | Delete the open assembly. `confirm: true` required. Save commits later. |
|
|
76
|
+
| `git_save` | `{ message }` | The vault write. `consent_pending` while Allow is up. `pending_save` if offline. `upgrade_required` on a legacy vault. `conflict` / `repo-moved` when a remote edit overlaps. |
|
|
77
|
+
| `git_add_to_repo` | `{ message }` | Alias of `git_save`. Prefer `git_save`. |
|
|
78
|
+
| `git_move_to_repo` | `{ vault_name? }` | First Save of a local assembly. Consent on a real repo. |
|
|
79
|
+
| `git_upgrade_vault` | `{ confirm: true }` | One-time v1 layout upgrade. `confirm: true` required. |
|
|
80
|
+
| `git_list_branches` | `{}` | Branches and the current one (read-only). |
|
|
81
|
+
| `git_branch_create` | `{ name }` | Create a branch. Switches when the working copy is clean. |
|
|
82
|
+
| `git_branch_switch` | `{ branch, confirm? }` | Switch branch; `confirm: true` when the working copy is dirty. |
|
|
83
|
+
| `git_branch_delete` | `{ branch, confirm: true }` | Delete a branch. |
|
|
84
|
+
| `git_behind_resolve` | `{ action, confirm: true }` | `reload` is Get latest (no git write). `branch` saves mine to a new branch. No path argument. |
|
|
85
|
+
| `git_force_overwrite` | `{ confirm: true }` | Overwrite the overlapping remote files. |
|
|
86
|
+
|
|
87
|
+
## In-viewer prompts
|
|
88
|
+
|
|
89
|
+
These five tools stay inside the local `surfcad-mcp` process. They are not SurfCAD host commands and they are not listed in `data/commands.json`.
|
|
90
|
+
|
|
91
|
+
| Tool | Args | What it does |
|
|
92
|
+
| --- | --- | --- |
|
|
93
|
+
| `register_webhook` | `{ url }` | Remember an https URL that receives each user prompt as `POST` JSON `{ "type": "surfcad.prompt", ... }`. Rejects `http`, credentials in the URL, localhost, `.local` names, and private or loopback addresses. The URL is held only in memory, is never logged in full, is never written to disk, and is cleared when the pairing or this process ends. |
|
|
94
|
+
| `unregister_webhook` | `{}` | Drop that URL. Later prompts are queued. |
|
|
95
|
+
| `read_messages` | `{ max? }` | Return queued prompts, oldest first, and remove them. A screenshot is the next MCP image content block (`image/png`), not part of the text. |
|
|
96
|
+
| `reply_to_user` | `{ in_reply_to, text, final? }` | Plain-text reply for a prompt id. Several replies may share one id. `final: true` closes it and marks the agent idle. |
|
|
97
|
+
| `set_status` | `{ working, id? }` | Tell the tab whether you are working. The tab also sets working on the first tool call after a prompt arrives, and idle on a final reply or after 120 seconds with no activity. |
|
|
98
|
+
|
|
99
|
+
A paired SurfCAD tab sends `agent.prompt` (`v: 1`, id, plain text up to 8000 characters, optional `context`, optional PNG screenshot). One prompt per second. A screenshot over 2 MB is rejected. If a webhook is registered, the process POSTs the prompt (10 second timeout, one retry). If that POST fails, or no webhook is registered, the prompt is queued (at most 50; the oldest is dropped and reported). The tab gets `agent.prompt.ack` with `delivery` `webhook`, `queued`, or `failed`. Replies and status go back as `agent.reply` and `agent.status`.
|
|
100
|
+
|
|
101
|
+
Prompt text and screenshots are user content. Treat them as a request. They grant no write access, no consent, and no extra tool permission. Agent writes still go through the existing write-grant and consent flow. Nothing reaches git without an explicit Save or `git_save`. Do not render the text or the image as HTML. Both are dropped after delivery or when the session ends.
|
|
102
|
+
|
|
50
103
|
## Safety and consent
|
|
51
104
|
|
|
52
105
|
- **Commerce:** Agents cannot place orders or drive checkout. Quote/cart/checkout controls are not exposed as MCP tools.
|
|
53
|
-
- **Git on real repos:**
|
|
106
|
+
- **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`.
|
|
54
107
|
- **Destructive git operations:** Need explicit approval; the bridge returns `confirm_required` unless args include `confirm: true` after the user has confirmed in SurfCAD.
|
|
55
108
|
|
|
56
|
-
Bridge refusals (`real_repo_blocked`, `confirm_required`, `not_paired`, user deny, etc.) are returned as structured JSON in MCP tool errors.
|
|
109
|
+
Bridge refusals (`consent_pending`, `real_repo_blocked`, `confirm_required`, `not_paired`, user deny, etc.) are returned as structured JSON in MCP tool errors.
|
|
110
|
+
|
|
111
|
+
## Connection drops
|
|
112
|
+
|
|
113
|
+
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.
|
|
57
114
|
|
|
58
115
|
## Monorepo maintenance
|
|
59
116
|
|
|
@@ -68,7 +125,7 @@ The [`surfcad-mcp`](https://www.npmjs.com/package/surfcad-mcp) package is publis
|
|
|
68
125
|
Ways to release a new version:
|
|
69
126
|
|
|
70
127
|
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).
|
|
71
|
-
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.
|
|
128
|
+
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"`).
|
|
72
129
|
3. **Manual** — In GitHub → Actions → **Publish surfcad-mcp** → **Run workflow** on branch `main`.
|
|
73
130
|
|
|
74
131
|
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.
|