通过 MCP 协议驱动 AutoCAD LT 的服务器,支持 File IPC 与 ezdxf 两种后端,提供绘图、实体、图层、块、标注、P&ID 符号等 8 组工具,可执行 AutoLISP 并支持无头 DXF 生成。
✓已通过基础校验
名称、分类、版本与作者信息完整,安装包与文档齐备。
✓可直接使用
提供 Markdown 文档与配置示例,下载后按文档说明使用即可。
MCP server for AutoCAD LT automation and headless DXF generation.
用于 AutoCAD LT 自动化和无头 DXF 生成的 MCP 服务器。
Two backends, one API:
两个后端,一套 API:
| Backend / 后端 | Runtime / 运行时 | Requires AutoCAD? / 是否需要 AutoCAD? | Screenshot / 截图 |
|---|---|---|---|
| File IPC | Windows Python | Yes — AutoCAD LT 2024+ (Windows) / 是 — AutoCAD LT 2024+(Windows) | Win32 PrintWindow |
| ezdxf | Any platform / 任意平台 | No (headless) / 否(无头模式) | matplotlib render / matplotlib 渲染 |
The 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.
该服务器通过 MCP stdio 传输暴露 8 个整合工具(drawing、entity、layer、block、annotation、pid、view、system)。MCP 客户端(Claude Desktop、Claude Code 等)连接后即可通过自然语言请求驱动 AutoCAD。
The ezdxf headless backend works on any platform (Linux, macOS, WSL) for offline DXF generation without AutoCAD installed.
ezdxf 无头后端可在任意平台(Linux、macOS、WSL)上运行,无需安装 AutoCAD 即可离线生成 DXF。
git clone https://github.com/puran-water/autocad-mcp.git
cd autocad-mcp
uv sync
Open AutoCAD LT and load mcp_dispatch.lsp using APPLOAD:
打开 AutoCAD LT,使用 APPLOAD 加载 mcp_dispatch.lsp:
APPLOAD in the AutoCAD command lineAPPLOAD<repo>/lisp-code/mcp_dispatch.lsp<repo>/lisp-code/mcp_dispatch.lsp= MCP Dispatch v3.1 loaded = and Ready for commands via (c:mcp-dispatch)= MCP Dispatch v3.1 loaded = 和 Ready for commands via (c:mcp-dispatch)Tip: Add the file to your AutoCAD Startup Suite (in the APPLOAD dialog) so it loads automatically with every drawing.
提示: 将该文件添加到 AutoCAD 启动组(在 APPLOAD 对话框中),使其随每个图形自动加载。
Add to your MCP client configuration (e.g. Claude Desktop claude_desktop_config.json):
添加到你的 MCP 客户端配置中(例如 Claude Desktop 的 claude_desktop_config.json):
{
"mcpServers": {
"autocad-mcp": {
"command": "C:\\path\\to\\autocad-mcp\\.venv\\Scripts\\python.exe",
"args": ["-m", "autocad_mcp"],
"env": { "AUTOCAD_MCP_BACKEND": "auto" }
}
}
}
Key points:
要点:
command must point to the Windows Python inside the project venv (not WSL python).command 必须指向项目 venv 中的 Windows Python(不是 WSL python)。AUTOCAD_MCP_BACKEND can be auto (default — tries File IPC, falls back to ezdxf), file_ipc (requires AutoCAD), or ezdxf (headless only).AUTOCAD_MCP_BACKEND 可以是 auto(默认 — 先尝试 File IPC,失败后回退到 ezdxf)、file_ipc(需要 AutoCAD)或 ezdxf(仅无头模式)。If your MCP client runs in WSL (e.g. Claude Code), launch the server through cmd.exe so it runs as a native Windows process:
如果你的 MCP 客户端运行在 WSL 中(例如 Claude Code),请通过 cmd.exe 启动服务器,使其作为原生 Windows 进程运行:
{
"mcpServers": {
"autocad-mcp": {
"type": "stdio",
"command": "cmd.exe",
"args": ["/d", "/s", "/c", "cd /d C:\\path\\to\\autocad-mcp && .venv\\Scripts\\python.exe -m autocad_mcp"],
"env": { "AUTOCAD_MCP_BACKEND": "auto" }
}
}
}
From your MCP client, call:
在你的 MCP 客户端中调用:
system(operation="status")
You should see backend: "file_ipc" if AutoCAD is running, or backend: "ezdxf" for headless mode.
如果 AutoCAD 正在运行,你应该会看到 backend: "file_ipc";如果是无头模式,则会看到 backend: "ezdxf"。
drawing — File/drawing managementdrawing — 文件/图形管理| Operation / 操作 | Description / 描述 | File IPC | ezdxf |
|---|---|---|---|
create |
Reset to clean drawing (erase all + purge) / 重置为空白图形(全部删除 + 清理) | Yes / 是 | Yes / 是 |
open |
Open an existing drawing / 打开已有图形 | Yes / 是 | Yes (DXF) / 是(DXF) |
info |
Get entity count and layers / 获取实体数量和图层 | Yes / 是 | Yes / 是 |
save |
Save current drawing (to path if given) / 保存当前图形(若给定路径则另存) | Yes / 是 | Yes / 是 |
save_as_dxf |
Export as DXF / 导出为 DXF | Yes / 是 | Yes / 是 |
plot_pdf |
Plot to PDF / 打印为 PDF | Yes / 是 | No / 否 |
purge |
Purge unused objects / 清理未使用对象 | Yes / 是 | Yes / 是 |
get_variables |
Get system variables by name / 按名称获取系统变量 | Yes / 是 | Yes / 是 |
undo |
Undo last operation / 撤销上一步操作 | Yes / 是 | No / 否 |
redo |
Redo last undone operation / 重做上次撤销的操作 | Yes / 是 | No / 否 |
entity — Entity CRUD + modificationentity — 实体增删改查 + 修改Create: create_line, create_circle, create_polyline, create_rectangle, create_arc, create_ellipse, create_mtext, create_hatch
创建: create_line、create_circle、create_polyline、create_rectangle、create_arc、create_ellipse、create_mtext、create_hatch
Read: list, count, get
读取: list、count、get
Modify: copy, move, rotate, scale, mirror, offset\, array, fillet\, chamfer\*, erase
修改: copy、move、rotate、scale、mirror、offset\、array、fillet\、chamfer\*、erase
\
offset,fillet,chamferare File IPC only (not supported in ezdxf headless backend).
\offset、fillet、chamfer仅支持 File IPC(ezdxf 无头后端不支持)。
layer — Layer managementlayer — 图层管理list, create, set_current, set_properties, freeze, thaw, lock, unlock
list、create、set_current、set_properties、freeze、thaw、lock、unlock
block — Block operationsblock — 块操作| Operation / 操作 | File IPC | ezdxf |
|---|---|---|
list |
Yes / 是 | Yes / 是 |
insert |
Yes / 是 | Yes / 是 |
insert_with_attributes |
Yes / 是 | Yes / 是 |
get_attributes |
Yes / 是 | Yes / 是 |
update_attribute |
Yes / 是 | Yes / 是 |
define |
No / 否 | Yes / 是 |
annotation — Text, dimensions, leadersannotation — 文字、标注、引线create_text, create_dimension_linear, create_dimension_aligned, create_dimension_angular, create_dimension_radius, create_leader
create_text、create_dimension_linear、create_dimension_aligned、create_dimension_angular、create_dimension_radius、create_leader
pid — P&ID operations (CTO symbol library)pid — P&ID 操作(CTO 符号库)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
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
P&ID symbol insertion requires the CAD Tools Online (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.
P&ID 符号插入需要安装 CAD Tools Online(CTO)P&ID 符号库到C:\PIDv4-CTO\。ezdxf 后端内置了 CTO 库支持。对于 File IPC 后端,部分 P&ID 操作需要额外的 LISP 辅助函数 — 详见 wiki 中的 P&ID 章节了解配置细节。
view — Viewport and screenshotview — 视口与截图| Operation / 操作 | Description / 描述 |
|---|---|
zoom_extents |
Zoom to show all entities / 缩放以显示所有实体 |
zoom_window |
Zoom to a specified window / 缩放到指定窗口 |
get_screenshot |
Capture current AutoCAD view as PNG / 将当前 AutoCAD 视图截取为 PNG |
Screenshots use PrintWindow (Win32) for the File IPC backend — works even when AutoCAD is minimized or in the background. The ezdxf backend renders via matplotlib.
File IPC 后端的截图使用 PrintWindow(Win32)— 即使 AutoCAD 最小化或处于后台也能正常工作。ezdxf 后端通过 matplotlib 渲染。
system — Server managementsystem — 服务器管理status, health, get_backend, runtime, init, execute_lisp
status、health、get_backend、runtime、init、execute_lisp
execute_lispruns arbitrary AutoLISP code (File IPC only). Passdata: {code: "(+ 1 2)"}. This turns the server into an extensible automation platform — any valid AutoLISP expression can be executed.execute_lisp可运行任意 AutoLISP 代码(仅 File IPC)。传入data: {code: "(+ 1 2)"}。这使服务器成为一个可扩展的自动化平台 — 任何有效的 AutoLISP 表达式都可以被执行。
MCP Client (Claude)
│ stdio (JSON-RPC)
▼
Python MCP Server (autocad_mcp)
│
├── File IPC Backend ──► C:/temp/*.json ──► mcp_dispatch.lsp (AutoCAD LT)
│ PostMessageW(WM_CHAR) to MDIClient — no focus steal
│
└── ezdxf Backend ──► in-memory DXF (headless, no AutoCAD needed)
The 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.
File IPC 后端通过 PostMessageW(WM_CHAR) 向 AutoCAD 的 MDIClient 窗口发送按键,触发 (c:mcp-dispatch) AutoLISP 命令。这种方式不会抢占窗口焦点 — 自动化运行期间你可以继续在其他应用程序中工作。
| Variable / 变量 | Default / 默认值 | Description / 描述 |
|---|---|---|
AUTOCAD_MCP_BACKEND |
auto |
Backend selection: auto, file_ipc, ezdxf / 后端选择:auto、file_ipc、ezdxf |
AUTOCAD_MCP_IPC_DIR |
C:/temp |
Directory for IPC command/result JSON files (must match on both Python and LISP sides) / IPC 命令/结果 JSON 文件目录(Python 端和 LISP 端必须一致) |
AUTOCAD_MCP_IPC_TIMEOUT |
10.0 |
IPC command timeout in seconds (1-300) / IPC 命令超时时间(秒,1-300) |
AUTOCAD_MCP_ONLY_TEXT |
false |
Disable screenshot capture (text feedback only) / 禁用截图捕获(仅文本反馈) |
Note: If you change
AUTOCAD_MCP_IPC_DIR, you must also update themcp-ipc-dirvariable inmcp_dispatch.lspto match.
注意: 如果你更改了AUTOCAD_MCP_IPC_DIR,还必须同步更新mcp_dispatch.lsp中的mcp-ipc-dir变量以保持一致。
uv sync
uv run pytest tests/ -v
AutoLISP was added to AutoCAD LT in the 2024 release (Windows only). AutoCAD LT for Mac does not support AutoLISP.
AutoLISP 是在 2024 版本(仅 Windows) 中被加入 AutoCAD LT 的。AutoCAD LT for Mac 不支持 AutoLISP。
| Supported (LT 2024+ Windows) / 支持(LT 2024+ Windows) | Not Supported / 不支持 |
|---|---|
.lsp / .fas / .vlx / .dcl |
VLIDE (Visual LISP IDE) |
All vl- utility functions / 所有 vl- 工具函数 |
vlax-* (ActiveX/COM) |
File I/O (open, read-line, etc.) / 文件 I/O(open、read-line 等) |
Express Tools |
Entity access (entget, entmod, etc.) / 实体访问(entget、entmod 等) |
3D operations / 3D 操作 |
| Selection sets / 选择集 | AutoLISP on Mac / Mac 上的 AutoLISP |
The mcp_dispatch.lsp dispatcher is fully compatible with LT 2024+.
mcp_dispatch.lsp 调度器与 LT 2024+ 完全兼容。
execute_lisp — Run arbitrary AutoLISP code via temp file paexecute_lisp — 通过临时文件路径运行任意 AutoLISP 代码23f1aea464fcc50c86a466b2f9db438acb4c9b42ac18d81272f9804800bce68b