dxf-cad-mcp
Summary: A lightweight MCP server that lets AI agents create, edit, inspect, preview, export, and measure 2D DXF CAD drawings without a CAD GUI.
Create DXF files in versions R12–R2018, defaulting to R2010.
Draw 2D entities: lines, polylines, rectangles, circles, arcs, ellipses, points, text, and mtext.
Add dimensions: linear, aligned, radius, diameter, and angular, returning measured values.
Add hatches using solid fills or standard patterns, plus splines and blocks/inserts.
Create and update layers with colors and linetypes; README also advertises layer state controls (on/frozen/locked).
Inspect drawings: DXF version, entity counts and types, bounding box, and layers; README also supports DWG reads via LibreDWG.
Render PNG previews and export vector PDFs with auto or A4/A3/A2 page sizing.
Open DXF or DWG files in local AutoCAD on macOS.
README additionally lists query/delete/modify/restore with backups, DXF-to-DWG conversion, text styles, roof intersection solving and three-view projection, area measurement with text association, and CSV export for verification.
Provides a tool to open generated DXF or DWG drawings directly in a local AutoCAD installation on macOS, automatically locating AutoCAD applications under /Applications/Autodesk and preferring full versions.
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., "@dxf-cad-mcp draw a 120x80 plate with 4 corner holes, dimension it, then render a PNG preview"
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.
dxf-cad-mcp
轻量级 DXF CAD MCP 服务器:让任何 AI agent(Claude / dsh / Cursor …)通过 MCP 协议 画工程图,不依赖 CAD 图形界面。
创建 DXF → 绘制实体/标注/填充/图块 → 图层管理 → 检查图纸
→ 面积测量 / 数据导出 → 屋面交线求解 → PNG 预览 / PDF 导出
→ 一键打开到 CAD跨平台:macOS / Windows / Linux 均可运行(DXF 是 Autodesk 公开规范的交换格式)
纯本地:ezdxf + matplotlib,不需要网络,不需要 CAD 授权即可生成图纸
DWG 输出:
dxf_convert_dwg一键 DXF→DWG(LibreDWG,DWG 是专有格式,ezdxf 写不了)macOS + AutoCAD 友好:内置中文字体(.ttc)与 "白/黑" 双色(ACI 7)渲染修复
为什么走 DXF 路线
AutoCAD for Mac 没有 AppleScript / COM / .NET 接口,直接操控 UI 不可行 (Windows 上的 CAD MCP 项目大多依赖 COM,难以移植)
DXF 是公开交换格式:ezdxf 纯本地读写,生成的图纸任何 CAD 软件都能打开 (AutoCAD / LibreCAD / QCAD / FreeCAD …)
"以文件为中心" 的架构:稳定、可验证、可回放——PNG/PDF 预览与 CAD 终显互相对照
Related MCP server: aspicio-dxf-viewer
特性
21 个 MCP 工具,覆盖完整 2D 绘图 + 编辑 + 测量/核对工作流(见下表)
量与核:
dxf_area识别闭合区域算面积并把区域内文字关联到区域 (支持 DWG、墙体双线+门洞桥接、楼层/房间级核对);dxf_extract把 实体批量导出 CSV 供 Excel 核对屋面交线:
dxf_roof_solve/dxf_roof_three_view同坡屋面交线求解与 三面投影(第一角法),纸面坐标可直接喂dxf_draw图层状态控制:关闭(不显示不打印)/ 冻结(不显示且不参与重生成)/ 锁定(显示但不能编辑),渲染预览与 AutoCAD 行为一致
编辑闭环:
dxf_query定位 →dxf_modify/dxf_delete修改 → 自动滚动备份(.bak1~.bak5)→dxf_restore一键回滚,所有改文件的 工具(含绘制类)落盘前自动备份9 种基础实体 + 5 种尺寸标注 + 27 种标准填充图案 + 样条 + 图块
颜色三种写法:ACI 数字 / 颜色名(
"red")/#RRGGBB真彩色内置标准线型:Dashed / Center / Hidden / Phantom / Dashdot
PNG 预览 + 矢量 PDF 导出(auto 自适应或 A4/A3/A2 横版)
中文渲染:启动时自动注册系统 CJK 字体,中文标注/文字预览不空白
工具列表(21 个)
工具 | 说明 |
| 创建空 DXF(版本 R12~R2018,默认 R2010) |
| 追加实体:line / polyline / rectangle / circle / arc / ellipse / point / text / mtext;文件不存在自动创建,引用的图层自动创建 |
| 追加尺寸标注:linear / aligned / radius / diameter / angular;返回每个标注的实测值 |
| 追加填充:solid 实底 / ANSI31 等标准图案;闭合多边形边界 |
| 追加样条线(过拟合点集的 2/3 阶样条) |
| 定义图块(内含 |
| 创建/更新/重命名/删除图层(颜色:ACI 数字 / 颜色名 / #RRGGBB;线型:Continuous/Dashed/Center/Hidden/Phantom/Dashdot;状态: |
| 检查图纸(DXF / DWG 均支持):版本、实体统计、类型分布、包围盒、图层(含开关/冻结/锁定状态与颜色);DWG 经 LibreDWG 自动转读 |
| 查找实体(按类型/图层/handle/文字子串),返回 handle + 类型 + 图层 + 摘要;编辑类工具的前置定位 |
| 删除实体(handle/类型/图层;删 DIMENSION 时同步清空其 *D 图形块) |
| 修改实体:图层/颜色/线型/文字内容 + 移动/绕点旋转/绕点缩放 |
| 从自动滚动备份(.bak1 最新 ~ .bak5 最旧)恢复文件 |
| 渲染 PNG 预览(ezdxf + matplotlib,不需要打开 CAD) |
| 导出矢量 PDF(线条/文字保持矢量,可 auto 自适应或 A4/A3/A2 横版) |
| DXF → DWG 转换(LibreDWG dxf2dwg,纯本地;版本 r12/r14/r2000/r2004,默认 r2000) |
| 用 macOS |
| 创建/更新/删除文字样式(中文显示正确的关键:挂宋体/黑体/楷体/仿宋/gbcbig 中文 TTF/SHX 字体) |
| 【算图】同坡屋面交线求解(纯计算):已知檐线 H 面投影 + 坡角 α,返回屋脊/檐沟 3D 交线,自动处理内凹檐线 |
| 【算图】同坡屋面三面投影(第一角法):H/V/W 纸面坐标 + 逐段可见性 + 45° 辅助线,可直接喂 |
| 【量】识别闭合区域算面积 + 文字关联(DXF/DWG):闭合折线/圆/填充直接算;LINE 墙线走 DCEL 面追踪围合房间,8 字形拆分, |
| 【核】把实体批量导出 CSV(utf-8-sig,Excel 直接打开):按类型/图层/文字过滤,含几何摘要列,供面积表核对 |
快速开始
git clone <repo-url> dxf-cad-mcp && cd dxf-cad-mcp
python3 -m venv .venv
.venv/bin/pip install -r requirements.txt # mcp<2, ezdxf, matplotlib可选:
dxf_convert_dwg依赖系统安装 LibreDWG(提供dxf2dwg命令):brew install libredwg(macOS)/apt install libredwg(Debian/Ubuntu)。 未安装时该工具返回安装提示,其余 20 个工具不受影响。dxf_read/dxf_area/dxf_extract等读取 DWG 的工具同样依赖 LibreDWG(dwg2dxf)。
或者直接作为包安装(附带 dxf-cad-mcp 命令):
pip install . # 或 pipx install .不经 MCP 先试一把(生成一张带标注/填充/图块的示例图):
.venv/bin/python examples/quickstart.py
# 输出 examples/quickstart.dxf / .png / .pdf接入 MCP 客户端
服务器使用 stdio 传输,在任何支持 MCP 的客户端里配置命令行即可。
dsh(~/.dsh/profiles/web/cordis.patch.yml):
- insert:
- id: mcp-dxf-cad
name: '@deepseek-ai/dsh-mcp-client'
config:
serverName: dxf-cad
transport: stdio
command: /path/to/dxf-cad-mcp/.venv/bin/python
args: ['/path/to/dxf-cad-mcp/server.py']
cwd: /path/to/dxf-cad-mcp
toolCallTimeoutMs: 120000通用 MCP 客户端(Claude Desktop / Cursor 等):
{
"mcpServers": {
"dxf-cad": {
"command": "/path/to/dxf-cad-mcp/.venv/bin/python",
"args": ["/path/to/dxf-cad-mcp/server.py"]
}
}
}dsh skill
skills/dxf-cad/SKILL.md 把本项目的量算配方沉淀成 dsh skill:房产图
layer=墙体 + close_gap=2500 参数模板、单位判断(mm vs 测绘米坐标)、
多楼层按 x 范围分层的汇总方法、与测绘权威表对照的偏差归因、21 工具速查
与已知陷阱。在 dsh 里说「量 CAD 图面积 / 核对图纸和测绘表」即会触发。
注册(源码在本仓库,软链到用户级 skill 根,改仓库即生效):
ln -s /path/to/dxf-cad-mcp/skills/dxf-cad ~/.agents/skills/dxf-cad测试
.venv/bin/python test_client.py # 端到端(第一批):基础实体 + 渲染
.venv/bin/python test_client2.py # 端到端(第二批):标注/填充/样条/图块 + PDF
.venv/bin/python test_client3.py # 端到端(量与核):面积追踪/文字关联/CSV/DWG/实测房产图test_client3.py 含 8 个 section、56 项断言:闭合折线/圆/填充直接面积、
T 形节点房间追踪、120×90 网格 900 格、dxf_extract CSV、真实 DWG(弘毅1)、
悬臂线段、以及继教学院 7 层实测房产图(墙体双线+门洞桥接,楼层轮廓与
继教学院房产面积计算表(修正版).docx 逐层对照:2/5/7 楼轮廓与 6 个房间
面积精确到 0.01)。实测 DWG 不在本机时自动跳过该 section。
测试产物输出到 test_output/(已 gitignore)。
已知限制
仅 2D:无参数化实体/约束/动态块(DXF 格式本身不含这些数据)
DXF 写入版本最高 R2018(AC1032),AutoCAD 2018+ 均可读取
标注预览使用 ezdxf 简化渲染器,与 CAD 显示可能有差异(AutoCAD 打开时按 定义点重新渲染,以 CAD 显示为准)
标注预览颜色:
*D几何块实体默认 ByBlock,预览按块所在图层(0)解析, 放在彩色标注层的标注预览仍显示白色——给*D块实体设显式颜色即可让 预览跟随;AutoCAD 中按 ByLayer 渲染,终显正确填充边界仅支持闭合多边形(圆形/弧线边界暂不支持)
仅 model space;布局/图纸空间未实现
dxf_convert_dwg/ DWG 读取走 LibreDWG 开源实现,成熟度低于 Autodesk 官方: MATERIAL / MLEADERSTYLE 等专有对象自动跳过(不影响几何);转换前会把 MTEXT 旋转角归零(绕开 LibreDWG 解析 bug),AutoCAD 打开后标注文字按定义点重渲染, 显示不受影响LibreDWG 0.14 的 r2004 往返不完整(转出 DXF 缺 EOF,读回即失败):
dxf_convert_dwg会回读验证并标verified=false,dxf_read返回明确错误; DWG 转换/读取建议用 r2000dxf_open_in_autocad仅 macOS(依赖open命令)mcp SDK 固定
<2:2.x 把 FastMCP 改名 MCPServer,与 v1 客户端生态不兼容dxf_area墙线追踪假设:线段在端点处相接(T 形/X 形交叉自动拆开、重合边 自动合并)。门洞(墙体双线在门洞处断开、门两侧本应连通)需用close_gap桥接,否则相邻房间会合并成一个大面;轴线/楼梯踏步/尺寸线 等非墙体线会切断房间,用layer或exclude_layers只留墙体线。 自交区域报带符号净面积并标self_intersecting=true;theta 形(两节点间 三条边)可能只追踪到部分区域dxf_area面积单位 = 绘图单位²:mm 绘图 ÷1e6 = m²;测绘米坐标图 (坐标量级 ~1e6)面积即 m²,无需换算
项目结构
dxf-cad-mcp/
├── server.py # MCP 服务器(21 个工具:绘图/编辑/测量/核对/屋面)
├── examples/
│ └── quickstart.py # 直调示例(无需 MCP 协议)
├── test_client.py # 端到端测试(第一批)
├── test_client2.py # 端到端测试(第二批)
├── test_client3.py # 端到端测试(量与核 + 实测房产图对照)
├── skills/dxf-cad/ # dsh skill:量算配方(软链注册到 ~/.agents/skills)
├── 修复记录/ # 每次修复/更改的带日期 md 记录(README.md 为索引)
├── requirements.txt
├── pyproject.toml
├── LICENSE # MIT
└── README.md修复记录
详见 修复记录/(每次修复/更改的带日期记录)。
License
Available Tools
11 toolsdxf_blocksA
定义图块(BLOCK)并向图纸插入图块引用(INSERT);文件不存在时自动创建。
blocks: 图块定义列表,每个: name (必填) 图块名(已存在同名图块会报错) base_point 插入基准点(可选,默认 [0,0]) entities (必填) 图块内实体,格式与 dxf_draw 的 entities 完全相同 (line/polyline/rectangle/circle/arc/ellipse/point/text/mtext)
refs: 图块引用列表(可省略),每个: block (必填) 图块名 insert (必填) 插入点 [x,y] rotation 旋转角度(可选,度) x_scale / y_scale 缩放(可选,默认 1) layer / color 公共可选字段
Inputs: path (required), refs, blocks, dxfversion.
dxf_createA
创建一个新的空 DXF 文件。
Args: path: 输出文件完整路径(.dxf)。 dxfversion: DXF 版本,可选 R12/R13/R14/R2000/R2004/R2007/R2010/R2013/R2018, 默认 R2010(兼容性最好的常用版本;AutoCAD 2024 全部支持)。 给老软件用就选更老的版本。
Inputs: path (required), dxfversion.
dxf_dimensionsA
向 DXF 图纸追加尺寸标注;文件不存在时自动创建。
每个标注是一个 dict,公共可选字段:layer、color、dimstyle(默认 "Standard")、 text(自定义标注文字,不传则显示实测值)。
标注类型与必填字段(坐标单位与绘图一致): linear: p1, p2, location[标注线位置点, 可选], angle(0=水平标注, 90=垂直) aligned: p1, p2, location[标注线位置点, 可选] radius: center, radius, angle(引线方向, 度, 可选), location(可选) diameter: center, radius, angle(可选), location(可选) angular: center, p1, p2[两条射线的端点], location(标注弧位置点, 可选, 不传则画在角平分线上)
返回值含每个标注的实测测量值(measurement),可直接核对。 注意:标注的预览渲染是 ezdxf 的简化实现,与 AutoCAD 的显示可能有差异 (例如 angular 预览可能显示补角);打开 AutoCAD 后 CAD 会按定义点 重新渲染,以 CAD 显示为准。
Inputs: dims (required), path (required), dxfversion.
dxf_drawA
向 DXF 图纸追加 2D 实体;文件不存在时自动创建。
每个实体是一个 dict,公共可选字段:layer(图层名,默认 0)、 color(ACI 数字 / 颜色名如 "red" / "#RRGGBB")。
实体类型与必填字段: line: start, end polyline: points[[x,y],...], closed(bool, 默认 false) rectangle: corner[x,y], width, height circle: center[x,y], radius arc: center[x,y], radius, start_angle, end_angle(度, 逆时针) ellipse: center[x,y], major_radius, ratio(0~1), rotation(度, 可选) point: point[x,y] text: point[x,y], text, height, rotation(度, 可选) mtext: point[x,y], text, char_height, width(可选)
Inputs: path (required), entities (required), dxfversion.
dxf_export_pdfA
把 DXF 导出为矢量 PDF(线条/文字保持矢量,可无限放大,适合打印归档)。
Args: path: 源 DXF 文件。 pdf_path: 输出 PDF 路径。 background: 背景色,"white"/"black"/"dark" 或 #RRGGBB。 page_size: "auto"(默认,按图纸包围盒自适应)或 "A4"/"A3"/"A2"(横版)。
Inputs: path (required), pdf_path (required), page_size, background.
dxf_hatchA
向 DXF 图纸追加填充(HATCH);文件不存在时自动创建。
每个填充是一个 dict: points (必填) 闭合多边形边界顶点 [[x,y],...](按序首尾自动闭合) pattern "solid"(实底,默认)或标准图案名,如 "ANSI31"(斜线)、 "ANSI32"、"CROSS"(网格)、"DOTT"/"DOTS"、"NET"、"GRAVEL"、 "BRICK"、"AR-CONC"(混凝土)、"TRUSS"(桁架)、"WAVES" 等 scale 图案缩放(默认 1.0,越大线越疏) angle 图案旋转角度(默认 0) layer / color 公共可选字段
注意:圆形/弧线边界暂不支持(仅多边形边界);复杂边界建议拆成多个填充。
Inputs: path (required), hatches (required), dxfversion.
dxf_layersB
创建或更新图层。
每个图层: {name(必填), color(可选, 同 color 规则), linetype(可选, 如 "Continuous"/"Dashed"/"Center"/"Hidden")}. 文件不存在时先创建。
Inputs: path (required), layers (required).
dxf_open_in_autocadB
把 DXF(或 DWG)文件打开到本机的 AutoCAD(macOS open 调用)。
Args: path: 要打开的图纸文件。 prefer: 可选,指定优先使用的 .app 路径(默认自动选择 /Applications/Autodesk 下的 AutoCAD,完整版优先)。
Inputs: path (required), prefer.
dxf_readB
检查一张 DXF 图纸:DXF 版本、实体总数与类型分布、包围盒、图层列表。
Inputs: path (required).
dxf_renderA
把 DXF 渲染成 PNG 预览图(纯本地,不需要打开 AutoCAD)。
Args: path: 源 DXF 文件。 png_path: 输出 PNG 路径。 dpi: 分辨率,默认 150(100~300)。 background: 背景色,"white"/"black"/"dark" 或 #RRGGBB。
Inputs: path (required), png_path (required), dpi, background.
dxf_splinesB
向 DXF 图纸追加样条线(SPLINE);文件不存在时自动创建。
每个样条是一个 dict: points (必填) 拟合点 [[x,y],...](≥3 个,样条穿过这些点) degree 样条阶数,2 或 3(默认 3) layer / color 公共可选字段
Inputs: path (required), splines (required), dxfversion.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 11 tools
Each tool targets a distinct operation: creation, entity drawing, dimensions, hatching, splines, blocks, layers, reading, and three separate output targets (PNG/PDF/AutoCAD). The only minor overlap is dxf_create vs dxf_draw (draw auto-creates), but their intent is clearly separated in the descriptions.
All tools share a consistent dxf_ prefix, but the suffix convention is mixed: some use verbs (dxf_create, dxf_draw, dxf_read, dxf_render) while others use plural nouns (dxf_dimensions, dxf_splines, dxf_hatch, dxf_blocks, dxf_layers). Still readable and predictable enough overall.
11 tools is well-scoped for a DXF manipulation server, with each tool covering a distinct CAD concept or output format. No bloat and no obviously trivial tools.
The server covers creation, drawing, annotation, blocks, layers, inspection, and export well, but it is append-only: there is no way to modify or delete existing entities or layers, and hatch boundaries cannot be circular/arc. These are notable gaps for iterative CAD editing workflows.
Maintenance
Related MCP Connectors
DXF and PDF/X-4 for AI agents: structured facts, PNG renders, an interactive in-chat viewer.
Read, query, edit and render DWG drawings with AI. No AutoCAD required.
Parametric 3D CAD for AI agents: build print-ready parts, check them, export STL, 3MF or STEP.
Build, check, and export parametric CAD models in your ForgeCAD Projects from your AI agent.
Related MCP Servers
- AlicenseBqualityDmaintenanceEnables AI agents to automate AutoCAD LT and create DXF files headless, with tools for drawing, entity, layer, block, annotation, PID, and system operations.16MIT
- AlicenseNot gradedqualityBmaintenanceOpens, inspects, and renders DXF/CAD drawings for AI agents: describe_dxf returns structured facts (layers with actual drawn colors, units, bounds, text content) and render_dxf returns PNG images. On MCP Apps hosts like ChatGPT and Claude, view_dxf opens an interactive in-chat viewer with pan, zoom, and layer toggles.6MIT
- 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 create, edit, and analyze CAD drawings either live through AutoCAD COM on Windows or headlessly via ezdxf anywhere, drawing mechanical parts, architectural plans, and P&IDs with ISO standard layers, dimensions, fits, and title blocks. It also reads existing drawings back for critique, diffing, scale checks, topology checks, and bill-of-material takeoffs to Excel or CSV.-