Skip to main content
Glama
solidworks-mcp-pro

solidworks-mcp-pro

by ANYLXB

solidworks-mcp-pro

一个从零编写的 SolidWorks MCP 自动建模仓库,用于把 Codex / 其他 MCP 客户端连接到本机 Windows 上的 SolidWorks,并通过 Python COM / SolidWorks API 自动创建零件、行业模板、导出文件和做基础审查。

说明:本仓库代码为独立生成的实现,没有复制第三方仓库代码。你可以把它作为自己的 GitHub 仓库第一版,然后继续扩展。

目标架构

Codex / MCP Client
        ↓ stdio MCP
solidworks-mcp-pro
        ↓ Python COM / pywin32
SldWorks.Application
        ↓
SolidWorks Part / Assembly / Drawing / STEP / PDF / PNG

Related MCP server: solidworks-mcp

当前第一版能力

  • MCP Server:通过 stdio 暴露 SolidWorks 工具。

  • SolidWorks 会话管理:连接、启动、活动文档、保存、导出。

  • 安全输出目录:默认只能写入 SW_MCP_OUTPUT_ROOT。

  • 基础零件:长方体、圆柱。

  • 行业模板:法兰、简化管板、简化立式换热器概念件。

  • JSON Spec 驱动:用结构化参数生成模型,减少自然语言歧义。

  • 基础审查:活动文档标题、路径、类型、质量属性、导出预览。

  • Codex 配置示例和 PowerShell 注册脚本。

  • 单元测试骨架和 Windows 集成测试标记。

系统要求

  • Windows 10 / 11

  • 已安装 SolidWorks

  • Python 3.10+

  • Codex CLI 或其他支持 MCP 的客户端

安装

cd C:\Projects
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -e C:\Projects\solidworks-mcp-pro

也可以直接在仓库根目录执行:

python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -e .

配置环境变量

最少建议设置输出目录:

setx SW_MCP_OUTPUT_ROOT "C:\SW-MCP-Output"

如果 SolidWorks 默认模板读取失败,手动设置模板路径:

setx SW_MCP_PART_TEMPLATE "C:\ProgramData\SOLIDWORKS\SOLIDWORKS 2025\templates\Part.prtdot"
setx SW_MCP_ASSEMBLY_TEMPLATE "C:\ProgramData\SOLIDWORKS\SOLIDWORKS 2025\templates\Assembly.asmdot"
setx SW_MCP_DRAWING_TEMPLATE "C:\ProgramData\SOLIDWORKS\SOLIDWORKS 2025\templates\Drawing.drwdot"

直接启动 MCP Server

.\.venv\Scripts\Activate.ps1
solidworks-mcp-pro

正常情况下它不会输出普通日志,因为 MCP 使用 stdio 通信。

注册到 Codex

方式一:命令注册

codex mcp add solidworks-pro -- C:\Projects\solidworks-mcp-pro\.venv\Scripts\python.exe -m sw_mcp_pro.mcp_server.server

方式二:参考 codex/config.example.toml 手动加入 Codex 配置。

在 Codex 中测试

请调用 solidworks-pro 的 sw_health,检查 SolidWorks 是否可连接。
请调用 solidworks-pro 创建一个法兰:外径 200mm,厚度 20mm,中心孔 80mm,6 个直径 12mm 螺栓孔,PCD 150mm,保存为 flange_demo.SLDPRT。

推荐工作方式

先用结构化 spec:

{
  "type": "flange",
  "name": "DN80_flange",
  "params": {
    "outer_diameter_mm": 200,
    "thickness_mm": 20,
    "center_hole_diameter_mm": 80,
    "bolt_count": 6,
    "bolt_hole_diameter_mm": 12,
    "bolt_circle_diameter_mm": 150,
    "material": "Plain Carbon Steel"
  },
  "save_as": "DN80_flange.SLDPRT"
}

然后让 Codex 调用:

请调用 sw_create_from_spec_json,使用这个 JSON 创建模型。

目录结构

solidworks-mcp-pro/
├── sw_mcp_pro/
│   ├── mcp_server/          # MCP 工具层
│   ├── sw_api/              # SolidWorks COM 封装层
│   ├── templates/           # 参数化行业模板
│   ├── specs/               # JSON spec 解析与校验
│   └── utils/               # 日志、安全路径、JSON 工具
├── examples/                # 示例 spec
├── installers/              # Codex 注册脚本
├── codex/                   # Codex 配置示例
├── docs/                    # 文档
└── tests/                   # 测试

安全边界

本项目默认不提供任意 Python / VBA 执行工具。所有文件写入默认限制在 SW_MCP_OUTPUT_ROOT 内,避免 AI 把文件保存到不可控目录。若确实需要写入任意路径,可设置:

setx SW_MCP_ALLOW_OUTSIDE_ROOT "1"

不建议长期开启。

发展路线

  • 更完整草图约束与尺寸系统

  • 孔向导 / 螺纹孔 / 配置表

  • 复杂装配体 Mate 模板

  • 工程图自动标注 / BOM / 标题栏

  • 换热器、管板、U 型管、支架、接管、封头模板

  • 模型对照 spec 自动验收

  • 多工作站任务队列

Available Tools

10 tools
sw_active_document_infoB

Return information about the active SolidWorks document.

Inputs: no named parameters. Returns: result

sw_create_boxB

Create a rectangular box Part and save it under the output root.

Inputs: width_mm (required), height_mm (required), length_mm (required), save_as_name. Returns: result

sw_create_cylinderC

Create a cylinder Part and save it under the output root.

Inputs: length_mm (required), diameter_mm (required), save_as_name. Returns: result

sw_create_flangeC

Create a parametric flange with center hole and bolt holes.

Inputs: bolt_count (required), thickness_mm (required), outer_diameter_mm (required), bolt_hole_diameter_mm (required), +5 more. Returns: result

sw_create_from_spec_jsonC

Create a model from a structured JSON spec.

Supported types: box, cylinder, flange, tube_sheet, vertical_heat_exchanger_concept.

Inputs: spec_json (required). Returns: result

sw_create_tube_sheetC

Create a simplified tube sheet with a grid of tube holes inside a circular plate.

Inputs: thickness_mm (required), tube_pitch_mm (required), tube_hole_count (required), outer_diameter_mm (required), +4 more. Returns: result

sw_create_vertical_heat_exchanger_conceptC

Create a simplified vertical heat exchanger shell concept model.

Inputs: shell_height_mm (required), shell_diameter_mm (required), material, save_as_name. Returns: result

sw_export_activeA

Export the active SolidWorks document to STEP, STL, IGES, Parasolid, PDF, DXF, DWG or PNG.

Inputs: format (required), save_as_name. Returns: result

sw_healthA

Check whether the local SolidWorks COM server is reachable.

Inputs: no named parameters. Returns: result

sw_review_activeB

Return a basic review summary for the active SolidWorks document.

Inputs: no named parameters. Returns: result

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    B3.3/5.0

    Scored across 10 tools

    Disambiguation4/5

    Most tools target clearly distinct actions: health check, document info, creation of specific shapes, export, and review. The main overlap is between the specific creation tools and sw_create_from_spec_json, which can create the same supported types and may cause an agent to pick the wrong pathway.

    Naming Consistency4/5

    The sw_ prefix and verb_noun structure are used consistently, creating a readable pattern like sw_create_box, sw_export_active, and sw_review_active. Minor deviations exist with sw_health and sw_active_document_info, which omit a verb, but the overall convention is still predictable.

    Tool Count5/5

    Ten tools is well-scoped for a SolidWorks automation server covering health, modeling, export, and review. Each tool serves a distinct role in the workflow without unnecessary redundancy or bloat.

    Completeness4/5

    The tool surface covers the core workflow: health check, inspect active document, create common part types, export to standard formats, and review the result. Missing capabilities like opening/closing documents, editing existing models, or assembly support are notable but likely outside the intended focused scope.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      MCP bridge server for SolidWorks that enables AI assistants to control SolidWorks programmatically via COM automation.
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI (e.g., Claude) to control SolidWorks via natural language, automating part creation, sketching, and feature operations through the Model Context Protocol.
      1
      MIT
    • A
      license
      B
      quality
      C
      maintenance
      Enables Claude or any MCP client to drive a live SOLIDWORKS session through its COM API, modeling parts, building assemblies with mates, checking interferences and machining feasibility, and exporting STEP or DXF files. It also exposes a local semantic index of the SOLIDWORKS API so the model can look up signatures, enums, and official examples before running arbitrary Python against the session.
      22
      2
      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
      -