surfcad-mcp 0.3.1 → 0.3.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 +12 -9
- package/data/commands.json +101 -22
- package/package.json +1 -1
- package/src/listCommandsMerge.mjs +62 -0
- package/src/prompt/errorHints.mjs +4 -2
- package/src/prompt/guide.mjs +8 -8
- package/src/prompt/promptSession.mjs +77 -17
- package/src/prompt/promptStall.mjs +14 -2
- package/src/prompt/promptTools.mjs +19 -11
- package/src/relay.mjs +2 -1
- package/src/server.mjs +59 -23
package/README.md
CHANGED
|
@@ -69,11 +69,11 @@ claude mcp add surfcad -- npx surfcad-mcp
|
|
|
69
69
|
|
|
70
70
|
## Tools
|
|
71
71
|
|
|
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
|
|
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 and that file list the bridge tools. `list_commands` returns those plus every other tool this server registers (`pair`, `guide`, `list_helpers`, and the prompt tools, including `reply_to_user` and `set_status`), in the `agent` group. Prefer `insert_*` feature tools. `set_script` is the freehand fallback and requires `part_id`.
|
|
73
73
|
|
|
74
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).
|
|
75
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
|
|
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 catalog, and `list_commands { names }` returns just those. With no filter it includes the MCP-only tools as well as the bridge catalog.
|
|
77
77
|
|
|
78
78
|
| Tool | Args | What it does |
|
|
79
79
|
| --- | --- | --- |
|
|
@@ -87,12 +87,13 @@ Results are compact JSON. Every tool whose result carries `status` (the model-ch
|
|
|
87
87
|
| `rename_assembly` | `{ assembly_id, name }` | Working-copy assembly label. Names may collide. No git write. |
|
|
88
88
|
| `part_get_transform` | `{ part_id }` | Read placement: `position` mm and intrinsic XYZ Euler degrees. |
|
|
89
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. |
|
|
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. A `face_id` axis pick is never ambiguous; a real tie returns `details.candidates`. |
|
|
91
|
+
| `joint_delete` | `{ joint_id }` | Remove one joint. One assembly undo step. A part move that joint does not name stays. |
|
|
91
92
|
| `set_active_part` | `{ part_id }` | Switch the editor and mesh. `status` then reports that part. |
|
|
92
93
|
| `open_assembly` | `{ assembly_id }` | Open a vault assembly by id. A name or path is `unknown_assembly`. |
|
|
93
94
|
| `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. |
|
|
94
|
-
| `delete_part` | `{ part_id, scope, confirm? }` | `scope: "assembly"` drops the row. `scope: "repo"`
|
|
95
|
-
| `delete_assembly` | `{ assembly_id, confirm: true, delete_parts? }` | Delete
|
|
95
|
+
| `delete_part` | `{ part_id, scope, confirm? }` | `scope: "assembly"` drops the row and does not commit. `scope: "repo"` deletes `parts/<id>.js` in one commit after `confirm: true` and returns the assemblies that use the part. A failed scan is `delete_refused`. |
|
|
96
|
+
| `delete_assembly` | `{ assembly_id, confirm: true, delete_parts? }` | Delete that assembly whether it is open or not. `confirm: true` required. A committed assembly is one commit; a never-saved open assembly leaves the working copy only. |
|
|
96
97
|
| `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. |
|
|
97
98
|
| `git_add_to_repo` | `{ message }` | Alias of `git_save`. Prefer `git_save`. |
|
|
98
99
|
| `git_move_to_repo` | `{ vault_name? }` | First Save of a local assembly. Consent on a real repo. |
|
|
@@ -116,13 +117,15 @@ These five tools stay inside the local `surfcad-mcp` process. They are not SurfC
|
|
|
116
117
|
| --- | --- | --- |
|
|
117
118
|
| `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. |
|
|
118
119
|
| `unregister_webhook` | `{}` | Drop that URL and bearer. Later prompts are queued. |
|
|
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` | `{
|
|
120
|
+
| `read_messages` | `{ max?, wait_ms? }` | 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. Every response includes `recent`: the last 50 prompts this session received, oldest first, each `{ id, state }`, in memory only. `acked` is only the ids this call removed. A later `read_messages {}` with an empty queue still lists those ids, so you can recover one after the ack. `status.last` is only the newest. When you finish the task from a prompt you received, close that chat with `reply_to_user`. |
|
|
121
|
+
| `reply_to_user` | `{ in_reply_to, text, final? }` | Plain-text reply for a prompt id this session received. 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, including after `read_messages` has acked it. `final: true` marks the agent idle. An `in_reply_to` that was never delivered to this session is `unknown_prompt` and nothing is sent to the tab. A cancelled id returns `{ "ok": false, "error": "cancelled" }` and is not shown in the tab. |
|
|
122
|
+
| `set_status` | `{ state, label?, id? }` | Progress only. It does not close the task; a closing `reply_to_user` does. `state: "responding"` (alias `typing`) keeps the chat open with bouncing dots. `state: "building"` (alias `working`) means you are creating or editing geometry: the chat collapses and the field shows "Agent is working...". Call `building` only once you have everything you need and are actually modeling. Listing parts, faces, edges, or transforms, `status`, and `read_messages` must not use `building`. The legacy boolean `working: true` is `building`. A model-changing tool also enters building if you skip the call. Building stays until the final reply, Stop, or disconnect. No activity for 15 minutes, while responding or building, shows the stall notice and leaves Stop up. A cancelled id returns `{ "ok": false, "error": "cancelled" }`. |
|
|
122
123
|
|
|
123
124
|
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`.
|
|
124
125
|
|
|
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
|
+
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. Call `set_status { state: "building" }` only once you have everything you need and are actually creating or editing geometry. Reads stay on responding.
|
|
127
|
+
|
|
128
|
+
`reply_to_user` only accepts an `in_reply_to` that this session received (queued, delivered by webhook or `read_messages`, or already replied). Any other id is an error `unknown_prompt` and no `agent.reply` is sent. The page also drops a reply whose id is not a prompt the user sent, so it is not drawn in the chat. `read_messages` includes `recent`, the last 50 prompts in this session (`{ id, state }`, oldest first, memory only). That list stays after the ack, including when the queue is empty. `status.last` is only the newest id.
|
|
126
129
|
|
|
127
130
|
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`.
|
|
128
131
|
|
package/data/commands.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"version": 1,
|
|
3
3
|
"bridgeVersion": 1,
|
|
4
4
|
"generatedBy": "npm run export:agent",
|
|
5
|
-
"count":
|
|
5
|
+
"count": 197,
|
|
6
6
|
"$defs": {
|
|
7
7
|
"status": {
|
|
8
8
|
"type": "object",
|
|
@@ -1182,7 +1182,7 @@
|
|
|
1182
1182
|
},
|
|
1183
1183
|
{
|
|
1184
1184
|
"name": "undo",
|
|
1185
|
-
"description": "One undo on the feature-bar stack (sketch session, assembly joints, or active part script) and run when the part script changes. A part step returns the refreshed status, bodyCount included. Takes return: \"status\" | \"summary\" | \"full\" (MCP default \"status\": status.script is omitted; \"summary\" adds status.features; \"full\" echoes the script).",
|
|
1185
|
+
"description": "One undo on the feature-bar stack (sketch session, assembly joints, or active part script) and run when the part script changes. An assembly undo reverts one assembly action, so a joint undo leaves a part move that joint does not name. A part step returns the refreshed status, bodyCount included. Takes return: \"status\" | \"summary\" | \"full\" (MCP default \"status\": status.script is omitted; \"summary\" adds status.features; \"full\" echoes the script).",
|
|
1186
1186
|
"args": {
|
|
1187
1187
|
"type": "object",
|
|
1188
1188
|
"additionalProperties": false,
|
|
@@ -1970,7 +1970,7 @@
|
|
|
1970
1970
|
},
|
|
1971
1971
|
{
|
|
1972
1972
|
"name": "list_faces",
|
|
1973
|
-
"description": "Every pickable face on the active part, or on part_id when set (an opaque surf id, never a path or display name). One row per face a viewport click selects, all bodies: id (f0, f1, …), name (feature.role[k] from the helper that built the face: cube1.top, boss.side, extrude2.wall[3]; feature is the marked block id, else <helper>@<n>; absent on faces no helper stamped, such as a hull), feature, role, type (planar, cylindrical, curved), center, normal, axis and radius for cylinders, area, and key. frame is \"local\" on every result: center, normal, axis and key.at are the part's own frame, including when the part is placed, and they match select_faces. Compose with part_get_transform to reach the assembly. The id is the patch index on this mesh and is only valid until the next remesh; a rerun of the same script keeps every id. Pass the key with the id to joint_pick so a stale id cannot silently pick another face. The whole list on a detailed part is 100 KB or more, so filter it in the tab: filter { kind, normalWithin: { n, deg }, minArea, maxArea, bbox: { min, max }, name, feature, role } keeps only faces that match every given field (the top faces: kind \"planar\", normalWithin { n: [0, 0, 1], deg: 5 }; every face of one feature: feature \"boss\"; the tops of every feature: role \"top\"; name / feature / role take a glob with *),
|
|
1973
|
+
"description": "Every pickable face on the active part, or on part_id when set (an opaque surf id, never a path or display name). One row per face a viewport click selects, all bodies: id (f0, f1, …), name (feature.role[k] from the helper that built the face: cube1.top, boss.side, extrude2.wall[3]; feature is the marked block id, else <helper>@<n>; absent on faces no helper stamped, such as a hull), feature, role, type (planar, cylindrical, curved), center, normal, axis and radius for cylinders, area, and key. frame is \"local\" on every result: center, normal, axis and key.at are the part's own frame, including when the part is placed, and they match select_faces. Compose with part_get_transform to reach the assembly. The id is the patch index on this mesh and is only valid until the next remesh; a rerun of the same script keeps every id. Pass the key with the id to joint_pick so a stale id cannot silently pick another face. The whole list on a detailed part is 100 KB or more, so filter it in the tab: filter { kind, normalWithin: { n, deg }, minArea, maxArea, bbox: { min, max }, name, feature, role } keeps only faces that match every given field (the top faces: kind \"planar\", normalWithin { n: [0, 0, 1], deg: 5 }; every face of one feature: feature \"boss\"; the tops of every feature: role \"top\"; name / feature / role take a glob with *). bbox keeps a face whose triangle bounds overlap the box, so a large face is included when the box covers any part of it. page { offset, limit } returns one page; omitting page returns the first 100 faces (limit defaults to 100). The result always carries total (rows after the filter), returned, offset, and limit, and nextOffset when another page remains. Walk pages with { offset: nextOffset } until nextOffset is absent.",
|
|
1974
1974
|
"args": {
|
|
1975
1975
|
"type": "object",
|
|
1976
1976
|
"additionalProperties": false,
|
|
@@ -2043,24 +2043,24 @@
|
|
|
2043
2043
|
"maxItems": 3
|
|
2044
2044
|
}
|
|
2045
2045
|
},
|
|
2046
|
-
"description": "Faces whose
|
|
2046
|
+
"description": "Faces whose triangle bounds overlap this box (part local, mm). A large face is kept when the box covers any part of it, even if its center lies outside."
|
|
2047
2047
|
}
|
|
2048
2048
|
}
|
|
2049
2049
|
},
|
|
2050
2050
|
"page": {
|
|
2051
2051
|
"type": "object",
|
|
2052
2052
|
"additionalProperties": false,
|
|
2053
|
-
"description": "One page of rows. The result
|
|
2053
|
+
"description": "One page of rows. The result carries total (rows after the filter), returned, offset, and limit, and nextOffset when another page remains (pass it as the next offset). list_faces uses offset 0 and limit 100 when page or limit is omitted. Other lists return every remaining row when limit is omitted.",
|
|
2054
2054
|
"properties": {
|
|
2055
2055
|
"offset": {
|
|
2056
2056
|
"type": "integer",
|
|
2057
2057
|
"minimum": 0,
|
|
2058
|
-
"description": "Rows to skip
|
|
2058
|
+
"description": "Rows to skip. 0 starts at the first row. list_faces also accepts the previous result's nextOffset."
|
|
2059
2059
|
},
|
|
2060
2060
|
"limit": {
|
|
2061
2061
|
"type": "integer",
|
|
2062
2062
|
"minimum": 1,
|
|
2063
|
-
"description": "Rows to return
|
|
2063
|
+
"description": "Rows to return. list_faces defaults to 100. Other lists return every remaining row when this is omitted."
|
|
2064
2064
|
}
|
|
2065
2065
|
}
|
|
2066
2066
|
}
|
|
@@ -2233,17 +2233,17 @@
|
|
|
2233
2233
|
"page": {
|
|
2234
2234
|
"type": "object",
|
|
2235
2235
|
"additionalProperties": false,
|
|
2236
|
-
"description": "One page of rows. The result
|
|
2236
|
+
"description": "One page of rows. The result carries total (rows after the filter), returned, offset, and limit, and nextOffset when another page remains (pass it as the next offset). list_faces uses offset 0 and limit 100 when page or limit is omitted. Other lists return every remaining row when limit is omitted.",
|
|
2237
2237
|
"properties": {
|
|
2238
2238
|
"offset": {
|
|
2239
2239
|
"type": "integer",
|
|
2240
2240
|
"minimum": 0,
|
|
2241
|
-
"description": "Rows to skip
|
|
2241
|
+
"description": "Rows to skip. 0 starts at the first row. list_faces also accepts the previous result's nextOffset."
|
|
2242
2242
|
},
|
|
2243
2243
|
"limit": {
|
|
2244
2244
|
"type": "integer",
|
|
2245
2245
|
"minimum": 1,
|
|
2246
|
-
"description": "Rows to return
|
|
2246
|
+
"description": "Rows to return. list_faces defaults to 100. Other lists return every remaining row when this is omitted."
|
|
2247
2247
|
}
|
|
2248
2248
|
}
|
|
2249
2249
|
}
|
|
@@ -2364,17 +2364,17 @@
|
|
|
2364
2364
|
"page": {
|
|
2365
2365
|
"type": "object",
|
|
2366
2366
|
"additionalProperties": false,
|
|
2367
|
-
"description": "One page of rows. The result
|
|
2367
|
+
"description": "One page of rows. The result carries total (rows after the filter), returned, offset, and limit, and nextOffset when another page remains (pass it as the next offset). list_faces uses offset 0 and limit 100 when page or limit is omitted. Other lists return every remaining row when limit is omitted.",
|
|
2368
2368
|
"properties": {
|
|
2369
2369
|
"offset": {
|
|
2370
2370
|
"type": "integer",
|
|
2371
2371
|
"minimum": 0,
|
|
2372
|
-
"description": "Rows to skip
|
|
2372
|
+
"description": "Rows to skip. 0 starts at the first row. list_faces also accepts the previous result's nextOffset."
|
|
2373
2373
|
},
|
|
2374
2374
|
"limit": {
|
|
2375
2375
|
"type": "integer",
|
|
2376
2376
|
"minimum": 1,
|
|
2377
|
-
"description": "Rows to return
|
|
2377
|
+
"description": "Rows to return. list_faces defaults to 100. Other lists return every remaining row when this is omitted."
|
|
2378
2378
|
}
|
|
2379
2379
|
}
|
|
2380
2380
|
}
|
|
@@ -2870,17 +2870,35 @@
|
|
|
2870
2870
|
"type": "object",
|
|
2871
2871
|
"additionalProperties": false,
|
|
2872
2872
|
"properties": {
|
|
2873
|
+
"width": {
|
|
2874
|
+
"type": "number",
|
|
2875
|
+
"minimum": 0.1,
|
|
2876
|
+
"description": "X size in mm. Same axis as sx; width wins when both are set."
|
|
2877
|
+
},
|
|
2878
|
+
"depth": {
|
|
2879
|
+
"type": "number",
|
|
2880
|
+
"minimum": 0.1,
|
|
2881
|
+
"description": "Y size in mm. Same axis as sy; depth wins when both are set."
|
|
2882
|
+
},
|
|
2883
|
+
"height": {
|
|
2884
|
+
"type": "number",
|
|
2885
|
+
"minimum": 0.1,
|
|
2886
|
+
"description": "Z size in mm. Same axis as sz; height wins when both are set."
|
|
2887
|
+
},
|
|
2873
2888
|
"sx": {
|
|
2874
2889
|
"type": "number",
|
|
2875
|
-
"minimum": 0.1
|
|
2890
|
+
"minimum": 0.1,
|
|
2891
|
+
"description": "Size along X in mm. width is the same axis and wins when both are set."
|
|
2876
2892
|
},
|
|
2877
2893
|
"sy": {
|
|
2878
2894
|
"type": "number",
|
|
2879
|
-
"minimum": 0.1
|
|
2895
|
+
"minimum": 0.1,
|
|
2896
|
+
"description": "Size along Y in mm. depth is the same axis and wins when both are set."
|
|
2880
2897
|
},
|
|
2881
2898
|
"sz": {
|
|
2882
2899
|
"type": "number",
|
|
2883
|
-
"minimum": 0.1
|
|
2900
|
+
"minimum": 0.1,
|
|
2901
|
+
"description": "Size along Z in mm. height is the same axis and wins when both are set."
|
|
2884
2902
|
},
|
|
2885
2903
|
"edgeRadius": {
|
|
2886
2904
|
"type": "number",
|
|
@@ -5056,6 +5074,11 @@
|
|
|
5056
5074
|
"type": "boolean",
|
|
5057
5075
|
"description": "When true, place the hole on the selected planar or cylindrical face. Otherwise use the default +Z top face. A named pick (select_faces { names }, or a click on a face a helper built) is resolved by name in the script (facesNamed for a face, edgesOf for the edges around it) and is found again after every rebuild, so it can be used for several inserts. A pick with no name clears with the rebuild, and use_selection: true with nothing selected is refused with no_selection."
|
|
5058
5076
|
},
|
|
5077
|
+
"depth": {
|
|
5078
|
+
"type": "number",
|
|
5079
|
+
"minimum": 0.1,
|
|
5080
|
+
"description": "Blind depth in mm, into the part from the face. Omit for a through hole, which is the default."
|
|
5081
|
+
},
|
|
5059
5082
|
"body": {
|
|
5060
5083
|
"type": "string",
|
|
5061
5084
|
"description": "Part script binding name"
|
|
@@ -5830,6 +5853,11 @@
|
|
|
5830
5853
|
"type": "boolean",
|
|
5831
5854
|
"description": "When true, place the hole on the selected planar or cylindrical face. Otherwise use the default +Z top face. A named pick (select_faces { names }, or a click on a face a helper built) is resolved by name in the script (facesNamed for a face, edgesOf for the edges around it) and is found again after every rebuild, so it can be used for several inserts. A pick with no name clears with the rebuild, and use_selection: true with nothing selected is refused with no_selection."
|
|
5832
5855
|
},
|
|
5856
|
+
"depth": {
|
|
5857
|
+
"type": "number",
|
|
5858
|
+
"minimum": 0.1,
|
|
5859
|
+
"description": "Blind depth in mm, into the part from the face. Omit for a through hole, which is the default."
|
|
5860
|
+
},
|
|
5833
5861
|
"body": {
|
|
5834
5862
|
"type": "string",
|
|
5835
5863
|
"description": "Part script binding name"
|
|
@@ -18055,7 +18083,7 @@
|
|
|
18055
18083
|
},
|
|
18056
18084
|
{
|
|
18057
18085
|
"name": "delete_part",
|
|
18058
|
-
"description": "Drop a part by opaque part_id (a path or name is unknown_part). scope assembly removes the row. scope repo
|
|
18086
|
+
"description": "Drop a part by opaque part_id (a path or name is unknown_part). scope assembly removes the row and does not commit. scope repo, after confirm: true, deletes parts/<id>.js in one commit and returns the assemblies that use the part. A failed scan is delete_refused and writes nothing. Other assemblies are not rewritten. Takes return: \"status\" | \"summary\" | \"full\" (MCP default \"status\": status.script is omitted; \"summary\" adds status.features; \"full\" echoes the script).",
|
|
18059
18087
|
"args": {
|
|
18060
18088
|
"type": "object",
|
|
18061
18089
|
"additionalProperties": false,
|
|
@@ -18074,7 +18102,7 @@
|
|
|
18074
18102
|
"assembly",
|
|
18075
18103
|
"repo"
|
|
18076
18104
|
],
|
|
18077
|
-
"description": "assembly drops the row; repo
|
|
18105
|
+
"description": "assembly drops the row; repo deletes parts/<id>.js in one commit and returns the assemblies that use the part."
|
|
18078
18106
|
},
|
|
18079
18107
|
"confirm": {
|
|
18080
18108
|
"type": "boolean",
|
|
@@ -18099,7 +18127,9 @@
|
|
|
18099
18127
|
"bad_args",
|
|
18100
18128
|
"unknown_part",
|
|
18101
18129
|
"confirm_required",
|
|
18102
|
-
"
|
|
18130
|
+
"delete_refused",
|
|
18131
|
+
"conflict",
|
|
18132
|
+
"pending_save",
|
|
18103
18133
|
"no_assembly",
|
|
18104
18134
|
"internal"
|
|
18105
18135
|
],
|
|
@@ -18116,7 +18146,7 @@
|
|
|
18116
18146
|
},
|
|
18117
18147
|
{
|
|
18118
18148
|
"name": "delete_assembly",
|
|
18119
|
-
"description": "Delete
|
|
18149
|
+
"description": "Delete an assembly by opaque assembly_id, whether it is open or not. Requires confirm: true. One commit deletes assemblies/<id>.surf.json. delete_parts also deletes parts/<id>.js when no other assembly references that id. A never-saved open assembly is removed from the working copy only. Returns the assemblies that use its parts. Nothing is written until confirm: true. Takes return: \"status\" | \"summary\" | \"full\" (MCP default \"status\": status.script is omitted; \"summary\" adds status.features; \"full\" echoes the script).",
|
|
18120
18150
|
"args": {
|
|
18121
18151
|
"type": "object",
|
|
18122
18152
|
"additionalProperties": false,
|
|
@@ -18134,7 +18164,7 @@
|
|
|
18134
18164
|
},
|
|
18135
18165
|
"delete_parts": {
|
|
18136
18166
|
"type": "boolean",
|
|
18137
|
-
"description": "When true,
|
|
18167
|
+
"description": "When true, the commit also deletes part files no other assembly references."
|
|
18138
18168
|
},
|
|
18139
18169
|
"return": {
|
|
18140
18170
|
"type": "string",
|
|
@@ -18155,6 +18185,9 @@
|
|
|
18155
18185
|
"bad_args",
|
|
18156
18186
|
"unknown_assembly",
|
|
18157
18187
|
"confirm_required",
|
|
18188
|
+
"conflict",
|
|
18189
|
+
"pending_save",
|
|
18190
|
+
"delete_refused",
|
|
18158
18191
|
"upgrade_required",
|
|
18159
18192
|
"no_assembly",
|
|
18160
18193
|
"internal"
|
|
@@ -18601,7 +18634,7 @@
|
|
|
18601
18634
|
},
|
|
18602
18635
|
{
|
|
18603
18636
|
"name": "joint_create",
|
|
18604
|
-
"description": "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. Prefer this over hand-computed part_set_transform numbers: one call creates a joint and solves the placement. type is coincident, parallel, perpendicular, distance, angle, concentric, symmetric or fixed (planar is coincident); picks are one row per reference from list_faces (face_id with its key from the same row; a cylindrical face is an axis pick; { part_id } alone is a whole-part pick), one pick for fixed and two for every other type; name, value_mm, sense and opposed as on joint_set_params. Runs the same open → pick → set params → commit path as the Joints card (the advanced path) and records one assembly undo step. The result carries jointId, type, name, valueMm, pickCount and placements: the position and rotation of every picked part after the solve. A pick that does not resolve is unknown_part / unknown_face, and a joint the solver refuses is joint_unsolvable with details.reason; in both cases nothing is written and no card is left open. usedSelection is always false: the picks are explicit. Takes return: \"status\" | \"summary\" | \"full\" (MCP default \"status\": status.script is omitted; \"summary\" adds status.features; \"full\" echoes the script).",
|
|
18637
|
+
"description": "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. Prefer this over hand-computed part_set_transform numbers: one call creates a joint and solves the placement. type is coincident, parallel, perpendicular, distance, angle, concentric, symmetric or fixed (planar is coincident); picks are one row per reference from list_faces (face_id with its key from the same row; a cylindrical face is an axis pick; a face_id is never an ambiguous axis; { part_id } alone is a whole-part pick), one pick for fixed and two for every other type; name, value_mm, sense and opposed as on joint_set_params. Runs the same open → pick → set params → commit path as the Joints card (the advanced path) and records one assembly undo step. The result carries jointId, type, name, valueMm, pickCount and placements: the position and rotation of every picked part after the solve. A pick that does not resolve is unknown_part / unknown_face, and a joint the solver refuses is joint_unsolvable with details.reason and, when more than one axis matches, details.candidates (id, origin, direction, radius); in both cases nothing is written and no card is left open. usedSelection is always false: the picks are explicit. Takes return: \"status\" | \"summary\" | \"full\" (MCP default \"status\": status.script is omitted; \"summary\" adds status.features; \"full\" echoes the script).",
|
|
18605
18638
|
"args": {
|
|
18606
18639
|
"type": "object",
|
|
18607
18640
|
"additionalProperties": false,
|
|
@@ -18782,6 +18815,52 @@
|
|
|
18782
18815
|
]
|
|
18783
18816
|
}
|
|
18784
18817
|
},
|
|
18818
|
+
{
|
|
18819
|
+
"name": "joint_delete",
|
|
18820
|
+
"description": "Delete one joint by joint_id (the Joints card Delete button) and record one assembly undo step. Remaining joints are solved again. A part move that this joint does not name stays. Undo restores the joint. Takes return: \"status\" | \"summary\" | \"full\" (MCP default \"status\": status.script is omitted; \"summary\" adds status.features; \"full\" echoes the script).",
|
|
18821
|
+
"args": {
|
|
18822
|
+
"type": "object",
|
|
18823
|
+
"additionalProperties": false,
|
|
18824
|
+
"required": [
|
|
18825
|
+
"joint_id"
|
|
18826
|
+
],
|
|
18827
|
+
"properties": {
|
|
18828
|
+
"joint_id": {
|
|
18829
|
+
"type": "string",
|
|
18830
|
+
"description": "Joint id from a joint_create or joint_commit result"
|
|
18831
|
+
},
|
|
18832
|
+
"return": {
|
|
18833
|
+
"type": "string",
|
|
18834
|
+
"enum": [
|
|
18835
|
+
"status",
|
|
18836
|
+
"summary",
|
|
18837
|
+
"full"
|
|
18838
|
+
],
|
|
18839
|
+
"description": "How much of status to return: \"status\" drops status.script, \"summary\" drops it and adds status.features (the feature strip), \"full\" keeps the whole script. Over MCP the default is \"status\"; in the page it is \"full\". Read the script with get_script."
|
|
18840
|
+
}
|
|
18841
|
+
}
|
|
18842
|
+
},
|
|
18843
|
+
"result": {
|
|
18844
|
+
"type": "object",
|
|
18845
|
+
"additionalProperties": true
|
|
18846
|
+
},
|
|
18847
|
+
"errors": [
|
|
18848
|
+
"bad_args",
|
|
18849
|
+
"no_assembly",
|
|
18850
|
+
"unknown_joint",
|
|
18851
|
+
"edit_failed",
|
|
18852
|
+
"internal"
|
|
18853
|
+
],
|
|
18854
|
+
"mutates": true,
|
|
18855
|
+
"destructive": true,
|
|
18856
|
+
"confirm": false,
|
|
18857
|
+
"group": "joint",
|
|
18858
|
+
"immediate": false,
|
|
18859
|
+
"uiEntry": "data-joint-card",
|
|
18860
|
+
"example": {
|
|
18861
|
+
"joint_id": "j1"
|
|
18862
|
+
}
|
|
18863
|
+
},
|
|
18785
18864
|
{
|
|
18786
18865
|
"name": "sheet_open",
|
|
18787
18866
|
"description": "Open the Sheet Metal picker (Shape rail).",
|
package/package.json
CHANGED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP-only tools (pair, guide, list_helpers, the prompt tools) are not
|
|
3
|
+
* bridge commands, so the tab's list_commands omits them. Fold the server's
|
|
4
|
+
* registered tool list into that result so an agent that asks list_commands
|
|
5
|
+
* sees every tool this process actually registers.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** Group on the tab's list_commands rows. Prompt and other MCP-only tools sit with the in-viewer prompt. */
|
|
9
|
+
export const MCP_ONLY_GROUP = 'agent';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {{ name: string, description?: string, inputSchema?: object }} tool
|
|
13
|
+
*/
|
|
14
|
+
export function mcpOnlyCommandRow(tool) {
|
|
15
|
+
const schema = tool.inputSchema && typeof tool.inputSchema === 'object'
|
|
16
|
+
? tool.inputSchema
|
|
17
|
+
: { type: 'object', additionalProperties: false, properties: {} };
|
|
18
|
+
return {
|
|
19
|
+
name: tool.name,
|
|
20
|
+
description: typeof tool.description === 'string' ? tool.description : '',
|
|
21
|
+
schema,
|
|
22
|
+
example: {},
|
|
23
|
+
group: MCP_ONLY_GROUP,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {object} pageResult The tab's list_commands result.
|
|
29
|
+
* @param {{ registered: Array<{ name: string, description?: string, inputSchema?: object }>, bridgeNames: Set<string>, args?: { names?: unknown, group?: unknown } }} opts
|
|
30
|
+
*/
|
|
31
|
+
export function mergeRegisteredIntoListCommands(pageResult, opts) {
|
|
32
|
+
if (!pageResult || typeof pageResult !== 'object' || Array.isArray(pageResult) || !Array.isArray(pageResult.commands)) {
|
|
33
|
+
return pageResult;
|
|
34
|
+
}
|
|
35
|
+
const bridgeNames = opts.bridgeNames instanceof Set ? opts.bridgeNames : new Set();
|
|
36
|
+
const extras = (opts.registered || [])
|
|
37
|
+
.filter((tool) => tool && typeof tool.name === 'string' && !bridgeNames.has(tool.name))
|
|
38
|
+
.map(mcpOnlyCommandRow);
|
|
39
|
+
const args = opts.args && typeof opts.args === 'object' ? opts.args : {};
|
|
40
|
+
const wanted = Array.isArray(args.names) ? new Set(args.names.filter((name) => typeof name === 'string')) : null;
|
|
41
|
+
const group = typeof args.group === 'string' && args.group !== 'all' ? args.group : null;
|
|
42
|
+
let add = extras;
|
|
43
|
+
if (wanted) add = add.filter((row) => wanted.has(row.name));
|
|
44
|
+
if (group) add = add.filter((row) => row.group === group);
|
|
45
|
+
|
|
46
|
+
const commands = pageResult.commands.slice();
|
|
47
|
+
const have = new Set(commands.map((row) => row?.name));
|
|
48
|
+
for (const row of add) {
|
|
49
|
+
if (!have.has(row.name)) commands.push(row);
|
|
50
|
+
}
|
|
51
|
+
const groups = { ...(pageResult.groups && typeof pageResult.groups === 'object' ? pageResult.groups : {}) };
|
|
52
|
+
for (const row of extras) groups[row.group] = (groups[row.group] || 0) + 1;
|
|
53
|
+
const total = (typeof pageResult.total === 'number' ? pageResult.total : pageResult.commands.length) + extras.length;
|
|
54
|
+
const result = { ...pageResult, commands, total, groups };
|
|
55
|
+
if (Array.isArray(pageResult.missing)) {
|
|
56
|
+
const found = new Set(add.map((row) => row.name));
|
|
57
|
+
const missing = pageResult.missing.filter((name) => !found.has(name));
|
|
58
|
+
if (missing.length) result.missing = missing;
|
|
59
|
+
else delete result.missing;
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
@@ -102,7 +102,7 @@ export const ERROR_HINTS = Object.freeze({
|
|
|
102
102
|
unknown_part: { hint: 'Not an open part id (paths and names are never ids): parts {} and pass a row\'s id.' },
|
|
103
103
|
unknown_assembly: { hint: 'Not a saved assembly id: list_assemblies {} and pass a row\'s id.' },
|
|
104
104
|
no_assembly: { hint: 'No document is open: create_assembly {} or open_assembly { assembly_id } first.' },
|
|
105
|
-
unknown_joint: { hint: 'The joint id is not in this assembly: joint_edit
|
|
105
|
+
unknown_joint: { hint: 'The joint id is not in this assembly: joint_edit and joint_delete take an id from a joint_create or joint_commit result; joint_open {} starts a new one.' },
|
|
106
106
|
unjointed_part: {
|
|
107
107
|
hint: 'Place it with joint_create (one call creates the joint and solves placement). Fix a base part with type fixed first.',
|
|
108
108
|
guide: 'A part that touches or attaches to another part belongs in a joint. joint_create { type, picks } writes the joint and solves the placement in one call. Ground the base with type fixed and one whole-part pick { part_id }, then mate each touching part with two picks from list_faces (coincident, concentric, distance, and the other types). part_set_transform is only for a part that touches nothing. The warning does not block the call: the placement was written. A single-part document does not warn, and neither does the base part once it has a fixed joint. parts and status list the ids still in no joint as unjointedParts. Bodies, patterns, and insert_move inside one part are not assembly parts and do not warn.',
|
|
@@ -110,8 +110,9 @@ export const ERROR_HINTS = Object.freeze({
|
|
|
110
110
|
no_joint_card: { hint: 'The joint card is closed: joint_open {} first, then joint_pick / joint_set_params / joint_commit.' },
|
|
111
111
|
no_joint_edit: { hint: 'No joint is open for editing: joint_open {} for a new joint or joint_edit { joint_id } for an existing one.' },
|
|
112
112
|
joints_unavailable: { hint: 'The joint card could not open because another card or session is open: close it (cancel_feature, sketch_cancel, sheet_exit) and call joint_create again.' },
|
|
113
|
-
joint_unsolvable: { hint: 'The solver refused that joint (details.reason is its message
|
|
113
|
+
joint_unsolvable: { hint: 'The solver refused that joint (details.reason is its message; details.candidates lists id, origin, direction and radius when more than one axis matches): pass face_id from list_faces, or pick one of those candidates. Concentric needs two cylindrical faces. Nothing was written.' },
|
|
114
114
|
part_still_referenced: { hint: 'Another assembly lists this part: delete it with scope: "assembly", or delete those parents first.' },
|
|
115
|
+
delete_refused: { hint: 'The delete was refused and nothing was written: tell the user the message and do not retry until they ask again.' },
|
|
115
116
|
origin_blocked: { hint: 'This change would move the assembly origin: place the part with part_set_transform instead.' },
|
|
116
117
|
off_study_part: { hint: 'The FEA study belongs to another part: set_active_part to the study\'s part (fea_state {} names it) and retry.' },
|
|
117
118
|
no_fea: { hint: 'No FEA study is open: fea_open {} (or the study tool the description names) first.' },
|
|
@@ -169,6 +170,7 @@ export const ERROR_HINTS = Object.freeze({
|
|
|
169
170
|
bridge_error: { hint: 'The tab refused the call without a code: status {} and retry once; tell the user if it repeats.' },
|
|
170
171
|
bad_webhook_url: { hint: 'Webhooks need a public https URL (no credentials, localhost or private hosts): fix it, or poll read_messages { wait_ms: 25000 } instead.', guide: PAIRING_GUIDE },
|
|
171
172
|
no_request: { hint: 'in_reply_to is not an open prompt id: read_messages {} lists the queued prompts.' },
|
|
173
|
+
unknown_prompt: { hint: 'in_reply_to is not a prompt this session received: call read_messages {} and use an id from recent, or the id on the prompt you were given.' },
|
|
172
174
|
reply_too_long: { hint: 'Shorten the reply (message gives the limit) or send it in several reply_to_user calls with final on the last.' },
|
|
173
175
|
});
|
|
174
176
|
|
package/src/prompt/guide.mjs
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* topic under 1,500 words.
|
|
13
13
|
*/
|
|
14
14
|
import { BUILD_GUIDANCE, JOINT_PLACEMENT_GUIDANCE } from './buildGuidance.mjs';
|
|
15
|
-
import { CLOSING_REPLY_GUIDANCE, PROMPT_SERVER_INSTRUCTIONS } from './promptTools.mjs';
|
|
15
|
+
import { BUILDING_STATUS_GUIDANCE, CLOSING_REPLY_GUIDANCE, PROMPT_SERVER_INSTRUCTIONS } from './promptTools.mjs';
|
|
16
16
|
import {
|
|
17
17
|
ERROR_TOPIC_CODES,
|
|
18
18
|
ERROR_TOPIC_PREFIX,
|
|
@@ -41,7 +41,7 @@ Reading results: every model-changing tool answers { ok, errors, status } with r
|
|
|
41
41
|
Ids are opaque surf ids from parts, list_assemblies, create_part, create_assembly; never a path or a display name.
|
|
42
42
|
Topics: guide { topic: "dialect" | "features" | "selection" | "paint" | "limits" | "camera" | "assembly" }; list_helpers { names } documents any script helper.
|
|
43
43
|
|
|
44
|
-
In-viewer prompt pane. ${CLOSING_REPLY_GUIDANCE} set_status is for progress and does not close the task.`;
|
|
44
|
+
In-viewer prompt pane. ${CLOSING_REPLY_GUIDANCE} set_status is for progress and does not close the task. ${BUILDING_STATUS_GUIDANCE} state "responding" (alias typing) is the bouncing dots after the user sends. Listing parts, faces, edges, or transforms, status, and read_messages never start building. Building stays until the closing reply. reply_to_user takes an in_reply_to that this session actually received; any other id is unknown_prompt and is not shown in the chat. After read_messages acks a prompt, that id stays in the response's recent list (the last 50 prompts in this session, oldest first, each { id, state }), including on a later empty read_messages {}.`;
|
|
45
45
|
|
|
46
46
|
const FEATURES = `Feature blocks. The script of a part is plain JavaScript over the SurfCAD helpers, and the feature strip reads it from marker comments. Every insert_* writes one block:
|
|
47
47
|
|
|
@@ -59,7 +59,7 @@ What the markers buy you:
|
|
|
59
59
|
- feature_tree {} lists the blocks; open_feature { id | index } opens that block's card, edit_feature { params } merges fields (keys depend on the kind: height, radius, distance; for a move dx, dy, dz, at), confirm_feature {} writes and runs. A confirm that changes nothing on a failing part answers ok: false with the errors.
|
|
60
60
|
- delete_feature { id | index, part_id? } removes the block from the active part and runs it; one undo restores it. A face pick does not retarget it. part_id (an opaque surf id) deletes from that part instead; a path or name is unknown_part. Deleting the block that declares part while later blocks use it is confirm_required (details.dependents) until the user agrees and you pass confirm: true.
|
|
61
61
|
- rollback_to { id | index } moves the rollback bar and re-evaluates up to there without editing the script; rollback_to { clear: true } removes it.
|
|
62
|
-
- undo / redo step the feature-bar stack (sketch session, assembly joints, or the active part) and return applied / reverted labels; a new committed edit clears redo.
|
|
62
|
+
- undo / redo step the feature-bar stack (sketch session, assembly joints, or the active part) and return applied / reverted labels; a new committed edit clears redo. On the assembly stack one undo is one action: undoing a joint leaves a part_set_transform of a part that joint does not name, and the next undo reverts that move. A move of a part the joint names is part of the joint step.
|
|
63
63
|
- get_script { range: { fromFeature: "cube1", toFeature: "fillet2" } } reads one span of blocks.
|
|
64
64
|
|
|
65
65
|
Script snippet feature. When no insert_* can do an operation, insert_code_snippet { gap, why, script } adds one block (its first line is // FEATURE-GAP: <missing feature or option> | <why the existing feature did not work>); script reads and sets part. Use set_script { part_id, source } only to rewrite a whole part; part_id must be the active part. Never redeclare a reserved helper name (cut, hole, shell, filletEdges, convexEdges, ...; the set_script description lists them): rename your variable.
|
|
@@ -68,7 +68,7 @@ Sketch sessions. sketch_begin → sketch_add { tool, ... } / pick_points { kind,
|
|
|
68
68
|
|
|
69
69
|
const SELECTION = `Selection. Faces and edges are addressed by keys that survive a rerun of the same script and are invalid after a remesh.
|
|
70
70
|
|
|
71
|
-
Faces. list_faces { part_id?, filter?, page? } returns one row per face a viewport click selects, all bodies: id (f0, f1, ...), type (planar | cylindrical | curved), center, normal, axis and radius for cylinders, area, and key { at, n, area, src?, ord? } (the same fingerprint the viewport uses). frame is "local": center, normal, axis and key.at are the part's own coordinates, including on a placed part, and they match select_faces. Compose with part_get_transform when another part does not share that frame. The whole list on a detailed part is 100 KB or more: filter it in the tab. filter { kind, normalWithin: { n, deg }, minArea, maxArea, bbox: { min, max } } keeps the rows that match every given field
|
|
71
|
+
Faces. list_faces { part_id?, filter?, page? } returns one row per face a viewport click selects, all bodies: id (f0, f1, ...), type (planar | cylindrical | curved), center, normal, axis and radius for cylinders, area, and key { at, n, area, src?, ord? } (the same fingerprint the viewport uses). frame is "local": center, normal, axis and key.at are the part's own coordinates, including on a placed part, and they match select_faces. Compose with part_get_transform when another part does not share that frame. The whole list on a detailed part is 100 KB or more: filter it in the tab. filter { kind, normalWithin: { n, deg }, minArea, maxArea, bbox: { min, max } } keeps the rows that match every given field. bbox keeps a face whose bounds overlap the box, including a large face whose center is outside it. page { offset, limit } returns one slice; omitting page returns the first 100 faces. The result carries total (after the filter), returned, offset, limit, and nextOffset when another page remains (pass offset: nextOffset). The top faces: { kind: "planar", normalWithin: { n: [0, 0, 1], deg: 5 } }. Hole walls: { kind: "cylindrical", maxArea }. Pass face_id together with its key to joint_pick so a stale id answers unknown_face instead of picking another face.
|
|
72
72
|
|
|
73
73
|
Edges. list_feature_edges gives grouped ids e0, e1, ... (a whole edge chain, the stable choice); list_edges gives raw mesh edges. Both set frame to "local" (midpoints in the same part frame as list_faces) and take filter { between: [faceKeyA, faceKeyB], minLength, maxLength, bbox } and page.
|
|
74
74
|
|
|
@@ -96,7 +96,7 @@ What is expensive: filletEdges / chamferEdges over many edges (a face pick on a
|
|
|
96
96
|
|
|
97
97
|
After a timeout. undo waits for the replaced worker, re-runs the restored script and reports that run (with return: "full", status.script is the restored script). If the run still did not report, status.stale: true says the numbers are the previous run's: call run {} again and read status. A status without stale is current.
|
|
98
98
|
|
|
99
|
-
Result sizes. Over MCP every model-changing tool defaults to return: "status" (no script echo). "summary" adds status.features, "full" echoes the script. Read scripts with get_script, one span with get_script { range }. list_commands { group } returns one tool group (core, feature, insert, pick, sketch, document, joint, paint, measure, fea, sheet, git, export, view, agent); list_commands { names } just those rows; no args is the
|
|
99
|
+
Result sizes. Over MCP every model-changing tool defaults to return: "status" (no script echo). "summary" adds status.features, "full" echoes the script. Read scripts with get_script, one span with get_script { range }. list_commands { group } returns one tool group (core, feature, insert, pick, sketch, document, joint, paint, measure, fea, sheet, git, export, view, agent); list_commands { names } just those rows; no args is the bridge catalog plus every MCP-only tool this server registers (pair, guide, list_helpers, reply_to_user, set_status, and the other prompt tools) in the agent group.
|
|
100
100
|
|
|
101
101
|
Pairing. A bridge call before pair is not_paired. pair returns pair_pending while the user has not clicked Allow. pairing_lost means the tab or relay dropped and the server re-pairs on its own: retry in a few seconds, do not ask for a new code. Numbers are finite and within ±1,000,000 mm; NaN and Infinity are bad_args.`;
|
|
102
102
|
|
|
@@ -112,7 +112,7 @@ const ASSEMBLY = `Assemblies, placement and joints.
|
|
|
112
112
|
|
|
113
113
|
Documents. create_assembly { name? } seeds an empty assembly with one empty part (no seed cube; single-flight per tab; no git write). open_assembly { assembly_id } opens a saved one; list_assemblies {} returns [{ id, name, open }]. parts {} returns assemblyId, activeId, unjointedParts and every part row with runState and crash, so a failed part that is not active is visible without switching. status carries the same unjointedParts list. unjointedParts is empty for a single-part document; a base part with a fixed joint is omitted.
|
|
114
114
|
|
|
115
|
-
Parts. create_part { name?, script?, position? } adds a part, makes it active and returns its new opaque id. Agent-created parts land at the assembly origin unless position [x, y, z] mm is given (a rough block-out; joint_create sets the final pose of a part that touches another); parts created from the UI stagger along +X. The part starts empty; the first insert_* creates the body. Feature tools write the active part, so set_active_part { part_id } before inserting. rename_part changes the label only; delete_part { part_id, scope: "assembly" | "repo" } drops the row (repo
|
|
115
|
+
Parts. create_part { name?, script?, position? } adds a part, makes it active and returns its new opaque id. Agent-created parts land at the assembly origin unless position [x, y, z] mm is given (a rough block-out; joint_create sets the final pose of a part that touches another); parts created from the UI stagger along +X. The part starts empty; the first insert_* creates the body. Feature tools write the active part, so set_active_part { part_id } before inserting. rename_part changes the label only; delete_part { part_id, scope: "assembly" | "repo", confirm? } drops the row (repo deletes parts/<id>.js in one commit, needs confirm: true, and returns the other assemblies that use it).
|
|
116
116
|
|
|
117
117
|
Reuse. insert_part { part_id } or { assembly_id } inserts by reference (the same id; one definition shared across assemblies). copy: true mints a new id and sets copiedFrom. open_part { part_id } opens a vault part into the document.
|
|
118
118
|
|
|
@@ -120,7 +120,7 @@ Instances. insert_part { part_id, instance: true, position? } adds another place
|
|
|
120
120
|
|
|
121
121
|
Placement. ${JOINT_PLACEMENT_GUIDANCE} part_get_transform { part_id } reads a rigid placement: translation in mm, rotation as intrinsic XYZ Euler degrees. A placed part's features, previews and picks are in its own frame. list_faces, list_edges and list_feature_edges set frame to "local" (centers and edge midpoints are part-local, not world); compose them with part_get_transform when another part does not share that frame. part_set_transform { part_id, position?, rotation? } writes that placement in one assembly undo step and is only for a part that touches nothing. create_part and insert_part { position } are a rough block-out. In an assembly of two or more parts, part_set_transform, or create_part / insert_part with a position, returns warning { code: "unjointed_part", part_id, hint } when that part is in no joint. The call still succeeds. A single-part document does not warn, and neither does the base part once it has a fixed joint.
|
|
122
122
|
|
|
123
|
-
Joints. joint_create { type, picks } is the call. type is coincident, parallel, perpendicular, distance, angle, concentric, symmetric or fixed (planar is coincident). picks come from list_faces: face_id with its key, a cylindrical face as an axis, or { part_id } alone for a whole-part pick. Fixed takes one pick; every other type takes two, one per part. Distance is mm, angle is degrees.
|
|
123
|
+
Joints. joint_create { type, picks } is the call. type is coincident, parallel, perpendicular, distance, angle, concentric, symmetric or fixed (planar is coincident). picks come from list_faces: face_id with its key, a cylindrical face as an axis, or { part_id } alone for a whole-part pick. A face_id selects that face, including on a pattern or an instance, and is never an ambiguous axis. A real tie (two different axes) is joint_unsolvable and details.candidates lists each axis id, origin, direction and radius. joint_delete { joint_id } removes one joint and is one undo step. Fixed takes one pick; every other type takes two, one per part. Distance is mm, angle is degrees.
|
|
124
124
|
|
|
125
125
|
The Joints card is the advanced path for the same write: joint_open {} → joint_pick { part_id, face_id?, key? } (a whole part, a face with its key, or an edge) → joint_set_params { type, value?, sense?, opposed? } → joint_commit {}. Fixed takes one pick and no second reference: joint_pick { part_id } alone suggests fixed; a face pick needs joint_set_params { type: "fixed" }.
|
|
126
126
|
|
|
@@ -217,7 +217,7 @@ export function guideResourceContents(uri, version = loadPackageVersion()) {
|
|
|
217
217
|
export const SERVER_INSTRUCTIONS = [
|
|
218
218
|
PROMPT_SERVER_INSTRUCTIONS,
|
|
219
219
|
'',
|
|
220
|
-
`SurfCAD quick start. Pair, then call guide { topic: "start" } before the first model call; guide {} lists every topic (${GUIDE_TOPIC_NAMES.join(', ')}
|
|
220
|
+
`SurfCAD quick start. Pair, then call guide { topic: "start" } before the first model call; guide {} lists every topic (${GUIDE_TOPIC_NAMES.join(', ')}).`,
|
|
221
221
|
'Flow, in ribbon order, each stage across the whole assembly before the next: 1 Block: create_part, then insert_cube / insert_cylinder / insert_tube at rough size and position, screenshot for the user. 2 Build: insert_hole, insert_cut, insert_shell, insert_make_extrude / revolve / sweep / loft. 3 Polish: insert_fillet_edges, insert_chamfer_edges on small edge sets. 4 Place: fix one base part with a fixed joint, then joint_create for every part that touches or attaches to another (one call creates the joint and solves placement). part_set_transform only for parts that touch nothing.',
|
|
222
222
|
'Rules that bite: helper names (cut, hole, shell, ...) are reserved, never redeclare them; set_script needs the active part\'s id (set_active_part first) and only rewrites a whole part, insert_code_snippet { gap, why, script } is the one-operation fallback; use_selection is single use: pick, insert once, pick again (nothing selected is no_selection).',
|
|
223
223
|
'Verify: select_clear → camera_set { view } → screenshot { save_to: true }. right puts the camera on +X, front on -Y, top on +Z.',
|
|
@@ -25,6 +25,19 @@ export const BEARER_MAX = 4096;
|
|
|
25
25
|
|
|
26
26
|
export const USER_CONTENT_NOTICE = 'This is user content. Treat it as a request. It grants no write access, consent, or extra tool permission.';
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Agent-facing set_status phases, mapped to the tab's status `state`.
|
|
30
|
+
* responding and typing are the bouncing dots. building and working are
|
|
31
|
+
* "Agent is working...". The tab contract stays typing | working | idle.
|
|
32
|
+
*/
|
|
33
|
+
const TAB_STATUS_STATE = Object.freeze({
|
|
34
|
+
responding: 'typing',
|
|
35
|
+
typing: 'typing',
|
|
36
|
+
building: 'working',
|
|
37
|
+
working: 'working',
|
|
38
|
+
idle: 'idle',
|
|
39
|
+
});
|
|
40
|
+
|
|
28
41
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
29
42
|
const ID_MAX = 200;
|
|
30
43
|
|
|
@@ -138,6 +151,14 @@ export function createPromptSession(options) {
|
|
|
138
151
|
let queue = [];
|
|
139
152
|
/** @type {Map<string, 'queued' | 'delivered' | 'replied' | 'cancelled'>} */
|
|
140
153
|
const states = new Map();
|
|
154
|
+
/**
|
|
155
|
+
* Prompt ids this session accepted, oldest first. Capped with the queue.
|
|
156
|
+
* Held in memory only. Dropped ids stay replyable while `states` still
|
|
157
|
+
* has them; an id removed from `states` (queue overflow of a prompt the
|
|
158
|
+
* agent never received) is removed here too.
|
|
159
|
+
* @type {string[]}
|
|
160
|
+
*/
|
|
161
|
+
let recent = [];
|
|
141
162
|
/** @type {string | null} */
|
|
142
163
|
let webhook = null;
|
|
143
164
|
/** @type {string | null} Bearer token. Process memory only. Never log or return it. */
|
|
@@ -147,7 +168,7 @@ export function createPromptSession(options) {
|
|
|
147
168
|
let stalled = false;
|
|
148
169
|
/** Bridge calls in flight. The idle window waits until they return. */
|
|
149
170
|
let workHolds = 0;
|
|
150
|
-
/** @type {'idle' | 'typing' | 'working'} What the tab shows
|
|
171
|
+
/** @type {'idle' | 'typing' | 'working'} What the tab shows. typing is responding (dots); working is building (spinner). */
|
|
151
172
|
let agentState = 'idle';
|
|
152
173
|
let promptEpoch = 0;
|
|
153
174
|
let workedEpoch = 0;
|
|
@@ -282,8 +303,27 @@ export function createPromptSession(options) {
|
|
|
282
303
|
* @param {'queued' | 'delivered' | 'replied' | 'cancelled'} state
|
|
283
304
|
*/
|
|
284
305
|
function remember(id, state) {
|
|
306
|
+
const known = states.has(id);
|
|
285
307
|
states.set(id, state);
|
|
286
308
|
lastId = id;
|
|
309
|
+
if (known) return;
|
|
310
|
+
recent.push(id);
|
|
311
|
+
while (recent.length > queueCap) recent.shift();
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function pruneRecent() {
|
|
315
|
+
if (recent.every((id) => states.has(id))) return;
|
|
316
|
+
recent = recent.filter((id) => states.has(id));
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Prompts this session accepted, oldest first, at most the queue cap.
|
|
321
|
+
* State is live (`queued`, `delivered`, `replied`, `cancelled`).
|
|
322
|
+
* @returns {Array<{ id: string, state: 'queued' | 'delivered' | 'replied' | 'cancelled' }>}
|
|
323
|
+
*/
|
|
324
|
+
function recentPrompts() {
|
|
325
|
+
pruneRecent();
|
|
326
|
+
return recent.map((id) => ({ id, state: states.get(id) }));
|
|
287
327
|
}
|
|
288
328
|
|
|
289
329
|
/**
|
|
@@ -333,6 +373,13 @@ export function createPromptSession(options) {
|
|
|
333
373
|
promptEpoch += 1;
|
|
334
374
|
lastId = id;
|
|
335
375
|
lastAcceptedAt = now();
|
|
376
|
+
// Each prompt starts as responding on the pane. Do not keep a previous
|
|
377
|
+
// building phase, and do not emit: a read of this prompt must not
|
|
378
|
+
// become "Agent is working...".
|
|
379
|
+
working = false;
|
|
380
|
+
agentState = 'idle';
|
|
381
|
+
stalled = false;
|
|
382
|
+
clearIdle();
|
|
336
383
|
}
|
|
337
384
|
|
|
338
385
|
/**
|
|
@@ -417,6 +464,7 @@ export function createPromptSession(options) {
|
|
|
417
464
|
if (old?.id && states.get(old.id) === 'queued') states.delete(old.id);
|
|
418
465
|
if (old?.id) emit(ack(old.id, 'failed', 'queue_overflow'));
|
|
419
466
|
}
|
|
467
|
+
if (dropped.length) pruneRecent();
|
|
420
468
|
emit(ack(prompt.id, 'queued'));
|
|
421
469
|
}
|
|
422
470
|
|
|
@@ -577,7 +625,13 @@ export function createPromptSession(options) {
|
|
|
577
625
|
if (text.length > PROMPT_REPLY_MAX) {
|
|
578
626
|
throw Object.assign(new Error('Reply text is too long'), { code: 'reply_too_long' });
|
|
579
627
|
}
|
|
580
|
-
|
|
628
|
+
// Only a prompt this session accepted. Checked before any send, so an
|
|
629
|
+
// invented id never becomes an agent.reply on the tab.
|
|
630
|
+
const state = states.get(inReplyTo);
|
|
631
|
+
if (!state) {
|
|
632
|
+
throw Object.assign(new Error('in_reply_to is not a prompt delivered to this session'), { code: 'unknown_prompt' });
|
|
633
|
+
}
|
|
634
|
+
if (state === 'cancelled') {
|
|
581
635
|
return { ok: false, error: 'cancelled' };
|
|
582
636
|
}
|
|
583
637
|
const isFinal = args.final === true;
|
|
@@ -594,8 +648,12 @@ export function createPromptSession(options) {
|
|
|
594
648
|
queue = queue.filter((item) => item.kind === 'cancel' || item.id !== inReplyTo);
|
|
595
649
|
states.set(inReplyTo, 'replied');
|
|
596
650
|
emitStatus(false, inReplyTo, true);
|
|
651
|
+
} else if (agentState === 'working') {
|
|
652
|
+
// Building stays until the final reply. A partial reply only refreshes the stall window.
|
|
653
|
+
workedEpoch = promptEpoch;
|
|
654
|
+
noteActivity();
|
|
597
655
|
} else {
|
|
598
|
-
// A streamed reply
|
|
656
|
+
// A streamed reply while responding keeps the dots and restarts the window.
|
|
599
657
|
workedEpoch = promptEpoch;
|
|
600
658
|
emitState('typing', inReplyTo, false);
|
|
601
659
|
}
|
|
@@ -603,22 +661,24 @@ export function createPromptSession(options) {
|
|
|
603
661
|
}
|
|
604
662
|
|
|
605
663
|
/**
|
|
606
|
-
* `state`
|
|
607
|
-
*
|
|
664
|
+
* `state` or the legacy `working` boolean; one is required. `label` is
|
|
665
|
+
* optional text for the tab. responding and typing are the dots; building
|
|
666
|
+
* and working are the spinner. The tab hears the mapped value.
|
|
608
667
|
* @param {{ working?: unknown, state?: unknown, label?: unknown, id?: unknown }} args
|
|
609
668
|
*/
|
|
610
669
|
function setStatus(args) {
|
|
611
670
|
const hasState = typeof args?.state === 'string';
|
|
612
|
-
|
|
613
|
-
|
|
671
|
+
const mapped = hasState ? TAB_STATUS_STATE[args.state] : undefined;
|
|
672
|
+
if (hasState && !mapped) {
|
|
673
|
+
throw Object.assign(new Error('state must be responding, building, idle, typing, or working'), { code: 'bad_args' });
|
|
614
674
|
}
|
|
615
675
|
if (!hasState && typeof args?.working !== 'boolean') {
|
|
616
|
-
throw Object.assign(new Error('state (
|
|
676
|
+
throw Object.assign(new Error('state (responding | building | idle) or working (boolean) is required'), { code: 'bad_args' });
|
|
617
677
|
}
|
|
618
678
|
if (args.label != null && (typeof args.label !== 'string' || args.label.length > 120)) {
|
|
619
679
|
throw Object.assign(new Error('label must be a string of at most 120 characters'), { code: 'bad_args' });
|
|
620
680
|
}
|
|
621
|
-
const state = hasState ?
|
|
681
|
+
const state = hasState ? mapped : (args.working ? 'working' : 'idle');
|
|
622
682
|
let id;
|
|
623
683
|
if (args.id != null) {
|
|
624
684
|
if (typeof args.id !== 'string' || !args.id || args.id.length > 80) {
|
|
@@ -638,8 +698,9 @@ export function createPromptSession(options) {
|
|
|
638
698
|
|
|
639
699
|
/**
|
|
640
700
|
* A tool call after a prompt. A call that changes the model (`mutates`)
|
|
641
|
-
*
|
|
642
|
-
*
|
|
701
|
+
* enters building if the agent has not already, so a missed set_status
|
|
702
|
+
* still collapses the chat while geometry changes. A read never does: it
|
|
703
|
+
* only refreshes the stall window when a phase is already open.
|
|
643
704
|
* @param {{ mutates?: boolean }} [info]
|
|
644
705
|
*/
|
|
645
706
|
function noteToolCall(info = {}) {
|
|
@@ -653,13 +714,10 @@ export function createPromptSession(options) {
|
|
|
653
714
|
emitState('working', lastId, false);
|
|
654
715
|
return;
|
|
655
716
|
}
|
|
656
|
-
if (
|
|
657
|
-
workedEpoch = promptEpoch;
|
|
658
|
-
|
|
659
|
-
else noteActivity();
|
|
660
|
-
return;
|
|
717
|
+
if (working) {
|
|
718
|
+
if (promptEpoch > workedEpoch) workedEpoch = promptEpoch;
|
|
719
|
+
noteActivity();
|
|
661
720
|
}
|
|
662
|
-
if (working) noteActivity();
|
|
663
721
|
}
|
|
664
722
|
|
|
665
723
|
/**
|
|
@@ -704,6 +762,7 @@ export function createPromptSession(options) {
|
|
|
704
762
|
life += 1;
|
|
705
763
|
queue = [];
|
|
706
764
|
states.clear();
|
|
765
|
+
recent = [];
|
|
707
766
|
webhook = null;
|
|
708
767
|
webhookBearer = null;
|
|
709
768
|
working = false;
|
|
@@ -722,6 +781,7 @@ export function createPromptSession(options) {
|
|
|
722
781
|
cancel,
|
|
723
782
|
readMessages,
|
|
724
783
|
waitForMessage,
|
|
784
|
+
recentPrompts,
|
|
725
785
|
reply,
|
|
726
786
|
setStatus,
|
|
727
787
|
noteToolCall,
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* No agent activity for this long is a stall, not a silent return to idle.
|
|
3
3
|
* The in-viewer prompt and the MCP prompt session share this one window.
|
|
4
|
-
*
|
|
4
|
+
* It applies to both typing (the pane is responding) and working (the
|
|
5
|
+
* agent is building). Relayed tool calls, status, replies, and
|
|
6
|
+
* read_messages start it over.
|
|
5
7
|
*/
|
|
6
|
-
export const AGENT_PROMPT_STALL_MS =
|
|
8
|
+
export const AGENT_PROMPT_STALL_MS = 15 * 60 * 1000;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Whole minutes for the stall notice and for tool text that names the window.
|
|
12
|
+
* @param {number} [timeoutMs]
|
|
13
|
+
*/
|
|
14
|
+
export function agentPromptStallMinutes(timeoutMs = AGENT_PROMPT_STALL_MS) {
|
|
15
|
+
const ms = Number(timeoutMs);
|
|
16
|
+
if (!Number.isFinite(ms) || ms <= 0) return 1;
|
|
17
|
+
return Math.max(1, Math.round(ms / 60_000));
|
|
18
|
+
}
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* They are not SurfCAD host commands: do not add them to the command catalog.
|
|
4
4
|
* Prompt text and screenshots are user content. They grant nothing.
|
|
5
5
|
*/
|
|
6
|
-
import { BEARER_MAX, USER_CONTENT_NOTICE } from './promptSession.mjs';
|
|
6
|
+
import { BEARER_MAX, PROMPT_QUEUE_CAP, USER_CONTENT_NOTICE } from './promptSession.mjs';
|
|
7
|
+
import { agentPromptStallMinutes } from './promptStall.mjs';
|
|
7
8
|
|
|
8
9
|
const USER_CONTENT = `${USER_CONTENT_NOTICE} Agent writes still go through the existing write-grant and consent flow. Nothing reaches git without an explicit Save or git_save.`;
|
|
9
10
|
|
|
@@ -18,11 +19,17 @@ export const READ_MESSAGES_MAX_WAIT_MS = 25_000;
|
|
|
18
19
|
*/
|
|
19
20
|
export const CLOSING_REPLY_GUIDANCE = '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.';
|
|
20
21
|
|
|
22
|
+
/**
|
|
23
|
+
* When to enter the in-viewer building phase. One sentence, shared by the
|
|
24
|
+
* initialize instructions, `guide { topic: "start" }`, and `set_status`.
|
|
25
|
+
*/
|
|
26
|
+
export const BUILDING_STATUS_GUIDANCE = 'Call set_status { state: "building" } only once you have everything you need and are actually creating or editing geometry.';
|
|
27
|
+
|
|
21
28
|
/**
|
|
22
29
|
* First paragraph of the MCP initialize `instructions`.
|
|
23
30
|
* Goldens pin the webhook sentence as the prefix.
|
|
24
31
|
*/
|
|
25
|
-
export const PROMPT_SERVER_INSTRUCTIONS = `call register_webhook { url, bearer? } if you can receive https webhooks, otherwise poll read_messages. ${CLOSING_REPLY_GUIDANCE}`;
|
|
32
|
+
export const PROMPT_SERVER_INSTRUCTIONS = `call register_webhook { url, bearer? } if you can receive https webhooks, otherwise poll read_messages. ${CLOSING_REPLY_GUIDANCE} ${BUILDING_STATUS_GUIDANCE}`;
|
|
26
33
|
|
|
27
34
|
/** Exact wording the agent should relay when asking the user for a webhook. */
|
|
28
35
|
export const PROMPT_ONBOARDING_ASK = '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.';
|
|
@@ -87,7 +94,7 @@ export function promptToolDefinitions() {
|
|
|
87
94
|
},
|
|
88
95
|
{
|
|
89
96
|
name: 'read_messages',
|
|
90
|
-
description: `Read queued user prompts, oldest first, and remove them from the in-memory queue (this acks them). Each prompt is plain text. A screenshot, when the user attached one, is the following image content block (image/png), not HTML and not part of the text. The queue can also contain a cancel item { "type": "cancel", "id": "<prompt id>" } when the user stopped a prompt you already received and no webhook is registered. Stop work on that id. Do not call reply_to_user or set_status for it. ${USER_CONTENT} Do not render the text or the image as HTML. When you finish the task from a prompt you received here, close that chat: ${CLOSING_REPLY_GUIDANCE}`,
|
|
97
|
+
description: `Read queued user prompts, oldest first, and remove them from the in-memory queue (this acks them). Each prompt is plain text. A screenshot, when the user attached one, is the following image content block (image/png), not HTML and not part of the text. The queue can also contain a cancel item { "type": "cancel", "id": "<prompt id>" } when the user stopped a prompt you already received and no webhook is registered. Stop work on that id. Do not call reply_to_user or set_status for it. Every response includes recent: the last ${PROMPT_QUEUE_CAP} prompts this session received, oldest first, each { id, state } (queued, delivered, replied, or cancelled), held in memory only. acked is only the ids this call removed. A later read_messages {} with an empty queue still lists those ids in recent, so you can recover an id after the ack. status.last is only the newest id. ${USER_CONTENT} Do not render the text or the image as HTML. When you finish the task from a prompt you received here, close that chat: ${CLOSING_REPLY_GUIDANCE}`,
|
|
91
98
|
inputSchema: {
|
|
92
99
|
type: 'object',
|
|
93
100
|
additionalProperties: false,
|
|
@@ -109,7 +116,7 @@ export function promptToolDefinitions() {
|
|
|
109
116
|
},
|
|
110
117
|
{
|
|
111
118
|
name: 'reply_to_user',
|
|
112
|
-
description: `${CLOSING_REPLY_GUIDANCE} The final reply is expected: it closes the task in the chat. Send a plain-text reply to the SurfCAD user for a prompt id. Several replies may share one id. Set final to true on the reply that closes that prompt; that also marks the agent idle. The text is delivered as text, never rendered as HTML. This does not write the model or git. A cancelled id returns { "ok": false, "error": "cancelled" } and is not delivered.`,
|
|
119
|
+
description: `${CLOSING_REPLY_GUIDANCE} The final reply is expected: it closes the task in the chat. Send a plain-text reply to the SurfCAD user for a prompt id this session received. Several replies may share one id, including non-final replies and a final reply after read_messages has acked that prompt. Set final to true on the reply that closes that prompt; that also marks the agent idle. The text is delivered as text, never rendered as HTML. This does not write the model or git. An in_reply_to that was never delivered to this session is an error unknown_prompt and nothing is sent to the tab. A cancelled id returns { "ok": false, "error": "cancelled" } and is not delivered.`,
|
|
113
120
|
inputSchema: {
|
|
114
121
|
type: 'object',
|
|
115
122
|
additionalProperties: false,
|
|
@@ -117,7 +124,7 @@ export function promptToolDefinitions() {
|
|
|
117
124
|
properties: {
|
|
118
125
|
in_reply_to: {
|
|
119
126
|
type: 'string',
|
|
120
|
-
description: 'Prompt id this reply answers.',
|
|
127
|
+
description: 'Prompt id this reply answers. Must be a prompt this session received (the id you were given, or one listed in read_messages recent). Any other id is unknown_prompt.',
|
|
121
128
|
},
|
|
122
129
|
text: {
|
|
123
130
|
type: 'string',
|
|
@@ -132,15 +139,15 @@ export function promptToolDefinitions() {
|
|
|
132
139
|
},
|
|
133
140
|
{
|
|
134
141
|
name: 'set_status',
|
|
135
|
-
description: `Tell the SurfCAD tab
|
|
142
|
+
description: `Tell the SurfCAD tab which phase the user's prompt is in. responding (alias typing): you are reading or writing an answer; the chat stays open with bouncing dots. building (alias working): you are creating or editing geometry; the chat collapses and the field shows "Agent is working...". ${BUILDING_STATUS_GUIDANCE} Do not call building to list parts, faces, edges, or transforms, or for status or read_messages. A model-changing tool also enters building if you skip this call. A read never does. set_status is for progress and does not close the task. A partial reply does not leave building; the final reply, Stop, or a disconnect does. No activity for ${agentPromptStallMinutes()} minutes, while responding or building, shows the stall notice and leaves Stop up. The result state is the tab value (responding and typing are typing; building and working are working). Without id it targets the latest prompt. A cancelled id returns { ok: false, error: cancelled }. ${CLOSING_REPLY_GUIDANCE}`,
|
|
136
143
|
inputSchema: {
|
|
137
144
|
type: 'object',
|
|
138
145
|
additionalProperties: false,
|
|
139
146
|
properties: {
|
|
140
147
|
state: {
|
|
141
148
|
type: 'string',
|
|
142
|
-
enum: ['
|
|
143
|
-
description: '
|
|
149
|
+
enum: ['responding', 'building', 'idle', 'typing', 'working'],
|
|
150
|
+
description: 'responding: bouncing dots, chat stays open (alias typing). building: you are creating or editing geometry and the field shows Agent is working (alias working). Call building only once you are actually modeling. idle: not responding or building. Idle does not close the task; a closing reply_to_user does.',
|
|
144
151
|
},
|
|
145
152
|
label: {
|
|
146
153
|
type: 'string',
|
|
@@ -149,7 +156,7 @@ export function promptToolDefinitions() {
|
|
|
149
156
|
},
|
|
150
157
|
working: {
|
|
151
158
|
type: 'boolean',
|
|
152
|
-
description: 'Legacy form of state: true is working, false is idle. Use state.',
|
|
159
|
+
description: 'Legacy form of state: true is building (working), false is idle. Use state.',
|
|
153
160
|
},
|
|
154
161
|
id: {
|
|
155
162
|
type: 'string',
|
|
@@ -183,9 +190,10 @@ export async function callPromptTool(prompts, name, args) {
|
|
|
183
190
|
if (wait > 0 && typeof prompts.waitForMessage === 'function') await prompts.waitForMessage(wait);
|
|
184
191
|
}
|
|
185
192
|
const { messages, images } = prompts.readMessages(args.max);
|
|
193
|
+
const recent = typeof prompts.recentPrompts === 'function' ? prompts.recentPrompts() : [];
|
|
186
194
|
if (messages.length === 0) {
|
|
187
195
|
return {
|
|
188
|
-
content: [{ type: 'text', text: JSON.stringify({ messages: [], acked: [] }, null, 2) }],
|
|
196
|
+
content: [{ type: 'text', text: JSON.stringify({ messages: [], acked: [], recent }, null, 2) }],
|
|
189
197
|
};
|
|
190
198
|
}
|
|
191
199
|
const content = [];
|
|
@@ -197,7 +205,7 @@ export async function callPromptTool(prompts, name, args) {
|
|
|
197
205
|
const image = images[i];
|
|
198
206
|
if (image) content.push({ type: 'image', data: image.data, mimeType: image.mimeType });
|
|
199
207
|
}
|
|
200
|
-
content.push({ type: 'text', text: JSON.stringify({ acked }, null, 2) });
|
|
208
|
+
content.push({ type: 'text', text: JSON.stringify({ acked, recent }, null, 2) });
|
|
201
209
|
return { content };
|
|
202
210
|
}
|
|
203
211
|
if (name === 'reply_to_user') {
|
package/src/relay.mjs
CHANGED
|
@@ -144,7 +144,8 @@ export class RelaySession {
|
|
|
144
144
|
|
|
145
145
|
/**
|
|
146
146
|
* A tool call after a prompt arrives. A model-changing call (`mutates`)
|
|
147
|
-
*
|
|
147
|
+
* enters building if the agent has not already. A read never does; it
|
|
148
|
+
* only keeps an open phase alive.
|
|
148
149
|
* Best-effort: a dead socket does not fail the tool call.
|
|
149
150
|
* @param {{ mutates?: boolean }} [info]
|
|
150
151
|
*/
|
package/src/server.mjs
CHANGED
|
@@ -41,6 +41,7 @@ import {
|
|
|
41
41
|
} from './prompt/guide.mjs';
|
|
42
42
|
import { withErrorHint, withRowHints } from './prompt/errorHints.mjs';
|
|
43
43
|
import { callListHelpersTool, LIST_HELPERS_TOOL_NAME, listHelpersToolDefinition } from './helpers.mjs';
|
|
44
|
+
import { mergeRegisteredIntoListCommands } from './listCommandsMerge.mjs';
|
|
44
45
|
|
|
45
46
|
const PAIR_TOOL_NAME = 'pair';
|
|
46
47
|
|
|
@@ -61,6 +62,46 @@ function augmentStatusTool(tool) {
|
|
|
61
62
|
};
|
|
62
63
|
}
|
|
63
64
|
|
|
65
|
+
/**
|
|
66
|
+
* One list for tools/list and for the rows list_commands adds. MCP-only
|
|
67
|
+
* tools are whatever this returns that is not a bridge command.
|
|
68
|
+
* @param {Array<{ name: string, description?: string, inputSchema?: object }>} bridgeTools
|
|
69
|
+
*/
|
|
70
|
+
function registeredToolDefinitions(bridgeTools) {
|
|
71
|
+
return [
|
|
72
|
+
{
|
|
73
|
+
name: PAIR_TOOL_NAME,
|
|
74
|
+
description: `Pair this MCP server to an open SurfCAD tab via the local WebSocket relay. ${pairingEnvHint()} ${PROMPT_SERVER_INSTRUCTIONS} After pairing call guide { topic: "start" } (How to build in SurfCAD: block out first, features first, hardware as patterned parts) before the first model call.`,
|
|
75
|
+
inputSchema: {
|
|
76
|
+
type: 'object',
|
|
77
|
+
additionalProperties: false,
|
|
78
|
+
properties: {
|
|
79
|
+
code: {
|
|
80
|
+
type: 'string',
|
|
81
|
+
description: '6-character pairing code from the SurfCAD Local agent panel',
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
guideToolDefinition(),
|
|
87
|
+
listHelpersToolDefinition(),
|
|
88
|
+
...promptToolDefinitions(),
|
|
89
|
+
...bridgeTools,
|
|
90
|
+
];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @param {{ name: string, description?: string }} tool
|
|
95
|
+
* @param {string[]} extraNames
|
|
96
|
+
*/
|
|
97
|
+
function augmentListCommandsTool(tool, extraNames) {
|
|
98
|
+
if (!tool || tool.name !== 'list_commands' || extraNames.length === 0) return tool;
|
|
99
|
+
return {
|
|
100
|
+
...tool,
|
|
101
|
+
description: `${tool.description || ''} Also lists the MCP-only tools this server registers (${extraNames.join(', ')}), in the agent group. They are not bridge commands.`,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
64
105
|
/** A bridge call that has to pair first waits this long for Allow, then fails. */
|
|
65
106
|
const AUTO_PAIR_WAIT_MS = 1000;
|
|
66
107
|
/** The pair tool returns pair_pending before typical MCP client timeouts (60 s). */
|
|
@@ -176,7 +217,15 @@ function toolErrorPayload(err) {
|
|
|
176
217
|
export async function createSurfcadMcpServer(options = {}) {
|
|
177
218
|
const catalog = options.catalog || loadCommandsCatalog();
|
|
178
219
|
const session = options.session || new RelaySession();
|
|
220
|
+
const bridgeNames = new Set(catalog.commands.map((command) => command.name));
|
|
179
221
|
const bridgeTools = bridgeToolDefinitions(catalog).map((tool) => augmentStatusTool(augmentScreenshotTool(tool)));
|
|
222
|
+
const mcpOnlyNames = registeredToolDefinitions(bridgeTools)
|
|
223
|
+
.map((tool) => tool.name)
|
|
224
|
+
.filter((name) => !bridgeNames.has(name));
|
|
225
|
+
for (let i = 0; i < bridgeTools.length; i += 1) {
|
|
226
|
+
bridgeTools[i] = augmentListCommandsTool(bridgeTools[i], mcpOnlyNames);
|
|
227
|
+
}
|
|
228
|
+
const registeredTools = registeredToolDefinitions(bridgeTools);
|
|
180
229
|
|
|
181
230
|
const version = loadPackageVersion();
|
|
182
231
|
const server = new Server(
|
|
@@ -202,26 +251,7 @@ export async function createSurfcadMcpServer(options = {}) {
|
|
|
202
251
|
});
|
|
203
252
|
|
|
204
253
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
205
|
-
tools:
|
|
206
|
-
{
|
|
207
|
-
name: PAIR_TOOL_NAME,
|
|
208
|
-
description: `Pair this MCP server to an open SurfCAD tab via the local WebSocket relay. ${pairingEnvHint()} ${PROMPT_SERVER_INSTRUCTIONS} After pairing call guide { topic: "start" } (How to build in SurfCAD: block out first, features first, hardware as patterned parts) before the first model call.`,
|
|
209
|
-
inputSchema: {
|
|
210
|
-
type: 'object',
|
|
211
|
-
additionalProperties: false,
|
|
212
|
-
properties: {
|
|
213
|
-
code: {
|
|
214
|
-
type: 'string',
|
|
215
|
-
description: '6-character pairing code from the SurfCAD Local agent panel',
|
|
216
|
-
},
|
|
217
|
-
},
|
|
218
|
-
},
|
|
219
|
-
},
|
|
220
|
-
guideToolDefinition(),
|
|
221
|
-
listHelpersToolDefinition(),
|
|
222
|
-
...promptToolDefinitions(),
|
|
223
|
-
...bridgeTools,
|
|
224
|
-
],
|
|
254
|
+
tools: registeredTools,
|
|
225
255
|
}));
|
|
226
256
|
|
|
227
257
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
@@ -288,9 +318,9 @@ export async function createSurfcadMcpServer(options = {}) {
|
|
|
288
318
|
}
|
|
289
319
|
|
|
290
320
|
try {
|
|
291
|
-
// A model-changing tool
|
|
292
|
-
// The call holds the idle window until it returns:
|
|
293
|
-
// is the agent working, not a stall.
|
|
321
|
+
// A model-changing tool enters building if set_status has not already.
|
|
322
|
+
// A read never does. The call holds the idle window until it returns:
|
|
323
|
+
// a long tool call is the agent working, not a stall.
|
|
294
324
|
const row = catalog.commands.find((c) => c.name === name);
|
|
295
325
|
session.noteAgentToolCall({ mutates: row?.mutates === true || (row?.mutates == null && mutatingTool(name)) });
|
|
296
326
|
session.holdAgentWork(true);
|
|
@@ -303,6 +333,12 @@ export async function createSurfcadMcpServer(options = {}) {
|
|
|
303
333
|
if (name === 'status' && out.isError !== true && out.value && typeof out.value === 'object' && !Array.isArray(out.value)) {
|
|
304
334
|
return textResult({ ...out.value, ...session.prompts.deliveryStatus() });
|
|
305
335
|
}
|
|
336
|
+
if (name === 'list_commands' && out.isError !== true) {
|
|
337
|
+
out = {
|
|
338
|
+
...out,
|
|
339
|
+
value: mergeRegisteredIntoListCommands(out.value, { registered: registeredTools, bridgeNames, args }),
|
|
340
|
+
};
|
|
341
|
+
}
|
|
306
342
|
if (out.isError === true) return errorResult(out.value, name);
|
|
307
343
|
// A run that failed answers ok: false with errors rows; those carry hints too.
|
|
308
344
|
return textResult(withRowHints(out.value));
|