mirror of
https://github.com/storytold/cadcraft.git
synced 2026-10-27 04:16:48 -06:00
tools/call checks the arguments against the tool's input schema: an
unknown tool, non-object arguments, a missing required argument or one
of the wrong type is a JSON-RPC -32602 error, as the MCP spec says, so
`command_line {}` no longer presses Enter and `script {}` no longer
succeeds. An empty batch `[]` gets one Invalid Request (-32600).
The `entities` command behind query_entities rejects a malformed window,
non-string type/layer and bad limit/offset instead of ignoring them.
`count` is every match, `returned` the page (`offset` is now in the tool
schema), and a window matches objects whose geometry is inside or
crosses it (the window/crossing selection test), with `crossing: false`
for entirely inside.
list_commands' filter matches command ids, labels and aliases, not any
text in the command's JSON.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
57 lines
3.0 KiB
Markdown
57 lines
3.0 KiB
Markdown
# CADCraft and AI agents (MCP)
|
|
|
|
CADCraft speaks the [Model Context Protocol](https://modelcontextprotocol.io) over stdio.
|
|
|
|
## Start it
|
|
|
|
```sh
|
|
# Headless: an in-process drawing session, no window.
|
|
cadcraft-cli mcp
|
|
|
|
# Bridged to the running app (watch the agent draw):
|
|
cadcraft --control 7979 &
|
|
cadcraft-cli mcp --connect 127.0.0.1:7979
|
|
```
|
|
|
|
`--connect` needs the app's `HOST:PORT`. Without one (or with an unknown argument) `cadcraft-cli mcp`
|
|
exits with an error instead of falling back to a headless session, so a client meant for the app
|
|
never edits a separate drawing by mistake. If the app can't be reached, startup fails too.
|
|
|
|
Example client configuration (Claude Code / Claude Desktop):
|
|
|
|
```json
|
|
{ "mcpServers": { "cadcraft": { "command": "cadcraft-cli", "args": ["mcp"] } } }
|
|
```
|
|
|
|
## Tools
|
|
|
|
| Tool | What it does |
|
|
|---|---|
|
|
| `command_line {text}` | Type at the command line exactly like a person: `line 0,0 @10,0 @0,5 c`, `circle 5,2 1`, `offset 0.5`, `zoom e`. Spaces act as Enter; empty text is Enter. Returns the new prompt, keywords and output. |
|
|
| `script {text}` | A multi-line script (like `.scr` files). |
|
|
| `execute {command, params}` | Any command with JSON parameters, never a dialog. `list_commands` shows ids and parameter docs. |
|
|
| `list_commands {filter?}` | The command catalog; `filter` matches part of a command's id, label or an alias. |
|
|
| `inspect_drawing {entities?, limit?}` | Counts, extents, layers, styles, blocks, layouts, selection, undo history and entities. |
|
|
| `query_entities {type?, layer?, window?, crossing?, limit?, offset?}` | Filtered entities with handles and geometry. `window` `[[x0,y0],[x1,y1]]` finds objects whose geometry is inside it or crosses it (`crossing: false`: entirely inside). `count` is every match, `returned` the page (`offset`, `limit`, default 500). |
|
|
| `render {width?, height?, fit?}` | A PNG image of the drawing. |
|
|
| `new_drawing {metric?}`, `open {path}`, `save {path?}`, `cancel` | Files and Escape. `save` to a `.svg`, `.png` or `.pdf` path exports: the drawing keeps its name and unsaved changes. |
|
|
| `screenshot`, `ui_inspect`, `ui_click {x, y}` | Only when connected to the app. |
|
|
|
|
Resources: `cadcraft://drawing` (inspect JSON) and `cadcraft://commands` (catalog).
|
|
|
|
Arguments are checked against each tool's input schema. An unknown tool, `arguments` that aren't an
|
|
object, a missing required argument or one of the wrong type is a JSON-RPC error `-32602` (invalid
|
|
params), so `command_line {}` never presses Enter by accident. A tool that runs and fails (a bad
|
|
point, an unknown command) returns a result with `isError: true` and the message.
|
|
|
|
## A typical session
|
|
|
|
1. `command_line {"text": "rectang 0,0 100,60"}`
|
|
2. `execute {"command": "circle", "params": {"center": [10, 10], "radius": 4}}`
|
|
3. `command_line {"text": "dimlinear 0,0 100,0 50,-8"}`
|
|
4. `inspect_drawing {}` — verify counts and geometry.
|
|
5. `render {}` — look at it.
|
|
|
|
The end-to-end test in `crates/mcp/src/tests.rs` runs a session like this and checks the result
|
|
only through MCP.
|