surfcad-mcp 0.2.5 → 0.3.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 +24 -10
- package/data/commands.json +7877 -1089
- package/data/helpers.json +1765 -0
- package/package.json +1 -1
- package/src/bridge/relayHub.mjs +2 -1
- package/src/helpers.mjs +209 -0
- package/src/prompt/buildGuidance.mjs +27 -0
- package/src/prompt/errorHints.mjs +295 -0
- package/src/prompt/guide.mjs +289 -0
- package/src/prompt/promptSession.mjs +148 -16
- package/src/prompt/promptStall.mjs +6 -0
- package/src/prompt/promptTools.mjs +48 -9
- package/src/relay.mjs +22 -3
- package/src/relayMessages.mjs +2 -0
- package/src/server.mjs +115 -19
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ Environment variables:
|
|
|
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
28
|
4. Click **Allow** (the green check) in SurfCAD when prompted.
|
|
29
29
|
|
|
30
|
-
The MCP server instructions
|
|
30
|
+
The MCP server instructions start with `call register_webhook { url, bearer? } if you can receive https webhooks, otherwise poll read_messages.` The next sentence tells the agent: when you finish a task started from the SurfCAD in-viewer prompt pane, send a closing reply with `reply_to_user` (`final: true`) summarising what was done, so the user gets confirmation. On failure or partial completion, say what was done, what failed and why, and what is left. The instructions continue with a quick-start (under 2 KB) that points at the `guide` tool. `guide { topic: "start" }` repeats that closing-reply rule.
|
|
31
31
|
|
|
32
32
|
A successful `pair`, when no webhook is registered yet, returns an onboarding note as text content (a `type: "text"` block, not only `structuredContent` or `_meta`). The note asks the agent to request a webhook URL and key from the user. The key is the `bearer` argument. Suggested wording to relay: "To get SurfCAD messages instantly, send me your webhook URL and key. This only needs to be done once. Otherwise I'll check for SurfCAD messages between steps, so replies may lag." If the user declines, the agent polls `read_messages`. This process holds the URL and bearer in memory only, so the agent should save them in its own config or memory and call `register_webhook` again after every pair. If a webhook is already registered when `pair` succeeds, the result omits that note and says the webhook is active.
|
|
33
33
|
|
|
@@ -61,28 +61,36 @@ In Cursor, add the same block under **Settings → MCP** or your project `.curso
|
|
|
61
61
|
claude mcp add surfcad -- npx surfcad-mcp
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
-
A local CLI session usually has no public https endpoint, so polling `read_messages` is the normal path there. Webhooks apply when the user runs a receiver that can take https POSTs. The key they send is the `bearer` argument of `register_webhook`.
|
|
64
|
+
`read_messages { wait_ms }` (up to 25,000 ms) long-polls so an idle agent makes one call every 25 s instead of spinning. A local CLI session usually has no public https endpoint, so polling `read_messages` is the normal path there. Webhooks apply when the user runs a receiver that can take https POSTs. The key they send is the `bearer` argument of `register_webhook`.
|
|
65
|
+
|
|
66
|
+
## How to build
|
|
67
|
+
|
|
68
|
+
`guide { topic: "start" }` carries the build guidance in full (the `pair` result and the initialize instructions point at it; `guide {}` lists the other topics: `features`, `selection`, `paint`, `limits`, `camera`, `assembly`), and the `insert_*` / `set_script` / `create_*` tool descriptions carry a one-line note of it: block out every part of the assembly as plain blocks first (within seconds, then a screenshot for the user), then Build and Shape, then Polish, then pattern and place; features first, with a `set_script` snippet only for one operation no feature can do, starting with `// FEATURE-GAP: <missing feature or option> | <why the existing feature did not work>`; one part per unique fastener type, one instance patterned to every place it goes. Fix one base part with a fixed joint, then place every part that touches or attaches to another with joint_create (one call creates the joint and solves placement). Use part_set_transform only for parts that touch nothing. Block-out positions are rough; joints set final positions. The full text is in [docs/agent/SKILL.md](../../docs/agent/SKILL.md).
|
|
65
69
|
|
|
66
70
|
## Tools
|
|
67
71
|
|
|
68
|
-
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`.
|
|
72
|
+
Every command in `data/commands.json` is one MCP tool with the same name and argument schema, plus `pair`, `guide` (plain-text agent guidance by topic, no pairing needed; `dialect` is every script helper by signature; `errors.<code>` topics carry the recovery for an error code), `list_helpers` (the helper registry as JSON: `{ names?, group?, match?, page? }`, full doc and examples with `names`), and five in-process prompt tools. Every `insert_*` description ends with the code its block carries at default arguments. The guide topics are also MCP resources (`surfcad://guide/<topic>`, versioned with this package). Every error payload carries `hint` (the next call to make) and, where a topic exists, `see`. `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`.
|
|
69
73
|
|
|
70
74
|
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).
|
|
71
75
|
|
|
76
|
+
Results are compact JSON. Every tool whose result carries `status` (the model-changing tools, `undo`, `redo`, and `status`) takes `return: "status" | "summary" | "full"`; this server sends `"status"` when you leave it out, so `status.script` is omitted and a result stays small. `"summary"` adds `status.features` (the feature strip); `"full"` echoes the script. `get_script` reads the script, and `get_script { range: { fromFeature, toFeature } }` reads one span of feature blocks. The lists are filtered in the tab: `list_faces { filter: { kind, normalWithin: { n, deg }, minArea, maxArea, bbox }, page: { offset, limit } }`, `list_edges` / `list_feature_edges { filter: { between: [faceKeyA, faceKeyB], minLength, maxLength, bbox }, page }`; every list result carries `total` and `returned`. `list_commands { group }` returns one group of tools (`core`, `feature`, `insert`, `pick`, `sketch`, `document`, `joint`, `paint`, `measure`, `fea`, `sheet`, `git`, `export`, `view`, `agent`) instead of the whole 130 KB catalog, and `list_commands { names }` returns just those.
|
|
77
|
+
|
|
72
78
|
| Tool | Args | What it does |
|
|
73
79
|
| --- | --- | --- |
|
|
74
|
-
| `parts` | `{}` | Open assembly: `assemblyId`, `activeId`, and part rows (`id`, `name`, `visible`). No path field. |
|
|
80
|
+
| `parts` | `{}` | Open assembly: `assemblyId`, `activeId`, `unjointedParts` (ids in no joint when there are two or more parts; empty for one part), and part rows (`id`, `name`, `visible`). No path field. |
|
|
75
81
|
| `list_assemblies` | `{}` | Vault assemblies as `[{ id, name }]`. `id` is the key; `name` is a label. |
|
|
76
82
|
| `create_assembly` | `{ name? }` | Seed a local assembly. Optional `name` is a label. No git write. |
|
|
77
|
-
| `create_part` | `{ name?, script?, position? }` | Add a part
|
|
83
|
+
| `create_part` | `{ name?, script?, position? }` | Add a part and return its new id. `position` is a rough block-out `[x,y,z]` mm (default: the origin). In an assembly of two or more parts, a position on a part in no joint adds `warning` `unjointed_part` and the call still succeeds. Working copy only. |
|
|
78
84
|
| `set_script` | `{ part_id, source }` | Freehand fallback. `part_id` must be the active part. Working copy only. |
|
|
85
|
+
| `geometry_workers` | `{}` | Debug status of the geometry workers: the device cap, live and busy counts, crashes, the primary and the pool. Read-only. |
|
|
79
86
|
| `rename_part` | `{ part_id, name }` | Working-copy display name. `{ partId, name, moved: false }`. No git write. |
|
|
80
87
|
| `rename_assembly` | `{ assembly_id, name }` | Working-copy assembly label. Names may collide. No git write. |
|
|
81
88
|
| `part_get_transform` | `{ part_id }` | Read placement: `position` mm and intrinsic XYZ Euler degrees. |
|
|
82
|
-
| `part_set_transform` | `{ part_id, position?, rotation? }` | Set placement (undoable). Working copy only. |
|
|
89
|
+
| `part_set_transform` | `{ part_id, position?, rotation? }` | Set placement (undoable). Only for a part that touches nothing. In an assembly of two or more parts, a part in no joint adds `warning` `unjointed_part` and the call still succeeds. Working copy only. |
|
|
90
|
+
| `joint_create` | `{ type, picks }` | Default assembly placement. One call creates the joint and solves placement. Fix one base part with `type: "fixed"` and one pick, then mate every part that touches another. |
|
|
83
91
|
| `set_active_part` | `{ part_id }` | Switch the editor and mesh. `status` then reports that part. |
|
|
84
92
|
| `open_assembly` | `{ assembly_id }` | Open a vault assembly by id. A name or path is `unknown_assembly`. |
|
|
85
|
-
| `insert_part` | `{ part_id
|
|
93
|
+
| `insert_part` | `{ part_id?, assembly_id?, copy?, instance?, position? }` | Insert by reference (same ids). `copy: true` mints a new id. `instance: true` adds another placement; `position` is a rough block-out. A position on an unjointed row in a multi-part assembly adds `warning` `unjointed_part`. No git write. |
|
|
86
94
|
| `delete_part` | `{ part_id, scope, confirm? }` | `scope: "assembly"` drops the row. `scope: "repo"` also plans a file delete and requires `confirm: true`. Neither commits. |
|
|
87
95
|
| `delete_assembly` | `{ assembly_id, confirm: true, delete_parts? }` | Delete the open assembly. `confirm: true` required. Save commits later. |
|
|
88
96
|
| `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. |
|
|
@@ -96,6 +104,10 @@ Parts and assemblies are opaque surf ids. A vault path or display name is `unkno
|
|
|
96
104
|
| `git_behind_resolve` | `{ action, confirm: true }` | `reload` is Get latest (no git write). `branch` saves mine to a new branch. No path argument. |
|
|
97
105
|
| `git_force_overwrite` | `{ confirm: true }` | Overwrite the overlapping remote files. |
|
|
98
106
|
|
|
107
|
+
### Geometry engine crashes
|
|
108
|
+
|
|
109
|
+
A part can kill the geometry engine (out of memory, a wasm abort, or a run past its 30 s budget). The tab replaces the worker on its own and other parts keep building; nothing hangs and nobody reloads. The tool that ran the part returns `ok: false` with `crash { code: "geometry_worker_crashed", reason, workerRestarted: true }` and one `failures` row with the same code; `status.runState` is `failed`, `errors` holds the row, and `parts` rows carry `runState` and `crash` for every part. Do not retry the same script: simplify the part, lower segment counts, or split it up, then run it again.
|
|
110
|
+
|
|
99
111
|
## In-viewer prompts
|
|
100
112
|
|
|
101
113
|
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`.
|
|
@@ -104,12 +116,14 @@ These five tools stay inside the local `surfcad-mcp` process. They are not SurfC
|
|
|
104
116
|
| --- | --- | --- |
|
|
105
117
|
| `register_webhook` | `{ url, bearer? }` | Remember an https URL that receives each user prompt as `POST` JSON `{ "type": "surfcad.prompt", ... }`. Optional `bearer` is sent as `Authorization: Bearer <bearer>` (non-empty, at most 4096 characters, no CR or LF). Rejects `http`, credentials in the URL, localhost, `.local` names, and private or loopback addresses. The URL and bearer are held only in memory, are never logged, are never written to disk, are never returned or put in status, are never sent to the SurfCAD tab, and are cleared on `unregister_webhook` and when the pairing session ends. A cancel of a prompt that was already delivered is POSTed as `{ "type": "cancel", "id" }` with the same bearer and timeout. Stop work on that id. |
|
|
106
118
|
| `unregister_webhook` | `{}` | Drop that URL and bearer. Later prompts are queued. |
|
|
107
|
-
| `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. A cancel item `{ "type": "cancel", "id" }` means the user stopped a prompt you already received and no webhook is registered. Stop work on that id. |
|
|
108
|
-
| `reply_to_user` | `{ in_reply_to, text, final? }` | Plain-text reply for a prompt id. Several replies may share one id. `final: true`
|
|
109
|
-
| `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. A cancelled id returns `{ "ok": false, "error": "cancelled" }`. |
|
|
119
|
+
| `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. A cancel item `{ "type": "cancel", "id" }` means the user stopped a prompt you already received and no webhook is registered. Stop work on that id. When you finish the task from a prompt you received, close that chat with `reply_to_user`. |
|
|
120
|
+
| `reply_to_user` | `{ in_reply_to, text, final? }` | Plain-text reply for a prompt id. The final reply is expected and closes the task: when you finish a task started from the in-viewer prompt pane, send `reply_to_user` with `final: true` summarising what was done, so the user gets confirmation. On failure or partial completion, say what was done, what failed and why, and what is left. Several replies may share one id. `final: true` marks the agent idle. A cancelled id returns `{ "ok": false, "error": "cancelled" }` and is not shown in the tab. |
|
|
121
|
+
| `set_status` | `{ working, id? }` | Progress only. Tell the tab whether you are working. It does not close the task; a closing `reply_to_user` does. 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. A cancelled id returns `{ "ok": false, "error": "cancelled" }`. |
|
|
110
122
|
|
|
111
123
|
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). When `bearer` was set, that POST includes `Authorization: Bearer <bearer>`. 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 working state go back as `agent.reply` and `agent.status`.
|
|
112
124
|
|
|
125
|
+
When you finish a task started from the in-viewer prompt pane, send a closing reply with `reply_to_user` (`final: true`) summarising what was done, so the user gets confirmation. On failure or partial completion, say what was done, what failed and why, and what is left. `set_status` is for progress and does not close the task.
|
|
126
|
+
|
|
113
127
|
Stop in the prompt card sends `agent.prompt.cancel` (`v: 1`, the current prompt id) over the same paired connection. Each prompt is `queued`, `delivered` (webhook POST succeeded, or `read_messages` returned it), `replied` (a final reply), or `cancelled`. A prompt that is still queued is removed and is not returned by `read_messages`. A prompt that was already delivered is marked `cancelled`. If a webhook is registered, the process POSTs `{ "type": "cancel", "id" }` with the same bearer, https, and timeout rules; if that POST fails, or no webhook is registered, the next `read_messages` returns `{ "type": "cancel", "id" }`. Stop work on that id. `reply_to_user` and `set_status` for a cancelled id return `{ "ok": false, "error": "cancelled" }` and nothing is sent to the tab. The tab clears its working state. Cancelling a prompt that already has a final reply returns `already_final`. An unknown id returns `not_found`.
|
|
114
128
|
|
|
115
129
|
The bridge `status` tool returns the active part plus fields from this process: `webhookRegistered` (`true` or `false`; the URL is not included), `queued` (prompt messages waiting for `read_messages`; cancelled prompts are not counted), `counts` (`{ queued, delivered, replied, cancelled }`), and `last` (`{ id, state }` of the latest prompt, or `null`). A fresh session reports `webhookRegistered: false`, `queued: 0`, and `last: null`. After one prompt and no webhook, `queued` is `1` and `last.state` is `queued`. After Stop, `last.state` is `cancelled` and `queued` does not include that prompt.
|