autocad-mcp

autocad-mcp

Enables automation of AutoCAD LT and headless DXF creation through two backends (File IPC for Windows AutoCAD LT and ezdxf for cross-platform) with tools for drawing, entity, layer, block, annotation, PID, view, and system operations.

Category
访问服务器

README

AutoCAD MCP Server

Máy chủ MCP cho tự động hóa AutoCAD LTtạo DXF headless.

Hai backend, một API:

Backend Runtime Cần AutoCAD? Screenshot
File IPC Windows Python Có — AutoCAD LT 2024+ (Windows) Win32 PrintWindow
ezdxf Mọi nền tảng Không (headless) matplotlib render

Server cung cấp 8 công cụ chính (drawing, entity, layer, block, annotation, pid, view, system) thông qua MCP stdio transport.

Một MCP client (Claude Desktop, Claude Code, v.v.) có thể kết nối và điều khiển AutoCAD bằng yêu cầu ngôn ngữ tự nhiên.


Prerequisites (Backend File IPC)

Yêu cầu:

  • Windows 10/11
    (Backend File IPC dùng Win32 API để gửi message tới cửa sổ mà không cần focus)

  • AutoCAD LT 2024 trở lên
    AutoLISP được hỗ trợ từ LT 2024 trên Windows.

    ⚠ AutoCAD LT cho Mac không hỗ trợ AutoLISP.

  • Python 3.10+
    (Python chạy native trên Windows — không dùng WSL Python)

  • uv package manager

Cài đặt:

https://docs.astral.sh/uv/getting-started/installation/


💡 Backend ezdxf headless chạy được trên:

  • Linux
  • macOS
  • WSL

không cần AutoCAD, chỉ dùng để tạo file DXF offline.


Quick Start

1. Clone và cài đặt

git clone https://github.com/ks40-academy/autocad-mcp.git
cd autocad-mcp
uv sync

2. Load LISP dispatcher trong AutoCAD LT

Mở AutoCAD LT và load file:

mcp_dispatch.lsp

bằng lệnh APPLOAD

Các bước:

  1. APPLOAD trong command line
  2. Chọn file
<repo>/lisp-code/mcp_dispatch.lsp
  1. Nhấn Load

Nếu thành công sẽ thấy:

=== MCP Dispatch v3.1 loaded ===
Ready for commands via (c:mcp-dispatch)

💡 Mẹo

Thêm file này vào Startup Suite trong APPLOAD để AutoCAD tự load khi mở bản vẽ.


3. Cấu hình MCP client

Ví dụ cấu hình trong:

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

Lưu ý quan trọng

  • command phải trỏ tới Windows Python trong venv
  • Không dùng WSL Python

Chạy từ WSL

Nếu MCP client chạy trong WSL (ví dụ Claude Code):

khởi động server thông qua cmd.exe

{
  "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. Kiểm tra hoạt động

Từ MCP client gọi:

system(operation="status")

Kết quả:

backend: "file_ipc"

nếu AutoCAD đang chạy

hoặc

backend: "ezdxf"

nếu chạy chế độ headless.


Tools

drawing — Quản lý file bản vẽ

Operation Mô tả File IPC ezdxf
create Reset bản vẽ sạch Yes Yes
open Mở bản vẽ Yes Yes (DXF)
info Thông tin entity và layer Yes Yes
save Lưu bản vẽ Yes Yes
save_as_dxf Xuất DXF Yes Yes
plot_pdf Xuất PDF Yes No
purge Xóa đối tượng không dùng Yes Yes
get_variables Lấy biến hệ thống Yes Yes
undo Hoàn tác Yes No
redo Làm lại Yes No

entity — Quản lý đối tượng

Tạo

  • create_line
  • create_circle
  • create_polyline
  • create_rectangle
  • create_arc
  • create_ellipse
  • create_mtext
  • create_hatch

Đọc

  • list
  • count
  • get

Chỉnh sửa

  • copy
  • move
  • rotate
  • scale
  • mirror
  • offset*
  • array
  • fillet*
  • chamfer*
  • erase

offset, fillet, chamfer chỉ dùng với File IPC.


layer — Quản lý layer

  • list
  • create
  • set_current
  • set_properties
  • freeze
  • thaw
  • lock
  • unlock

block — Thao tác 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 — Chú thích

  • create_text
  • create_dimension_linear
  • create_dimension_aligned
  • create_dimension_angular
  • create_dimension_radius
  • create_leader

pid — P&ID

Thư viện ký hiệu CTO.

Các lệnh:

  • 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

⚠ Cần cài thư viện:

https://www.cadtoolsonline.com/

vào thư mục

C:\PIDv4-CTO\

view — Viewport & Screenshot

Operation Mô tả
zoom_extents Zoom toàn bộ
zoom_window Zoom theo cửa sổ
get_screenshot Chụp ảnh AutoCAD

File IPC dùng:

PrintWindow (Win32)

Có thể chụp ngay cả khi AutoCAD bị minimize.

ezdxf dùng:

matplotlib render

system — Quản lý server

  • status
  • health
  • get_backend
  • runtime
  • init
  • execute_lisp

execute_lisp

Chạy AutoLISP bất kỳ:

Ví dụ

(+ 1 2)

Gửi:

data: {code: "(+ 1 2)"}

Biến server thành nền tảng automation mở rộng.


Architecture

MCP Client (Claude)
        │
        │ stdio (JSON-RPC)
        ▼
Python MCP Server (autocad_mcp)
        │
        ├── File IPC Backend
        │       │
        │       └── C:/temp/*.json
        │               │
        │               ▼
        │        mcp_dispatch.lsp (AutoCAD)
        │
        └── ezdxf Backend
                │
                ▼
           in-memory DXF

File IPC gửi keystrokes tới AutoCAD bằng:

PostMessageW(WM_CHAR)

Ưu điểm:

  • Không cướp focus cửa sổ
  • Có thể làm việc ứng dụng khác song song.

Environment Variables

Variable Default Mô tả
AUTOCAD_MCP_BACKEND auto chọn backend
AUTOCAD_MCP_IPC_DIR C:/temp thư mục IPC
AUTOCAD_MCP_IPC_TIMEOUT 10 timeout
AUTOCAD_MCP_ONLY_TEXT false tắt screenshot

⚠ Nếu đổi:

AUTOCAD_MCP_IPC_DIR

phải sửa luôn biến:

*mcp-ipc-dir*

trong file

mcp_dispatch.lsp

Development

uv sync
uv run pytest tests/ -v

AutoCAD LT AutoLISP Compatibility

AutoLISP được thêm vào AutoCAD LT 2024 (Windows).

Hỗ trợ Không hỗ trợ
.lsp VLIDE
vl-* functions vlax-*
File I/O Express Tools
entget 3D operations
selection sets AutoLISP trên Mac

What's New v3.1

Các cập nhật chính:

  • execute_lisp
  • undo / redo
  • open drawing
  • create drawing reset
  • save path
  • get_variables fix
  • polyline fix
  • ESC prefix
  • UTF8 fallback
  • IPC timeout config
  • thread-safe init

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选