mirror of
https://github.com/storytold/cadcraft.git
synced 2026-10-28 12:56:47 -06:00
* cadcraft-cli mcp: --connect without HOST:PORT is an error, not a headless session (#103) `mcp --connect` with no address (or an empty or flag-like one) fell through to the headless backend, so a client meant for the app got successful edits in a separate drawing. The mcp arguments now go through parse_mcp_args: --connect must be followed by a non-empty value that doesn't start with `-`, unknown arguments and a repeated --connect are rejected, and every error exits non-zero before any MCP request is served. Plain `mcp` is still headless; a real address still connects, and an unreachable one still fails. - Unit tests for the parser; integration tests (tests/mcp_connect.rs) run the binary: missing/empty/flag-like address, headless control, loopback endpoint routing, closed port. - docs/mcp.md says what happens without an address. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Move tests away from other PRs' hunks to avoid merge conflicts Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
2.2 KiB
Markdown
52 lines
2.2 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. |
|
|
| `inspect_drawing {entities?, limit?}` | Counts, extents, layers, styles, blocks, layouts, selection, undo history and entities. |
|
|
| `query_entities {type?, layer?, window?}` | Filtered entities with handles and geometry. |
|
|
| `render {width?, height?, fit?}` | A PNG image of the drawing. |
|
|
| `new_drawing {metric?}`, `open {path}`, `save {path?}`, `cancel` | Files and Escape. |
|
|
| `screenshot`, `ui_inspect`, `ui_click {x, y}` | Only when connected to the app. |
|
|
|
|
Resources: `cadcraft://drawing` (inspect JSON) and `cadcraft://commands` (catalog).
|
|
|
|
## 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.
|