solidworks-mcp-pro

solidworks-mcp-pro

Enables connecting MCP clients to local SolidWorks for automated 3D part creation, template generation, file export, and basic review via natural language.

Category
Visit Server

README

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

当前第一版能力

  • 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 自动验收
  • 多工作站任务队列

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured