{"id":"26e133bd-8030-44fc-877a-774b90dccbd4","slug":"puran-water-autocad-mcp","kind":"mcp","name":"autocad-mcp","summary":"MCP server for AutoCAD LT v3.1: freehand AutoLISP execution, 8 consolidated tools, File IPC + ezdxf backends, focus-free dispatch, undo/redo, P&ID symbols, and robust IPC with ESC prefix and UTF-8 fal","owner":"puran-water","repoUrl":"https://github.com/puran-water/autocad-mcp","license":"MIT","licenseTier":"permissive","trust":"community","stars":573,"match":null,"fewStars":false,"format":"mcp","createdAt":"2025-03-20T17:22:52.000Z","addedAt":"2026-10-15T00:50:25.107Z","logoUrl":"https://avatars.githubusercontent.com/u/214024398?v=4","linkOnly":false,"collection":null,"skillPath":null,"categories":["files-documents","cloud-infra"],"tags":[],"runtime":"binary","local":true,"cloudCapable":false,"cloudCapability":"unknown","cloudReadyOnPlatform":false,"needsApiKey":false,"reviewed":false,"syncedAt":"2026-10-18T00:50:49.195Z","sample":false,"url":"https://conduits.dev/tools/puran-water-autocad-mcp","language":"Python","transports":["stdio"],"install":{},"requirements":{"env":[],"upstreamMayCharge":false},"tools":null,"readme":"# AutoCAD MCP Server\n\nMCP server for AutoCAD LT automation and headless DXF generation.\n\nTwo backends, one API:\n\n| Backend | Runtime | Requires AutoCAD? | Screenshot |\n|---------|---------|-------------------|------------|\n| **File IPC** | Windows Python | Yes — AutoCAD LT 2024+ (Windows) | Win32 PrintWindow |\n| **ezdxf** | Any platform | No (headless) | matplotlib render |\n\nThe server exposes **8 consolidated tools** (`drawing`, `entity`, `layer`, `block`, `annotation`, `pid`, `view`, `system`) over the MCP stdio transport. An MCP client (Claude Desktop, Claude Code, etc.) connects and drives AutoCAD through natural-language requests.\n\n## Prerequisites (File IPC backend)\n\n- **Windows 10/11** (the File IPC backend uses Win32 APIs for focus-free window messaging)\n- **AutoCAD LT 2024 or newer** — AutoLISP support was added in LT 2024 for Windows. AutoCAD LT for Mac exists but does **not** support AutoLISP.\n- **Python 3.10+** (Windows native — not WSL Python)\n- **uv** package manager ([install guide](https://docs.astral.sh/uv/getting-started/installation/))\n\n> The ezdxf headless backend works on any platform (Linux, macOS, WSL) for offline DXF generation without AutoCAD installed.\n\n## Quick Start\n\n### 1. Clone and install\n\n```powershell\ngit clone https://github.com/puran-water/autocad-mcp.git\ncd autocad-mcp\nuv sync\n```\n\n### 2. Load the LISP dispatcher in AutoCAD LT\n\nOpen AutoCAD LT and load `mcp_dispatch.lsp` using **APPLOAD**:\n\n1. Type `APPLOAD` in the AutoCAD command line\n2. Browse to `<repo>/lisp-code/mcp_dispatch.lsp`\n3. Click **Load**\n4. You should see: `=== MCP Dispatch v3.1 loaded ===` and `Ready for commands via (c:mcp-dispatch)`\n\n> **Tip:** Add the file to your AutoCAD Startup Suite (in the APPLOAD dialog) so it loads automatically with every drawing.\n\n### 3. Configure your MCP client\n\nAdd to your MCP client configuration (e.g. Claude Desktop `claude_desktop_config.json`):\n\n```json\n{\n  \"mcpServers\": {\n    \"autocad-mcp\": {\n      \"command\": \"C:\\\\path\\\\to\\\\autocad-mcp\\\\.venv\\\\Scripts\\\\python.exe\",\n      \"args\": [\"-m\", \"autocad_mcp\"],\n      \"env\": { \"AUTOCAD_MCP_BACKEND\": \"auto\" }\n    }\n  }\n}\n```\n\n**Key points:**\n\n- The `command` must point to the **Windows Python** inside the project venv (not WSL python).\n- `AUTOCAD_MCP_BACKEND` can be `auto` (default — tries File IPC, falls back to ezdxf), `file_ipc` (requires AutoCAD), or `ezdxf` (headless only).\n\n#### Running from WSL\n\nIf your MCP client runs in WSL (e.g. Claude Code), launch the server through `cmd.exe` so it runs as a native Windows process:\n\n```json\n{\n  \"mcpServers\": {\n    \"autocad-mcp\": {\n      \"type\": \"stdio\",\n      \"command\": \"cmd.exe\",\n      \"args\": [\"/d\", \"/s\", \"/c\", \"cd /d C:\\\\path\\\\to\\\\autocad-mcp && .venv\\\\Scripts\\\\python.exe -m autocad_mcp\"],\n      \"env\": { \"AUTOCAD_MCP_BACKEND\": \"auto\" }\n    }\n  }\n}\n```\n\n### 4. Verify\n\nFrom your MCP client, call:\n\n```\nsystem(operation=\"status\")\n```\n\nYou should see `backend: \"file_ipc\"` if AutoCAD is running, or `backend: \"ezdxf\"` for headless mode.\n\n## Tools\n\n### `drawing` — File/drawing management\n\n| Operation | Description | File IPC | ezdxf |\n|-----------|-------------|----------|-------|\n| `create` | Reset to clean drawing (erase all + purge) | Yes | Yes |\n| `open` | Open an existing drawing | Yes | Yes (DXF) |\n| `info` | Get entity count and layers | Yes | Yes |\n| `save` | Save current drawing (to path if given) | Yes | Yes |\n| `save_as_dxf` | Export as DXF | Yes | Yes |\n| `plot_pdf` | Plot to PDF | Yes | No |\n| `purge` | Purge unused objects | Yes | Yes |\n| `get_variables` | Get system variables by name | Yes | Yes |\n| `undo` | Undo last operation | Yes | No |\n| `redo` | Redo last undone operation | Yes | No |\n\n### `entity` — Entity CRUD + modification\n\n**Create:** `create_line`, `create_circle`, `create_polyline`, `create_rectangle`, `create_arc`, `create_ellipse`, `create_mtext`, `create_hatch`\n\n**Read:** `list`, `count`, `get`\n\n**Modify:** `copy`, `move`, `rotate`, `scale`, `mirror`, `offset`\\*, `array`, `fillet`\\*, `chamfer`\\*, `erase`\n\n> \\* `offset`, `fillet`, `chamfer` are File IPC only (not supported in ezdxf headless backend).\n\n### `layer` — Layer management\n\n`list`, `create`, `set_current`, `set_properties`, `freeze`, `thaw`, `lock`, `unlock`\n\n### `block` — Block operations\n\n| Operation | File IPC | ezdxf |\n|-----------|----------|-------|\n| `list` | Yes | Yes |\n| `insert` | Yes | Yes |\n| `insert_with_attributes` | Yes | Yes |\n| `get_attributes` | Yes | Yes |\n| `update_attribute` | Yes | Yes |\n| `define` | No | Yes |\n\n### `annotation` — Text, dimensions, leaders\n\n`create_text`, `create_dimension_linear`, `create_dimension_aligned`, `create_dimension_angular`, `create_dimension_radius`, `create_leader`\n\n### `pid` — P&ID operations (CTO symbol library)\n\n`setup_layers`, `insert_symbol`, `list_symbols`, `draw_process_line`, `connect_equipment`, `add_flow_arrow`, `add_equipment_tag`, `add_line_number`, `insert_valve`, `insert_instrument`, `insert_pump`, `insert_tank`\n\n> P&ID symbol insertion requires the [CAD Tools Online](https://www.cadtoolsonline.com/) (CTO) P&ID Symbol Library installed at `C:\\PIDv4-CTO\\`. The ezdxf backend has built-in CTO library support. For the File IPC backend, some P&ID operations require additional LISP helpers — see the P&ID section in the wiki for setup details.\n\n### `view` — Viewport and screenshot\n\n| Operation | Description |\n|-----------|-------------|\n| `zoom_extents` | Zoom to show all entities |\n| `zoom_window` | Zoom to a specified window |\n| `get_screenshot` | Capture current AutoCAD view as PNG |\n\nScreenshots use `PrintWindow` (Win32) for the File IPC backend — works even when AutoCAD is minimized or in the background. The ezdxf backend renders via matplotlib.\n\n### `system` — Server management\n\n`status`, `health`, `get_backend`, `runtime`, `init`, `execute_lisp`\n\n> `execute_lisp` runs arbitrary AutoLISP code (File IPC only). Pass `data: {code: \"(+ 1 2)\"}`. This turns the server into an extensible automation platform — any valid AutoLISP expression can be executed.\n\n## Architecture\n\n```\nMCP Client (Claude)\n    │  stdio (JSON-RPC)\n    ▼\nPython MCP Server (autocad_mcp)\n    │\n    ├── File IPC Backend ──► C:/temp/*.json ──► mcp_dispatch.lsp (AutoCAD LT)\n    │   PostMessageW(WM_CHAR) to MDIClient — no focus steal\n    │\n    └── ezdxf Backend ──► in-memory DXF (headless, no AutoCAD needed)\n```\n\nThe File IPC backend sends keystrokes to AutoCAD's MDIClient window via `PostMessageW(WM_CHAR)`, triggering the `(c:mcp-dispatch)` AutoLISP command. This approach does **not** steal window focus — you can continue working in other applications while automation runs.\n\n## Environment Variables\n\n| Variable | Default | Description |\n|----------|---------|-------------|\n| `AUTOCAD_MCP_BACKEND` | `auto` | Backend selection: `auto`, `file_ipc`, `ezdxf` |\n| `AUTOCAD_MCP_IPC_DIR` | `C:/temp` | Directory for IPC command/result JSON files (must match on both Python and LISP sides) |\n| `AUTOCAD_MCP_IPC_TIMEOUT` | `10.0` | IPC command timeout in seconds (1-300) |\n| `AUTOCAD_MCP_ONLY_TEXT` | `false` | Disable screenshot capture (text feedback only) |\n\n> **Note:** If you change `AUTOCAD_MCP_IPC_DIR`, you must also update the `*mcp-ipc-dir*` variable in `mcp_dispatch.lsp` to match.\n\n## Development\n\n```powershell\nuv sync\nuv run pytest tests/ -v\n```\n\n## AutoCAD LT AutoLISP Compatibility\n\nAutoLISP was added to AutoCAD LT in the **2024 release (Windows only)**. AutoCAD LT for Mac does not support AutoLISP.\n\n| Supported (LT 2024+ Windows) | Not Supported |\n|-------------------------------|---------------|\n| `.lsp` / `.fas` / `.vlx` / `.dcl` | VLIDE (Visual LISP IDE) |\n| All `vl-*` utility functions | `vlax-*` (ActiveX/COM) |\n| File I/O (`open`, `read-line`, etc.) | Express Tools |\n| Entity access (`entget`, `entmod`, etc.) | 3D operations |\n| Selection sets | AutoLISP on Mac |\n\nThe `mcp_dispatch.lsp` dispatcher is fully compatible with LT 2024+.\n\n## What's New in v3.1\n\n- **`execute_lisp`** — Run arbitrary AutoLISP code via temp file pattern. Turns the server from a fixed command set into an extensible automation platform.\n- **Undo / Redo** — Single-step undo and redo via `drawing` tool.\n- **Drawing open** — Open existing `.dwg` files programmatically (FILEDIA suppressed).\n- **Drawing create** — Now resets current drawing (erase all + purge) instead of `_.NEW`, preserving the LISP dispatcher namespace.\n- **Drawing save with path** — `save` with a `path` parameter uses SAVEAS; without path uses QSAVE.\n- **`get_variables` fix** — Respects the `names` parameter; returns requested variables with proper type handling.\n- **Polyline/leader fix** — Point arrays properly encoded via semicolon-delimited format.\n- **ESC prefix** — Sends 2x ESC before each dispatch to cancel stale pending commands from prior timeouts.\n- **UTF-8/cp1252 fallback** — Handles non-ASCII characters in LISP result files (AutoCAD writes Windows-1252).\n- **Configurable IPC timeout** — `AUTOCAD_MCP_IPC_TIMEOUT` env var (1–300 seconds, default 10).\n- **Thread-safe backend init** — `asyncio.Lock` prevents parallel initialization races.\n\n## License\n\nMIT\n"}