Skip to main content
Glama

cad-mcp

让 Claude Code / Codex 通过 MCP 驱动 SolidWorks 与 Creo 完成机械建模和出图。

AI 不再一步步"点 CAD":它写一份与 CAD 无关的设计规格(spec),平台负责标准查表、规则检查、出图规划,再编译成 SolidWorks / Creo 的原生模型与工程图。目标是替代非标自动化设备中工程师的日常画图工作,工程师只做审核。

项目状态:早期(v0.2)。平台核心已在模拟 CAD 上完整跑通;SolidWorks COM 执行器与 Creo 适配器已编写、尚未实机验证。详见 实现状态。

工作原理

需求 ──AI──► spec(JSON:参数、基体、孔、型腔、基准、装配、出图要求)
               │
               ├─ IR 解析       参数表达式求值、螺纹/沉孔标准展开、质量估算
               ├─ 设计规则       孔边距、破边、盲孔深度、螺纹深度、孔距、钣金折弯边距…
               ├─ 出图规划       图幅比例、GB 第一角布局、坐标尺寸、孔标注、技术要求、标题栏、明细表
               │
               └─ 适配器编译 ──► SolidWorks(COM)/ Creo(CREOSON + TOOLKIT)/ Mock(任意平台)
                                   └─ 回读再生错误、实测质量 → 与 spec 对账
  • 一份 spec,两种 CAD:同一描述编译到 SolidWorks 或 Creo。

  • 参数化与关联更新:改一个参数,零件、引用它的装配和图纸自动重建。

  • 不破坏原始数据:所有修改在隔离工作区进行,支持检查点与回滚;发布版本不可覆盖;新版本 CAD 默认只读打开旧版本文件。

  • 多版本共存:SolidWorks 2022/2024/2026 用带版本号的 ProgID 精确连接,Creo 7/9/10 各配独立 CREOSON。

Related MCP server: SolidWorks Automation Skill

快速开始(任意平台,模拟 CAD)

需要 uv。

git clone https://github.com/hongheshan-svg/cad-mcp.git
cd cad-mcp
uv sync
uv run pytest -q          # 全部通过
uv run cadmcp doctor      # 查看可用目标(默认两个模拟目标:mock-sw2024、mock-creo10)

在仓库目录启动 Claude Code,项目自带的 .mcp.json 会提示启用 cad 服务器,然后试试:

用 cad MCP 设计一块电机安装板,材料 AL6061-T6,外形 250×150,厚 12,四角 R5。
中心 Φ50H7 止口通孔;周围 4×M5 螺纹孔(深10,螺纹深8)均布在 Φ70 圆上,起始角45°;
四角 4×M6 内六角沉孔,孔中心距边 15。图号 MP-001,表面处理 阳极氧化黑。出图并提交版本 A。

工程图 SVG 预览和发布文件会出现在 ~/cadmcp/ 下(可用 CADMCP_WORKSPACE 修改)。

接入 Codex

# ~/.codex/config.toml
[mcp_servers.cad]
command = "uv"
args = ["run", "--project", "/path/to/cad-mcp", "cadmcp", "serve", "--stdio"]
tool_timeout_sec = 300

也支持 Streamable HTTP:uv run cadmcp serve --http 0.0.0.0:8765。

连接真实 CAD(Windows)

git clone https://github.com/hongheshan-svg/cad-mcp.git D:\cad-mcp
cd D:\cad-mcp
powershell -ExecutionPolicy Bypass -File scripts\win\setup.ps1
uv run python scripts\win\probe_sw.py --version 2024 --node-config D:\cadmcp\node.yaml

节点配置示例见 config/node.windows.example.yaml,完整步骤与核对清单见 docs/WINDOWS_TEST.md。

spec 示例

{
  "name": "CS01-002_CylMountPlate", "part_no": "CS01-002", "title": "气缸安装板",
  "material": "AL6061-T6", "surface_treatment": "阳极氧化黑",
  "parameters": {"L": 200, "W": 80, "T": 12, "pitch": 160},
  "base": {"type": "extrude", "profile": {"shape": "rect", "width": "L", "height": "W"}, "thickness": "T"},
  "features": [
    {"feature": "hole", "name": "Post", "type": "counterbore", "size": "M8",
     "positions": [["-pitch/2", 0], ["pitch/2", 0]]},
    {"feature": "hole", "name": "Cyl", "type": "clearance", "size": "M6",
     "pattern": {"kind": "circular", "radius": 17, "count": 4, "start_angle": 45}},
    {"feature": "hole", "name": "Rod", "type": "simple", "size": 26, "positions": [[0, 0]]}
  ],
  "references": [{"name": "CS_Cyl", "origin": [0, 0, "T"]}]
}

孔只需写类型和公制规格,底孔、过孔、沉孔尺寸由平台按标准查表;与外购件对接的孔用 mount 特征按库登记的接口自动生成,装配时还会校验装的是不是同一个件;装配只按命名坐标系(CS_*)定位,不选面、不选边。完整示例见 examples/cylinder_station.py。

MCP 工具

分组

工具

目标

cad_list_targets cad_select_target cad_get_capabilities

变更会话

cad_change_begin cad_change_status cad_checkpoint cad_change_rollback cad_change_commit

建模

cad_build_part cad_build_assembly cad_build_frame cad_build_drawing cad_set_parameters

读取

cad_get_model cad_search_library cad_open_existing

修改现有模型

cad_inspect_existing cad_edit_existing cad_change_writeback(改尺寸/变量/属性/材料、压缩特征、装配换件并比对安装接口;自动更新引用的图纸并查悬空标注;发布后回写原位置)

选型计算

cad_calc(气缸、伺服+丝杠、同步带、螺栓组,输出计算书)

校验与输出

cad_validate cad_check_interference cad_export_bom(xlsx/csv:多级 BOM、汇总 BOM、采购清单、原材料汇总、下料明细;ERP 导入列映射与物料编码对照) cad_export

每个工具都带只读/写入注解,便于客户端审批;出错时返回的 error.hint 是写给 AI 看的下一步建议。出图工作流见 skills/mechanical-drawing/SKILL.md。

能力边界

支持

暂不支持

板/块/L 形件(外形、螺纹孔/过孔/沉孔/销孔/腰型孔、型腔、凸台、倒角圆角,含内侧面特征)

斜孔、螺纹轴端

剖视图(自动全剖/阶梯剖/局部剖,指定半剖、左视图剖;剖面线、螺纹画法、剖切符号按 GB/T 4458.6);孔表(孔多时自动);引出标注自动避让

旋转剖、断面图(轴类除外)

阶梯轴(键槽、挡圈槽、退刀槽、端部倒角、配合公差,自动出断面图)

铸件(板/块类:自动生成毛坯件与毛坯图,加工余量、铸孔、铸后钻孔,铸造技术要求,GB/T 6414 公差)

拔模与铸造圆角建模、复杂箱体

钣金(直边折弯、翻边孔、展开图含折弯线与说明)

复杂曲面

铝型材机架(立柱+多层横梁、下料清单、角码紧固件)

焊接件(方管/矩形管/角钢/圆管/扁钢/槽钢/工字钢 + 焊接板;自动识别焊缝与焊脚、GB/T 324 焊缝符号(周围焊/双面焊/焊接方法)、切割清单与序号、焊接技术要求)

斜撑、型钢端部切角、焊缝实体

标准件/外购件装配、BOM;Creo 从零建模与出图细节(拉伸件/轴类,经 TOOLKIT 服务 creo_toolkit/,待实机编译)

Creo 钣金/焊接件/装配建模

基准、几何公差、表面粗糙度(含配合面粗糙度检查);SolidWorks 原生基准符号、公差框格、表面结构符号

引线关联到模型边线待实机确认

目录

src/cadmcp/
  ir/            spec 模型与解析          rules.py      设计规则
  detailing.py   出图规划与检查           render_svg.py 工程图预览
  adapters/      mock / solidworks / creo gateway/      会话、策略、MCP 服务
docs/            DESIGN.md(架构设计)  WINDOWS_TEST.md(实机测试手册)
scripts/win/     Windows 安装与探针脚本  skills/      AI 出图工作流

文档

许可证

Apache-2.0

Available Tools

24 tools
cad_build_assemblyB

按装配 spec 建装配:组件用 CS_ 坐标系对齐定位(align → to + offset/rotate),可线性阵列。返回 BOM 和初步干涉。

Inputs: spec (required). Returns: object

cad_build_drawingA

按出图 spec 生成工程图:自动选图幅比例、视图、总体尺寸、孔坐标与孔标注、技术要求、标题栏、明细表,并做出图检查。

Inputs: spec (required). Returns: object

cad_build_frameA

铝型材机架:给 name/part_no/title、width/depth/height(外形 mm)、profile(默认 PRF-4040)、 levels(横梁层中心高度,默认底层+顶层)、bracket(角码,默认 BRK-4040),生成立柱+横梁装配并建模。 返回下料清单 cut_list、型材总长、BOM(含角码/T 螺母/螺钉)。之后可用 asm: 把机架装进总装, 或在其上加安装板(坐标原点在机架底面中心)。 construction="welded" 生成方管焊接机架(section 默认 SHS40x3,feet 地脚板),作为一个焊接件零件, 返回切割清单;之后可 cad_build_drawing 出焊接件图(焊缝符号、切割清单、焊接技术要求)。

Inputs: spec (required). Returns: object

cad_build_partA

按零件 spec 建模(新建或按同名覆盖重建)。返回尺寸、质量、孔标注、设计规则检查结果。 基准:草图在 XY(Z=0),实体向 +Z;面名 top/bottom/front(-Y)/back(+Y)/left(-X)/right(+X)。

Inputs: spec (required). Returns: object

cad_calcA

选型计算,返回带公式过程的计算书与推荐型号(有变更会话时计算书存入工作区并随版本发布)。 cylinder: load_kg 或 force_N, orientation horizontal|vertical, stroke_mm, pressure_MPa=0.5, direction push|pull screw_drive: load_kg, stroke_mm, speed_mm_s, accel_time_s=0.2, orientation, lead_mm(可选), screw_diameter_mm=16 belt_drive: load_kg, stroke_mm, speed_mm_s, accel_time_s=0.2, pulley_pd_mm=30 bolt: size(M6), count, grade 8.8|10.9|12.9, tension_N, shear_N 先算再建模:用 selection 结果选标准件(cad_search_library)和定尺寸。

Inputs: kind (required), params (required). Returns: object

cad_change_beginB

开启变更会话:创建隔离工作区(可复制已有设计文件进来),后续所有建模/修改都在其中。

Inputs: project (required), target, sources. Returns: object

cad_change_commitA

把工作区发布为新修订版本(不可覆盖)。门禁(再生无错、规则无 error、图纸无 error)不通过会被拒绝。 description 为更改内容(写进图纸更改记录表;首版可省略),by 为更改人。图纸标题栏自动写入版本号。

Inputs: revision (required), by, description. Returns: object

cad_change_rollbackA
Destructive

回滚到检查点(0 = 会话开始)。之后的修改会丢弃。

Inputs: to. Returns: object

cad_change_statusB
Read-onlyIdempotent

当前会话:模型列表、检查点、提交门禁状态。

Inputs: no named parameters. Returns: object

cad_change_writebackA
Destructive

把已发布版本中修改过的源文件回写到原位置(共享盘 / PDM 检出目录)。confirm=false 只列出计划; 原文件先备份到发布目录 _writeback_backup;原文件期间被别人改过(冲突)、只读(PDM 未检出)、 或不在 policy.writeback_allow 中的都不会覆盖。平台新建的文件不回写,需按公司流程入库。

Inputs: confirm. Returns: object

cad_check_interferenceD
Read-onlyIdempotent

装配干涉检查。

Inputs: name (required). Returns: object

cad_checkpointB

打检查点(工作区快照),之后可回滚到这里。

Inputs: label. Returns: object

cad_edit_existingA

修改现有模型。edits 为指令列表: {"op":"set_dimension","name":"D1@凸台-拉伸1","value":20} / {"op":"set_variable","name":"pitch","value":180} / {"op":"suppress","feature":"圆角1","suppressed":true} / {"op":"set_property","name":"Description","value":"..."} / {"op":"set_material","material":"AL6061-T6"}。 先校验(名称存在、方程式驱动的尺寸要改变量、变化幅度);dry_run=true 只校验。执行后重建,出错不保存; 成功则返回改前改后对比(尺寸/质量/包围盒),并自动更新引用它的装配和工程图、检查悬空标注。 每次修改前自动建检查点(rollback_to)。发布后可用 cad_change_writeback 回写原位置。

Inputs: file (required), edits (required), dry_run. Returns: object

cad_exportC
Read-onlyIdempotent

导出文件到会话 out/ 目录。

Inputs: name (required), format (required). Returns: object

cad_export_bomB
Read-onlyIdempotent

导出装配 BOM(CSV,UTF-8 BOM 便于 Excel 打开)。

Inputs: name (required). Returns: object

cad_get_capabilitiesA
Read-onlyIdempotent

查询目标对各能力的支持级别(full/partial/none)。不支持的能力不要尝试。

Inputs: target. Returns: object

cad_get_modelC
Read-onlyIdempotent

读取模型:spec、解析结果摘要、规则发现、(装配)BOM、(图纸)尺寸清单。

Inputs: name (required). Returns: object

cad_inspect_existingA
Read-onlyIdempotent

读出工作区中现有模型(旧零件/装配/工程图):特征树(压缩状态、父子关系)、全部尺寸全名与数值、 方程式与全局变量、自定义属性、材料、质量,以及引用它的装配/工程图(used_by)。 文件须先用 cad_change_begin(project, sources=[...]) 复制进工作区;file 为工作区内相对路径。

Inputs: file (required). Returns: object

cad_list_targetsA
Read-onlyIdempotent

列出可用的 CAD 目标(CAD 类型、版本、节点、状态)。

Inputs: no named parameters. Returns: object

cad_open_existingB
Read-onlyIdempotent

打开已有设计文件(版本保护:新版本 CAD 默认只读打开旧版本文件,旧版本 CAD 拒绝打开新文件)。

Inputs: path (required), write. Returns: object

cad_search_libraryA
Read-onlyIdempotent

搜索标准件/外购件库。返回编码、参数和可用的命名基准。装配中用 source="lib:?L=600"。

Inputs: query, category. Returns: object

cad_select_targetC
Read-onlyIdempotent

设置默认 CAD 目标(新变更会话使用)。

Inputs: target (required). Returns: object

cad_set_parametersA

修改模型驱动参数(值或表达式),自动重建该模型及依赖它的装配/工程图。

Inputs: name (required), updates (required). Returns: object

cad_validateC
Read-onlyIdempotent

运行设计规则与出图检查,返回提交门禁状态。

Inputs: name. Returns: object

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.1/5.0

    Scored across 24 tools

    Disambiguation4/5

    Most tools are clearly separated by resource and action (targets, change session, build part/assembly/drawing/frame, calc, library, export). A few pairs overlap mildly: cad_open_existing vs cad_inspect_existing, cad_validate vs cad_check_interference, and cad_export vs cad_export_bom, plus cad_change_status partially duplicates cad_get_model's summary role. Descriptions do help disambiguate these, so misselection risk is low but not zero.

    Naming Consistency4/5

    All names share a cad_ prefix and snake_case, which is good. However, the ordering convention is mixed: most are verb_noun (cad_build_part, cad_get_model, cad_list_targets), while the session group is noun_verb (cad_change_begin, cad_change_commit, cad_change_rollback). The grouping is readable and intentional, but it is a deviation from the dominant pattern.

    Tool Count4/5

    24 tools is at the upper bound, but the domain is genuinely broad: target selection, isolated change sessions with checkpoints/rollback, part/assembly/drawing/frame modeling, existing-model editing, validation, library search, engineering calc, and export/writeback. Each tool maps to a real workflow step, though a couple (export_bom vs export, change_status vs get_model) could be folded together.

    Completeness4/5

    The surface covers the full modeling lifecycle: begin session, build, edit, inspect, parameterize, validate, checkpoint/rollback, commit, writeback, and export. Gaps are minor: no explicit delete/rename of workspace models, no dedicated checkpoint listing or cleanup, and drawing output is only reachable via the generic export tool. Agents can work around these.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI agents such as Claude to drive SolidWorks through its COM API using natural language, creating parts and assemblies, sketching geometry, and adding features without clicking menus. Also supports running arbitrary API scripts and verifying results through model reports, rendered views, interference checks, and exports.
      2
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI agents to drive desktop CAD software through natural language with verified execution, failure recovery, and traceable results across modeling, assemblies, drawings, exports, motion, FEA, and related engineering workflows.
      2
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables Claude to drive SolidWorks in natural language, creating parts and assemblies, sketching and modeling features, editing dimensions, setting materials, and exporting CAD files. It also exposes selection, mass-property, and viewport-capture tools so 3D designs can be built and verified conversationally.
      MIT
    • F
      license
      B
      quality
      C
      maintenance
      Enables AI agents to drive SolidWorks for parametric modelling, aerospace part generation, sheet metal, weldments, assemblies, drawings, simulation, inspection, and file export. It provides approval-gated operations, verification tools, and journaling for safe, recoverable design automation.
      94
      -