Skip to main content
Glama
solid-mcp-studio

solid-mcp-studio

by igokmen433
README.md
<p align="center">
  <img src="docs/assets/banner.png" alt="solid-mcp-studio" width="100%" />
</p>

<p align="center">
  <strong>πŸ‡¬πŸ‡§ English</strong> &nbsp;|&nbsp; <a href="README.tr.md">πŸ‡ΉπŸ‡· TΓΌrkΓ§e</a>
</p>

**Bidirectional Live SolidWorks CAD Automation Server via Model Context Protocol (MCP).**

`solid-mcp-studio` combines a **Python MCP Server** (`server.py`) with a persistent **C# SolidWorks Interop Bridge** (`sw_bridge.exe`) to give AI agents direct, real-time control over a live, visible SolidWorks session β€” from parametric 3D modeling and sheet metal fabrication to production-ready 2D technical drawings and 1:1 laser-ready DXF exports.

> πŸ“– **Detailed Turkish User Guide:** [docs/SOLIDWORKS_MCP_KILAVUZU.md](docs/SOLIDWORKS_MCP_KILAVUZU.md)

> [!NOTE]
> **Hobby & Non-Commercial Project:** This project was created purely as a personal hobby and technical experiment, with no commercial purpose or affiliation. *SolidWorks* is a registered trademark of Dassault Systèmes.

---

## Key Capabilities

- **Live & Visible SolidWorks Execution:** Operates directly on the user's running SolidWorks window so every sketch, feature, and drawing view can be watched in real time. Never modifies system templates or user settings.
- **Parametric 3D Modeling (Phase 2):** Full sketch geometry (`line`, `circle`, `arc`, `rect`, `polygon`), parametric dimensions (`sw_sketch_dimension`), geometric relations (`sw_sketch_relation`), `Extrude Boss/Cut`, `Revolve Boss/Cut`, `Fillet`, `Chamfer`, material assignment, and `sw_undo`.
- **Production-Ready Technical Drawings (Phase 3):** Clean title-block-free Landscape A3 sheets, automatic standard orthographic views, longitudinal section views (`KESΔ°T A-A`), detail views, calm targeted dimensioning (inspecting each view via `sw_drawing_inspect_view` and placing collision-free dimensions one by one with `sw_drawing_add_dimension` instead of cluttered auto-dimension dumps), in-place revision on the same `.SLDDRW` sheet, manufacturing notes, and 200 DPI PNG + PDF + `.SLDDRW` export.
- **Autonomous `jobs/` Workflow & 7-Angle Visual Analysis:** Drop a `.SLDPRT`/`.STEP`/`.IGES` part into `jobs/parcadan_teknik_resim/` for automatic 7-view viewport inspection (`Isometric`, `Front`, `Back`, `Top`, `Bottom`, `Right`, `Left`) and a structured drawing plan, or drop a `.PDF`/`.PNG`/`.JPG` drawing into `jobs/teknik_resimden_parca/` to generate a verified dimension table and build the parametric 3D model step by step.
- **Sheet Metal & Laser DXF Workflow:** `Base Flange`, `Edge Flange`, `Hem`, bend inspection (`K-factor`, thickness, bend radius), flat-pattern drawing views with bend notes, and clean Layer-0 1:1 laser-ready DXF export.
- **Visual Checkpoint Verification:** High-resolution viewport screenshots (`sw_capture_viewport`) and 200 DPI drawing previews enable multimodal AI agents to visually verify geometry and drawing readability at every step.

---

## Visual Examples

| Parametric 3D Model (Live Viewport) | Auto-Generated A3 Technical Drawing |
| :---: | :---: |
| ![3D Parametric Model](docs/assets/example_3d_model.png) | ![Production Technical Drawing](docs/assets/example_technical_drawing.jpg) |

---

## Architecture

```mermaid
flowchart LR
    AI["AI Client (Antigravity / Claude / Cursor)"] <-->|MCP stdio JSON-RPC| PY["Python MCP Server\nserver.py + mcp_server/"]
    PY <-->|Persistent STA NDJSON| CS["C# Interop Bridge\nbridge/bin/sw_bridge.exe"]
    CS <-->|COM / SolidWorks API| SW["Live SolidWorks 2025"]
```

- **Python layer (`server.py`, `mcp_server/`):** Exposes 40+ strongly typed MCP tools and renders PDF drawings to 200 DPI PNGs via PyMuPDF (`fitz`).
- **C# STA bridge (`bridge/*.cs`):** Runs as a persistent single-threaded apartment (STA) subprocess communicating over newline-delimited JSON (NDJSON) for fast, reliable SolidWorks COM interop without per-call startup overhead.
- **Engineering rules (`rules/`):** Structured modeling, drawing, and autonomous file-based workflow specifications (`modeling_rules.md`, `drawing_rules.md`, `autonomous_workflow.md`).

---

## Tool Overview

| Category | Tools |
| :--- | :--- |
| **Session & Inspection** | `sw_status`, `sw_list_docs`, `sw_activate_doc`, `sw_open_doc`, `sw_new_part`, `sw_save_doc`, `sw_zoom_fit`, `sw_capture_viewport`, `sw_inspect_part` |
| **Parametric Sketching** | `sw_sketch_start`, `sw_sketch_line`, `sw_sketch_circle`, `sw_sketch_arc`, `sw_sketch_rect`, `sw_sketch_polygon`, `sw_sketch_dimension`, `sw_sketch_relation`, `sw_sketch_close` |
| **3D Solid Features** | `sw_extrude_boss`, `sw_extrude_cut`, `sw_revolve_boss`, `sw_revolve_cut`, `sw_fillet`, `sw_chamfer`, `sw_set_material`, `sw_undo`, `sw_delete_feature` |
| **Technical Drawings** | `sw_get_drawing_rules`, `sw_drawing_create_sheet`, `sw_drawing_add_standard_views`, `sw_drawing_add_section_view`, `sw_drawing_add_detail_view`, `sw_drawing_auto_dimension`, `sw_drawing_add_isometric`, `sw_drawing_list_annotations`, `sw_drawing_move_annotation`, `sw_drawing_delete_annotation`, `sw_drawing_inspect_view`, `sw_drawing_add_dimension`, `sw_drawing_add_note`, `sw_drawing_set_metadata`, `sw_drawing_export` |
| **Sheet Metal** | `sw_sm_base_flange`, `sw_sm_edge_flange`, `sw_sm_hem`, `sw_sm_set_flat_state`, `sw_sm_inspect_bends`, `sw_drawing_add_flat_pattern`, `sw_drawing_set_sheet_metal_notes`, `sw_export_flat_dxf` |

---

## Prerequisites

- **OS:** Windows 10 / 11 (64-bit)
- **CAD:** SolidWorks installed locally (tested on SolidWorks 2025)
- **Python:** 3.11 or newer
- **.NET Framework:** Built-in Windows 64-bit `csc.exe` (`C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe`)

---

## Installation

### 1. Clone the repository

```powershell
git clone https://github.com/igokmen433/solid-mcp-studio.git
cd solid-mcp-studio
```

### 2. Set up the Python virtual environment

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

### 3. Build the C# SolidWorks Interop Bridge

> **Note:** SolidWorks Interop DLLs (`SolidWorks.Interop.sldworks.dll`, `SolidWorks.Interop.swconst.dll`) are proprietary to Dassault Systèmes and are intentionally excluded from this repository. The build script automatically locates them from your local SolidWorks installation and compiles `bridge\bin\sw_bridge.exe`.

```powershell
powershell -ExecutionPolicy Bypass -File .\bridge\build_bridge.ps1
```

---

## Connecting to an MCP Client

`solid-mcp-studio` uses standard **MCP (`stdio`)**, so it works with **Antigravity**, **Claude Code**, **OpenAI Codex CLI**, **Claude Desktop**, **Cursor**, and any other MCP-compatible client on Windows.

### Antigravity / Claude Desktop / Cursor (`mcp.json`)

Add the server to your MCP client configuration (see [mcp_config.example.json](mcp_config.example.json)):

```json
{
  "mcpServers": {
    "solidworks-cad-mcp": {
      "command": "C:/path/to/solid-mcp-studio/.venv/Scripts/python.exe",
      "args": [
        "C:/path/to/solid-mcp-studio/server.py"
      ]
    }
  }
}
```

### Claude Code

```powershell
claude mcp add solidworks-cad-mcp -- C:/path/to/solid-mcp-studio/.venv/Scripts/python.exe C:/path/to/solid-mcp-studio/server.py
```

### OpenAI Codex CLI (`~/.codex/config.toml`)

```toml
[mcp_servers.solidworks-cad-mcp]
command = "C:/path/to/solid-mcp-studio/.venv/Scripts/python.exe"
args = ["C:/path/to/solid-mcp-studio/server.py"]
```

> πŸ’‘ **Automatic Engineering Rules:** Pre-configured instruction files are included for all major agents β€” `GEMINI.md` (Antigravity / Gemini), `CLAUDE.md` (Claude Code), and `AGENTS.md` (OpenAI Codex / Cursor).

---

## Verification Tests

With SolidWorks running (or closed β€” the bridge can launch it automatically):

```powershell
.\.venv\Scripts\python.exe tests\test_phase1_bridge.py
.\.venv\Scripts\python.exe tests\test_phase2_modeling.py
.\.venv\Scripts\python.exe tests\test_phase3_drawing.py
```

For sheet metal parts, pass one or more `.SLDPRT` files:

```powershell
.\.venv\Scripts\python.exe tests\test_sheet_metal_live.py path\to\your_sheet_metal_part.SLDPRT
```

---

## Project Structure

```text
solid-mcp-studio/
β”œβ”€β”€ server.py                  # MCP server entrypoint
β”œβ”€β”€ mcp_server/                # Python MCP tool registrations & NDJSON bridge client
β”œβ”€β”€ bridge/                    # C# SolidWorks COM interop bridge source & build script
β”œβ”€β”€ rules/                     # Modeling, drawing & autonomous workflow rules
β”œβ”€β”€ AGENTS.md / CLAUDE.md / GEMINI.md  # Agent instruction files (Codex, Claude Code, Antigravity)
β”œβ”€β”€ docs/                      # Detailed Turkish guide & visual showcase assets
β”œβ”€β”€ jobs/                      # Drop-in workspace for autonomous CAD <-> Drawing jobs
β”œβ”€β”€ tests/                     # Live verification scripts (Phases 1–3 & Sheet Metal)
β”œβ”€β”€ pyproject.toml
β”œβ”€β”€ mcp_config.example.json
└── LICENSE
```

---

## License

This project is licensed under the **MIT License** β€” see [LICENSE](LICENSE) for details.