autocad-mcp

作者 puran-water · 版本 1.0.0 · 更新于 2026-10-19 00:45 ·169.9 KB

通过 MCP 协议驱动 AutoCAD LT 的服务器,支持 File IPC 与 ezdxf 两种后端,提供绘图、实体、图层、块、标注、P&ID 符号等 8 组工具,可执行 AutoLISP 并支持无头 DXF 生成。

AutoCADMCPAutoLISPCAD绘图P&ID
2 下载11 浏览
将提示词发送给你的 AI,即可安装该 Skill
请从 https://github.com/puran-water/autocad-mcp 获取并安装 Skill:autocad-mcp。安装完成后告诉我怎么使用。

✓已通过基础校验

名称、分类、版本与作者信息完整,安装包与文档齐备。

✓可直接使用

提供 Markdown 文档与配置示例,下载后按文档说明使用即可。

Skill 详情

AutoCAD MCP Server

AutoCAD MCP 服务器

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。

Prerequisites (File IPC backend)

前置条件(File IPC 后端)

  • Windows 10/11 (the File IPC backend uses Win32 APIs for focus-free window messaging)
  • Windows 10/11(File IPC 后端使用 Win32 API 实现不抢占焦点的窗口消息传递)
  • AutoCAD LT 2024 or newer — AutoLISP support was added in LT 2024 for Windows. AutoCAD LT for Mac exists but does not support AutoLISP.
  • AutoCAD LT 2024 或更新版本 — AutoLISP 支持是在 LT 2024 for Windows 中加入的。AutoCAD LT for Mac 虽然存在,但不支持 AutoLISP。
  • Python 3.10+ (Windows native — not WSL Python)
  • Python 3.10+(Windows 原生 — 不是 WSL Python)
  • uv package manager (install guide)
  • uv 包管理器(安装指南)

The ezdxf headless backend works on any platform (Linux, macOS, WSL) for offline DXF generation without AutoCAD installed.
ezdxf 无头后端可在任意平台(Linux、macOS、WSL)上运行,无需安装 AutoCAD 即可离线生成 DXF。

Quick Start

快速开始

1. Clone and install

1. 克隆并安装

git clone https://github.com/puran-water/autocad-mcp.git
cd autocad-mcp
uv sync

2. Load the LISP dispatcher in AutoCAD LT

2. 在 AutoCAD LT 中加载 LISP 调度器

Open AutoCAD LT and load mcp_dispatch.lsp using APPLOAD:

打开 AutoCAD LT,使用 APPLOAD 加载 mcp_dispatch.lsp:

  1. Type APPLOAD in the AutoCAD command line
    在 AutoCAD 命令行中输入 APPLOAD
  2. Browse to <repo>/lisp-code/mcp_dispatch.lsp
    浏览到 <repo>/lisp-code/mcp_dispatch.lsp
  3. Click Load
    点击 Load
  4. You should see: = 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 对话框中),使其随每个图形自动加载。

3. Configure your MCP client

3. 配置你的 MCP 客户端

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:

要点:

  • The 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(仅无头模式)。

Running from WSL

从 WSL 运行

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" }
    }
  }
}

4. Verify

4. 验证

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"。

Tools

工具

drawing — File/drawing management

drawing — 文件/图形管理

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 + modification

entity — 实体增删改查 + 修改

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, chamfer are File IPC only (not supported in ezdxf headless backend).
\
offset、fillet、chamfer 仅支持 File IPC(ezdxf 无头后端不支持)。

layer — Layer management

layer — 图层管理

list, create, set_current, set_properties, freeze, thaw, lock, unlock list、create、set_current、set_properties、freeze、thaw、lock、unlock

block — Block operations

block — 块操作

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, leaders

annotation — 文字、标注、引线

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 screenshot

view — 视口与截图

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 management

system — 服务器管理

status, health, get_backend, runtime, init, execute_lisp status、health、get_backend、runtime、init、execute_lisp
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. execute_lisp 可运行任意 AutoLISP 代码(仅 File IPC)。传入 data: {code: "(+ 1 2)"}。这使服务器成为一个可扩展的自动化平台 — 任何有效的 AutoLISP 表达式都可以被执行。

Architecture

架构

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 命令。这种方式不会抢占窗口焦点 — 自动化运行期间你可以继续在其他应用程序中工作。

Environment Variables

环境变量

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 the mcp-ipc-dir variable in mcp_dispatch.lsp to match.
注意: 如果你更改了 AUTOCAD_MCP_IPC_DIR,还必须同步更新 mcp_dispatch.lsp 中的 mcp-ipc-dir 变量以保持一致。

Development

开发

uv sync
uv run pytest tests/ -v

AutoCAD LT AutoLISP Compatibility

AutoCAD LT AutoLISP 兼容性

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+ 完全兼容。

What's New in v3.1

v3.1 新特性

  • execute_lisp — Run arbitrary AutoLISP code via temp file pa
  • execute_lisp — 通过临时文件路径运行任意 AutoLISP 代码
下载后解压即可使用

文件

文件名
841ee69de88d75faa52f7279b61b6e57.zip
大小
169.9 KB
SHA256
23f1aea464fcc50c86a466b2f9db438acb4c9b42ac18d81272f9804800bce68b
来源
GitHub
存储
COS

评论

暂无评分,欢迎发表第一条评价

还没有评论,来抢沙发吧

    版本历史

    1. v1.0.0最新2026-10-19
    发表新帖 联系我们 官方QQ群
    梦马论坛-以梦为马,不负韶华

    化工人的交流乐园

    联系我们

    • 投诉建议 相关侵权、举报、投诉及建议等,请发 E-mail:admin@meng.horse