autocad-mcp
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@autocad-mcp Draw a line from (0,0) to (10,10)"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
AutoCAD MCP Server
Máy chủ MCP cho tự động hóa AutoCAD LT và tạo DXF headless.
Một API, hai backend vẽ và hai transport kết nối:
Tùy chọn | Ghi chú | |
Backend | File IPC | Windows + AutoCAD LT 2024+; điều khiển qua ActiveX/COM + AutoLISP |
ezdxf | Mọi nền tảng; DXF in-memory, không cần AutoCAD | |
Transport | stdio (mặc định) | Claude Desktop, Claude Code, client MCP cục bộ |
streamable-http | ChatGPT Developer mode / remote MCP qua HTTPS tunnel |
Server cung cấp 8 công cụ (drawing, entity, layer, block, annotation, pid, view, system) với dispatch theo operation. Phiên bản runtime: 3.1 (LISP dispatcher reliability v3.2).
Prerequisites
Backend File IPC (AutoCAD thật)
Windows 10/11 (không dùng WSL Python cho File IPC)
AutoCAD LT 2024+ trên Windows — AutoLISP chỉ có từ LT 2024; AutoCAD LT cho Mac không hỗ trợ AutoLISP
Python 3.10+ (native Windows)
uv package manager
Backend ezdxf (headless)
Chạy trên Linux, macOS, WSL hoặc Windows — không cần AutoCAD, chỉ tạo/sửa DXF offline.
Related MCP server: AutoCAD MCP Server
Quick Start
1. Clone và cài đặt
git clone https://github.com/sontakmtp-cell/autocad-mcp.git
cd autocad-mcp
uv sync2. Auto-load LISP dispatcher (mỗi document)
State AutoLISP thuộc từng bản vẽ. Load mcp_dispatch.lsp một lần không đủ khi mở/tạo DWG mới. Cấu hình startup theo document:
Thêm
<repo>/lisp-codevào Support File Search Path.Thêm cùng thư mục vào
TRUSTEDPATHS. Không tắtSECURELOAD.Copy
lisp-code/acadltdoc.lsp.examplethànhacadltdoc.lsptrong một Support File Search Path.Restart AutoCAD LT, mở bản vẽ. Mỗi document nên in:
=== MCP Dispatch v3.2 reliability overrides loaded ===Example dùng (findfile "mcp_dispatch.lsp") rồi (load ...), không hard-code path máy. Startup Suite / APPLOAD lặp lại không cần. Nếu document đang active thiếu dispatcher, MCP báo dispatcher_missing_in_active_document — server không tự mở APPLOAD.
3. Cấu hình MCP client (stdio)
Ví dụ 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" }
}
}
}commandphải trỏ tới Windows Python trong venvKhông dùng WSL Python khi cần File IPC
Client chạy trong WSL
Khởi động server qua cmd.exe + Windows Python:
{
"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
Từ MCP client:
system(operation="status")backend: "file_ipc"— AutoCAD đang chạy và được phát hiệnbackend: "ezdxf"— chế độ headless
Diagnostics bổ sung:
system(operation="health")
system(operation="tool_manifest")
system(operation="runtime")Transport HTTP (ChatGPT / remote)
Transport mặc định vẫn là stdio. Để mở MCP qua mạng:
Profile | Auth | Mục đích |
| — | Chỉ local; stdio hoặc HTTP không remote policy |
| No Auth ( | Demo ngắn hạn, chỉ operation đọc allowlist |
| OAuth 2.1 / OIDC | Remote thật (ChatGPT, tunnel HTTPS) |
Dev demo (No Authentication)
$env:AUTOCAD_MCP_BACKEND = "ezdxf" # hoặc auto / file_ipc
$env:AUTOCAD_MCP_TRANSPORT = "streamable-http"
$env:AUTOCAD_MCP_HOST = "127.0.0.1"
$env:AUTOCAD_MCP_PORT = "8765"
$env:AUTOCAD_MCP_PATH = "/mcp"
$env:AUTOCAD_MCP_REMOTE_PROFILE = "dev"
$env:AUTOCAD_MCP_AUTH_MODE = "none"
$env:AUTOCAD_MCP_ALLOW_NO_AUTH = "1"
$env:AUTOCAD_MCP_ALLOWED_HOSTS = "127.0.0.1"
uv run python -m autocad_mcpHoặc dùng script tunnel Phase 3:
powershell -ExecutionPolicy Bypass -File .\scripts\run-phase3-dev.ps1Production OAuth + ChatGPT
Server là resource server (không tự host login). Cần OIDC provider (Auth0, Okta, Cognito, …) phát hành JWT + JWKS.
powershell -ExecutionPolicy Bypass -File .\scripts\run-phase4-oauth.ps1 `
-PublicBaseUrl "https://cad.example.com" `
-OAuthIssuer "https://issuer.example" `
-OAuthAudience "https://cad.example.com"Endpoint MCP:
https://cad.example.com/mcpMetadata:
https://cad.example.com/.well-known/oauth-protected-resourceScopes:
autocad.read,autocad.writeexecute_lispmặc định bị chặn trên mọi remote profile; chỉ bật khi setAUTOCAD_MCP_ALLOW_EXECUTE_LISP=1(rủi ro cao — AutoLISP tùy ý trên máy host)
Kết nối ChatGPT (Windows — khuyến nghị)
ChatGPT gọi MCP qua HTTPS công khai. MCP chỉ bind 127.0.0.1:8765; cần Cloudflare named tunnel (không dùng Quick Tunnel *.trycloudflare.com cho OAuth domain cố định).
Cài cloudflared (một lần):
winget install --id Cloudflare.cloudflaredMỗi phiên làm việc — 2 cửa sổ:
Cửa sổ | File | Việc |
1 |
| MCP OAuth production trên |
2 |
| Login Cloudflare (lần đầu) → tạo tunnel/config/DNS → |
start_cloudflare_tunnel.bat gọi scripts/setup-cloudflare-tunnel.ps1:
Mở browser / in link Cloudflare login nếu chưa có
~\.cloudflared\cert.pemChọn zone domain (ví dụ
kythuatvang.com) → AuthorizeTạo/chọn named tunnel, ghi
config.yml(hostname→http://127.0.0.1:8765)Route DNS (ghi đè record cũ bằng CNAME tunnel nếu cần)
Chạy tunnel (giữ cửa sổ mở)
URL gắn vào ChatGPT Developer mode (OAuth):
https://cad.kythuatvang.com/mcp(Wrapper start_mcp_chatgpt.bat đang cấu hình site-specific cho domain/issuer Auth0 của repo này — chỉnh bat/script nếu dùng domain khác.)
Kiểm tra public trước khi connect ChatGPT:
curl.exe -sS -i "https://cad.kythuatvang.com/.well-known/oauth-protected-resource"
# kỳ vọng: 200 + JSON scopes/issuer
curl.exe -sS -i "https://cad.kythuatvang.com/mcp"
# kỳ vọng: 401 khi chưa có token (OAuth bật)HTTP | Ý nghĩa |
530 | Tunnel chưa |
502 | Tunnel OK nhưng MCP ( |
401 trên | Đúng — client phải login OAuth |
200 metadata | Resource server reachable |
Tuỳ chọn PowerShell:
# Chỉ setup, không giữ tunnel
powershell -ExecutionPolicy Bypass -File .\scripts\setup-cloudflare-tunnel.ps1 -SkipRun
# Hostname / tunnel name tuỳ chỉnh
powershell -ExecutionPolicy Bypass -File .\scripts\setup-cloudflare-tunnel.ps1 `
-Hostname "cad.example.com" -TunnelName "autocad-mcp"Chi tiết OAuth/policy: docs/phase2-remote-policy.md, docs/phase4-oauth.md, docs/ke-hoach-chatgpt-http-bridge.md.
AUTOCAD_MCP_TRANSPORT=sseđược nhận trong config nhưng chưa implement — dùngstdiohoặcstreamable-http.
Tools
Mỗi tool nhận operation (string) và thường có data (object) + include_screenshot (bool).
drawing — Quản lý file bản vẽ
Operation | Mô tả | File IPC | ezdxf |
| Bản vẽ mới / reset | Yes | Yes |
| Mở bản vẽ | Yes | Yes (DXF) |
| Extents, entity, layer, block | Yes | Yes |
| Lưu ( | Yes | Yes |
| Xuất DXF | Yes | Yes |
| Xuất PDF | Yes | No |
| Xóa đối tượng không dùng | Yes | Yes |
| Đọc biến hệ thống | Yes | Yes |
| Hoàn tác / làm lại | Yes | No |
entity — Đối tượng hình học
Tạo: create_line, create_circle, create_polyline, create_rectangle, create_arc, create_ellipse, create_mtext, create_hatch
Đọc: list, count, get
Sửa: copy, move, rotate, scale, mirror, offset*, array, fillet*, chamfer*, erase
* offset, fillet, chamfer chỉ File IPC.
layer — Layer
list, create, set_current, set_properties, freeze, thaw, lock, unlock
block — Block
Operation | File IPC | ezdxf |
| Yes | Yes |
| Yes | Yes |
| Yes | Yes |
| Yes | Yes |
| Yes | Yes |
| No | Yes |
annotation — Chú thích & auto-dimension
Cơ bản
create_textcreate_dimension_linear/aligned/angular/radiuscreate_leader
Workflow dimension tự động (part-aware)
Operation | Vai trò |
| Gom geometry 2D thành |
| Preview plan |
| Ghi plan đã duyệt (một Undo group trên File IPC) |
| Lối tắt detect → plan → commit |
| Ghi nhiều dimension một request / một Undo group |
|
|
| Kiểm tra chất lượng bố trí (read-only) |
| Sửa an toàn theo |
Selector cho plan/auto (chọn một): target_part_id | entity_ids | region | selection: "current".
Profile built-in: mechanical_mm, mechanical_inch, iso_simple. Profile tùy chỉnh mặc định lưu tại %LOCALAPPDATA%\autocad-mcp\dimension_profiles.json (hoặc AUTOCAD_MCP_DIMENSION_PROFILES).
Chi tiết và ví dụ JSON: docs/auto-dimension.md.
pid — P&ID (thư viện 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
Cần cài thư viện CAD Tools Online vào:
C:\PIDv4-CTO\view — Viewport & screenshot
Operation | Mô tả |
| Zoom toàn bộ |
| Zoom cửa sổ |
| Chụp PNG |
File IPC: Win32
PrintWindow(kể cả khi AutoCAD minimize)ezdxf: matplotlib render
system — Server
Operation | Mô tả |
| Backend, capabilities |
| Health check nhanh (có |
| Platform, Python path, backend env |
| Tools đã đăng ký, annotation ops, feature status |
| Re-init backend |
| Chạy AutoLISP tùy ý — File IPC; remote cần |
Ví dụ execute_lisp:
system(operation="execute_lisp", data={"code": "(+ 1 2)"})Architecture
MCP Client (Claude / ChatGPT / …)
│
├── stdio (JSON-RPC) ← mặc định
└── streamable-http (/mcp) ← remote + tunnel HTTPS
│
▼
remote policy / OAuth / path guard
│
▼
Python MCP Server (autocad_mcp 3.1)
│
├── File IPC Backend (Windows)
│ │ C:/temp/*session*/*request*.json
│ ▼
│ mcp_dispatch.lsp (AutoCAD LT)
│ + auto_dimension*.lsp
│
└── ezdxf Backend
▼
in-memory DXFFile IPC
Route expression whitelist qua ActiveX: ưu tiên
Document.PostCommand, fallback tường minhDocument.SendCommandKhông dùng keyboard, clipboard, focus hay
WM_CHARTrước khi gửi: kiểm tra
IsQuiescent/CMDACTIVE→autocad_busynếu user đang có lệnh (MCP không gửi ESC)Request file mang process/session ID + request ID; LISP mở đúng file đó
Mã lỗi ổn định: docs/file-ipc-error-model.md.
Checklist tay: docs/file-ipc-manual-test.md.
Environment Variables
Backend & IPC
Variable | Default | Mô tả |
|
|
|
|
| Thư mục file IPC |
|
| Timeout giây (clamp 1–300) |
| (auto) | Override COM ProgID AutoCAD đang chạy |
|
| Tắt đính kèm screenshot |
|
| Path file profile dimension tùy chỉnh |
| — | Ghi snapshot debug backend detection |
| (auto) | Nhãn entrypoint trong |
Nếu đổi AUTOCAD_MCP_IPC_DIR, cập nhật tương ứng biến *mcp-ipc-dir* trong lisp-code/mcp_dispatch.lsp.
Transport & remote
Variable | Default | Mô tả |
|
|
|
|
| Bind host HTTP |
|
| Port HTTP |
|
| Path MCP endpoint |
|
| Stateless HTTP mode |
|
|
|
|
|
|
|
| Bật No Auth (chỉ với profile |
|
| Cho phép |
| — | Host allowlist ( |
| — | Thư mục file cho open/save remote ( |
| — | Resource URL HTTPS công khai (OAuth) |
|
| Giới hạn ảnh remote (5 MB) |
| — | OIDC issuer |
| — | JWT |
|
| Scopes chấp nhận |
Development
uv sync
uv run pytest tests/ -vCI: .github/workflows/test.yml.
Script hỗ trợ:
Script | Mục đích |
| HTTP dev + Cloudflare Quick Tunnel demo (No Auth) |
| HTTP production OAuth (local |
| Login CF + named tunnel + DNS + |
| Wrapper Phase 4 OAuth (site-specific) |
| Wrapper named tunnel cho ChatGPT HTTPS |
AutoCAD LT AutoLISP Compatibility
AutoLISP có trên AutoCAD LT 2024+ (Windows).
Hỗ trợ | Không hỗ trợ |
| VLIDE, Express Tools đầy đủ, 3D nâng cao, AutoLISP trên Mac |
Một số đường dimension tối ưu dùng ActiveX khi có; xem lisp-code/auto_dimension_activex.lsp.
Documentation
Tài liệu | Nội dung |
Workflow part-aware dimension | |
Mã lỗi File IPC | |
Kiểm thử tay IPC | |
Remote allowlist / path guard | |
OAuth production + ChatGPT | |
Kế hoạch HTTP bridge tổng thể | |
Baseline phase 0 |
What's included (current)
8 tool MCP thống nhất, operation dispatch
Dual backend: File IPC + ezdxf
Dual transport: stdio + Streamable HTTP
Remote policy (dev No-Auth allowlist, production OAuth scopes)
ChatGPT path: OAuth MCP + Cloudflare named tunnel helpers (
start_cloudflare_tunnel.bat)Part-aware auto-dimension: detect → plan → commit / one-shot / audit-repair
File IPC reliability: session/request IDs, structured
error_code, per-document dispatcher probesystem.tool_manifest/runtime/healthdiagnosticsexecute_lispcho automation mở rộng (local only)Wheel packaging kèm
lisp-code(hatchlingforce-include)
License
MIT
Available Tools
9 toolsannotationA
Annotation: text, dimensions, leaders, and automatic dimension workflows.
Operations: create_text — data: {x, y, text, height?, rotation?, layer?} create_dimension_linear — data: {x1, y1, x2, y2, dim_x, dim_y} create_dimension_aligned — data: {x1, y1, x2, y2, offset} create_dimension_angular — data: {cx, cy, x1, y1, x2, y2} create_dimension_radius — data: {cx, cy, radius, angle} create_leader — data: {points: [[x,y],...], text} detect_parts — read-only geometry clustering; data: {source_layers?, gap_tolerance?, include_screenshot?} plan_dimensions — preview a plan without editing; data: {target_part_id?, entity_ids?, region?, region_mode?, selection?, use_current_selection?, source_layers?, profile?, dimension_layer?, include_overall?, include_features?, include_holes?, include_arcs?, include_centers?, clear_existing?} commit_dimension_plan — commit an approved plan; data: {plan_id, expected_revision, ...} auto_dimension — detect, plan, and commit in one request. It accepts target_part_id, entity_ids, region, region_mode, selection='current' or use_current_selection, source_layers, dimension_layer, profile, include_overall, include_features, include_holes, include_arcs, include_centers, clear_existing, include_screenshot. batch_create_dimensions — commit data.dimensions in one request, one Undo group, and one final Regen where the backend supports it. dimension_profiles — data: {action: list|get|save|delete, ...} audit_dimensions — read-only dimension quality audit; data: {profile?, dimension_layer?, include_screenshot?} repair_dimension_layout — apply a fresh audit's safe repairs; data: {audit_id, issue_ids?, spacing?}
Automatic-dimension selectors are mutually exclusive: target_part_id, entity_ids, region, or selection='current'. Dimension results include created_count, dimension_types, selection_scope, scan counters, commit_engine, regen_count, and timings_ms when the backend can provide those values.
Performance rule: when two or more dimensions are needed, use annotation_batch_create_dimensions or annotation_auto_dimension once. Do not call create_dimension_* repeatedly.
Performance rule: pass region, entity_ids, or selection='current' whenever possible. After annotation_detect_parts, reuse geometry_cache_token together with target_part_id so the same full drawing is not exported twice.
Inputs: operation (required), data, include_screenshot. Returns: result
annotation_audit_dimensionsARead-onlyIdempotent
Find duplicates, overlap, crossings, missing intent, detached refs and style errors.
Inputs: data, include_preview. Returns: result
annotation_auto_dimensionADestructive
Plan and immediately commit dimensions for one selected part/region/entity set.
Performance rule: when two or more dimensions are needed, use annotation_batch_create_dimensions or annotation_auto_dimension once. Do not call create_dimension_* repeatedly.
Performance rule: pass region, entity_ids, or selection='current' whenever possible. After annotation_detect_parts, reuse geometry_cache_token together with target_part_id so the same full drawing is not exported twice.
Inputs: data, include_screenshot. Returns: result
annotation_batch_create_dimensionsADestructive
Create two or more dimensions in one request and one Undo group.
Use this instead of repeatedly calling annotation.create_dimension_*. data.dimensions accepts linear, diameter, radius, center, and text items in either plan-shaped form (geometry/placement) or compact coordinate form.
Inputs: data (required), include_screenshot. Returns: result
annotation_detect_partsARead-onlyIdempotent
Cluster Model Space geometry and return part_1, part_2... with an indexed preview.
Performance rule: pass region, entity_ids, or selection='current' whenever possible. After annotation_detect_parts, reuse geometry_cache_token together with target_part_id so the same full drawing is not exported twice.
Inputs: data, include_preview. Returns: result
annotation_plan_dimensionsDRead-only
Create or revise a D1/D2... plan; no AutoCAD entity is created.
Inputs: data, include_preview. Returns: result
annotation_repair_dimension_layoutCDestructive
Remove duplicates and fix safe layer/style/lane issues from a fresh audit.
Inputs: data, include_screenshot. Returns: result
drawingA
Drawing file management.
Operations: create — Create a new empty drawing. data: {name?} open — Open an existing drawing. data: {path} info — Get drawing extents, entity count, layers, blocks. save — Save current drawing. data: {path?} (saves to path if given, else QSAVE) save_as_dxf — Export as DXF. data: {path} plot_pdf — Plot to PDF. data: {path} purge — Purge unused objects. get_variables — Get system variables. data: {names: [...]} undo — Undo last operation. redo — Redo last undone operation.
Inputs: operation (required), data, include_screenshot. Returns: result
pidA
P&ID drawing with CTO symbol library.
Operations: setup_layers — Create standard P&ID layers. insert_symbol — data: {category, symbol, x, y, scale?, rotation?} list_symbols — data: {category} draw_process_line — data: {x1, y1, x2, y2} connect_equipment — data: {x1, y1, x2, y2} add_flow_arrow — data: {x, y, rotation?} add_equipment_tag — data: {x, y, tag, description?} add_line_number — data: {x, y, line_num, spec} insert_valve — data: {x, y, valve_type, rotation?, attributes?} insert_instrument — data: {x, y, instrument_type, rotation?, tag_id?, range_value?} insert_pump — data: {x, y, pump_type, rotation?, attributes?} insert_tank — data: {x, y, tank_type, scale?, attributes?}
Inputs: operation (required), data, include_screenshot. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 9 tools
Tools are mostly distinct, with annotation covering text/leaders/dimensions and specialized tools for audit, auto, batch, plan, and repair. Some overlap exists between individual dimension creation in annotation and the batch/auto tools, but performance rules help disambiguate.
All tools use snake_case, and annotation-related tools share an 'annotation_' prefix. However, patterns vary (e.g., detect_parts vs. auto_dimension), though still readable.
9 tools is well-scoped for a CAD server covering drawing management, annotation, and P&ID. Each tool has clear purpose without redundancy.
Significant gaps: no tools for basic geometry creation (lines, circles), general editing, or layer management. The server is heavily biased toward dimensions and P&ID, missing fundamental CAD operations.
Related MCP Connectors
Read, query, edit and render DWG drawings with AI. No AutoCAD required.
DXF and PDF/X-4 for AI agents: structured facts, PNG renders, an interactive in-chat viewer.
Edit AutoCAD and Revit MEP drawings from Claude or ChatGPT in plain English.
Convert, create and edit Word, PowerPoint, Excel and PDF documents from any AI agent.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceEnables natural-language control of AutoCAD LT for automation and headless DXF generation, supporting drawing, entity, layer, block, annotation, P&ID, and system operations via an MCP interface.MIT
- AlicenseAqualityDmaintenanceMCP server for AutoCAD LT automation and headless DXF generation, exposing tools for drawing, entities, layers, blocks, annotations, P&ID, and view operations via natural language.8MIT
- FlicenseNot gradedqualityAmaintenanceEnables AI agents to draft, edit, read, and validate CAD drawings either by driving a live AutoCAD session over COM or headlessly through ezdxf on any platform, spanning mechanical parts, architectural plans, P&IDs, ISO-compliant dimensioning and GD&T, and quantity takeoffs into spreadsheets.-
- FlicenseNot gradedqualityAmaintenanceEnables AI agents to drive AutoCAD either live through COM on Windows or headlessly via ezdxf on any OS, using a single typed contract across 247 tools. Supports drafting and reading mechanical, architectural and P&ID drawings with ISO GD&T and dimension-tolerance validation, standards-compliant sheets, and quantity takeoffs.-