surfcad-mcp 0.2.5 → 0.3.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 +14 -3
- package/data/commands.json +8365 -1647
- package/data/helpers.json +1765 -0
- package/package.json +1 -1
- package/src/helpers.mjs +209 -0
- package/src/prompt/buildGuidance.mjs +21 -0
- package/src/prompt/errorHints.mjs +288 -0
- package/src/prompt/guide.mjs +285 -0
- package/src/prompt/promptSession.mjs +94 -11
- package/src/prompt/promptTools.mjs +31 -3
- package/src/relay.mjs +9 -3
- package/src/server.mjs +107 -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.` and continue with a quick-start (under 2 KB) that points at the `guide` tool.
|
|
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,14 +61,20 @@ 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. 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
80
|
| `parts` | `{}` | Open assembly: `assemblyId`, `activeId`, and part rows (`id`, `name`, `visible`). No path field. |
|
|
@@ -76,6 +82,7 @@ Parts and assemblies are opaque surf ids. A vault path or display name is `unkno
|
|
|
76
82
|
| `create_assembly` | `{ name? }` | Seed a local assembly. Optional `name` is a label. No git write. |
|
|
77
83
|
| `create_part` | `{ name?, script?, position? }` | Add a part at the origin (optional `[x,y,z]` mm) and return its new id. 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. |
|
|
@@ -96,6 +103,10 @@ Parts and assemblies are opaque surf ids. A vault path or display name is `unkno
|
|
|
96
103
|
| `git_behind_resolve` | `{ action, confirm: true }` | `reload` is Get latest (no git write). `branch` saves mine to a new branch. No path argument. |
|
|
97
104
|
| `git_force_overwrite` | `{ confirm: true }` | Overwrite the overlapping remote files. |
|
|
98
105
|
|
|
106
|
+
### Geometry engine crashes
|
|
107
|
+
|
|
108
|
+
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.
|
|
109
|
+
|
|
99
110
|
## In-viewer prompts
|
|
100
111
|
|
|
101
112
|
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`.
|