Skip to main content
Glama
README.md
[English](README.md) | [简体中文](README_CN.md)

# maycad-mcp

**Deterministic Python SDK, CLI, and 75-Tool MCP Server for Autonomous AI-Driven MayCAD (MayTec) 3D Aluminum Profile Engineering**

[![Python 3.10+](https://img.shields.io/badge/Python-3.10%2B-3776AB?logo=python&logoColor=white)](pyproject.toml)
[![Platform Windows x64](https://img.shields.io/badge/Platform-Windows%20x64-0078D6?logo=windows&logoColor=white)](RESEARCH.md)
[![MayCAD 12.10](https://img.shields.io/badge/MayCAD-12.10%20Build%20292-0A7E8C)](RESEARCH.md)
[![MCP Tools 75](https://img.shields.io/badge/MCP%20Tools-75-4B32C3)](docs/TOOLS.md)
[![License MIT](https://img.shields.io/badge/License-MIT-2EA44F)](LICENSE)

`maycad-mcp` enables AI agents (Claude Code, Claude Desktop, Codex, Cursor, Antigravity, or any MCP client) and Python/CLI automation scripts to design, inspect, validate, modify, render, and export industrial MayTec aluminum extrusion assemblies programmatically—with **zero simulated mouse clicks, zero screen-coordinate clicking, and zero vision-based GUI scraping**.

> [!IMPORTANT]
> **Independent Open-Source Bridge**: `maycad-mcp` does **not** redistribute any proprietary MayCAD binaries, `library.zip` bytecode, or `.bindata` catalog databases. It requires a legally installed, licensed copy of **MayCAD 64-bit** on Windows and leaves all original installation files 100% unmodified.

---

## Live Verified Showcases

### 1. Eight-Corner Poly-Joint Test Frame (`800 × 600 × 600 mm`, `PROF40-4040L`)

Built autonomously end-to-end through the live MCP `STDIO` protocol (`examples/eight_corners_demo/build_eight_corners.py`): all eight corners of a cube frame use eight distinct MayTec joining methods simultaneously—without collisions (`0` interference) and producing a 19-row native MayTec BOM.

![Eight-Corner Frame Showcase](examples/eight_corners_demo/eight_corners_overview.png)

| Corner | Connection Type | MayTec Profile / Part | Article No. |
| --- | --- | --- | --- |
| Corner 1 (Top Front-Left) | 3-Way Sphere Corner Piece | `CORNER40_SPHERE` | `1.48.448` |
| Corner 2 (Top Front-Right) | 3-Way Cubic Black Corner Piece | `CORNER40_CUBIC-BK` | `1.48.441.2` |
| Corner 3 (Top Back-Left) | 3-Way Segment Corner Piece | `CORNER40_SEGMENT` | `1.48.442` |
| Corner 4 (Top Back-Right) | 45° Polyamide Corner Piece | `CORNER40_45-PA` | `1.48.14440` |
| Corner 5 (Bottom Front-Left) | Cast Gusset Brackets + Fasteners | `JE_GUS_3876_PC` | `1.46.204.3876.2` |
| Corner 6 (Bottom Front-Right) | Steel 90° Angle Brackets | `ACC_ANGLE_1.46.20639` | `1.46.20639` |
| Corner 7 (Bottom Back-Left) | 45° Mitered Diagonal Struts (`294.56 mm`) | `PROF40-4040L` | `1.11.040040.43LP` |
| Corner 8 (Bottom Back-Right) | Internal Concealed Connectors + Plastic Endcap | `1.21.4EK1` / `1.21.4E0` + `CAP40SQ4040` | `1.42.20404.2` |

### 2. Parametric Heavy Industrial Workbench (`2000 × 800 × 900 mm` → `2400 × 800 × 900 mm`)

Verified across a full 17-step live MCP acceptance suite ([Acceptance Report](examples/workbench_acceptance/ACCEPTANCE_REPORT.md)): parametric creation, real catalog lookup, outer-envelope vs. cut-length accounting (`1920 / 720 / 844 mm` → `2320 mm`), automatic `SceneMap.postprocess` fastening (`20/20` connectors), 3D OBB SAT collision checking (`0` collisions), 6 m bar cutting optimization (`85.42%` utilization), headless OpenGL FBO multi-view rendering, native PDF drawing (`615,274 bytes`), 3-view DXF + panel DXF, and `transfer.exe`-verified AP214 STEP solid export (`162,440 bytes`, `184` vertices / `276` faces).

![Heavy Workbench Isometric Render](examples/workbench_acceptance/screenshots/wb2000_isometric.png)

---

## Why Deterministic Architecture Instead of UI Automation?

Deep technical inspection of **MayCAD 12.10** (`Build: 292`, [RESEARCH.md](RESEARCH.md)) confirmed:

- `framedesigner.exe` (`py2exe`, CPython 2.7.18 x64 + PyQt4 4.11.4) provides **no official public SDK, CLI modeling mode, COM/ActiveX interface, Named Pipe, or local HTTP control API**; `-test` and `-docserver` branches in bytecode are permanently disabled by hardcoded `BRANCH_UID` checks.
- Windows UI Automation (`UIAutomation`) inspects the live `QGLWidget` viewport and sees only **24 generic `Pane` nodes** with **zero clickable menu/button/input controls**.
- However, the native `.scene` v14 format (XML / AES-256-CBC wrapper) is lossless and deterministic, and loading the unmodified `C:\Program Files\MayTec\MayCad-64\python27.dll` inside an **isolated child worker process** gives direct headless access to MayCAD's native `app.Application(False)`, `catalog.fdcache.FDCache`, `SceneMap.postprocess`, `BillMaytec`, `CutList`, `DxfPanelExporter`, `FdConstructionDocDrawable`, and hardware OpenGL FBO `pdf_get_frame_image`.

```mermaid
flowchart LR
    Agent["AI Agent / MCP Client<br/>(Claude, Codex, Cursor, Antigravity)"] -->|STDIO / Streamable HTTP<br/>75 MCP Tools| MCP["maycad_mcp.server<br/>(FastMCP / MCPServer)"]
    CLI["maycad CLI / Python Scripts"] --> SDK["maycad_mcp.sdk<br/>(MayCADSDK)"]
    MCP --> SDK
    SDK --> Scene["Scene Codec &amp; Geometry<br/>(v14 XML/AES + 3D OBB SAT + Millimeter Units)"]
    SDK --> Catalog["Read-Only Product Catalog<br/>(fdcatalogMAYTEC.bindata)"]
    SDK --> Worker["Py27Worker Client<br/>(127.0.0.1 TCP + Token Auth)"]
    Worker --> Py27["Isolated Child Process<br/>(python27.dll + app.Application)"]
    Py27 --> MayCAD["Local MayCAD 12.10<br/>(Unmodified Install Dir)"]
    SDK --> Exporters["AP214 STEP / DXF / BOM / CutList / PDF / Report"]
    Exporters -->|transfer.exe validation| MayCAD
```

---

## Capability & Honest Boundary Matrix

| Capability | Status | Implementation & Verified Notes |
| --- | --- | --- |
| Read / Write `.scene` v14 (Plain XML & Encrypted Binary) | Verified | Lossless roundtrip against 13 contrast scenes + official `Board.scene` (`docs/SCENE_FORMAT.md`) |
| Native MayCAD Kernel Execution (`python27.dll`) | Verified | Persistent loopback-TCP child process with token auth, crash/timeout cleanup, stale PID lock recovery |
| Real MayTec Product Catalog Search | Verified | Reads `fdcatalogMAYTEC.bindata` (`96.8 MB`): profiles, `Ix`/`Iy`, slot width, connectors, endcaps, feet, casters, brackets, screws, hinges, handles, panels |
| Missing Catalog Fields (`cross_section_area_mm2`, alloy) | Honest `null` | `fdcatalogMAYTEC.bindata` does not include net area or alloy grade; SDK explicitly returns `null` rather than guessing |
| 3D Modeling, Assembly & 13 Parametric Templates | Verified | Distinguishes outer envelope vs. centerline vs. exact cut length; supports linked parameter resize (`design_update_parameters`) |
| 3D Interference & Missing Connector Checks | Verified | OBB SAT collision check, joint detection, duplicate check, auto-connect via `SceneMap.postprocess` |
| Native BOM, CutList, DXF & Headless PDF Drawing | Verified | `BillMaytec` CSV/JSON/XML, FFD 6 m bar cutlist optimization, 3-view DXF + `DxfPanelExporter`, ReportLab PDF |
| AP214 Solid B-Rep STEP Export | Verified (Local) | MayCAD cloud STEP API returns HTTP `502`/`404`; local pure-Python `local_ap214` solid B-Rep exporter passes `transfer.exe` STEP→OBJ verification (envelope solids; see [Known Issues](docs/KNOWN_ISSUES_AND_ROADMAP.md)) |
| Headless OpenGL FBO Viewport Screenshots | Verified (Ortho) | Uses native `pdf_get_frame_image` hardware OpenGL FBO with auto-scaled camera distance (`>= 2000 cm`); always renders orthographic projection |
| Euler-Bernoulli Deflection & Stress Heuristic | Heuristic Only | Uses real catalog `Ix`/`Iy` with assumed `E = 70000 MPa`, yield `160 MPa`; always sets `certified_safety_approval: false` |
| Visual Clicking / Screen-Coordinate Automation | Zero | Audited all 58 `src/maycad_mcp/**/*.py` files (`0` hits); UI backend is read-only dialog monitoring & optional preview launch |

---

## 75 MCP Tools Overview

All 75 tools across 9 functional domains are documented in detail in [docs/TOOLS.md](docs/TOOLS.md):

| Domain | Module | Count | Key Capabilities |
| --- | --- | --- | --- |
| **System & Session** | `system_tools.py` | 6 | Diagnostics (`maycad_run_diagnostics`), version, capabilities, active project, GUI preview launch |
| **Project Lifecycle** | `project_tools.py` | 11 | Create, open, save, save-as, inspect, object tree, snapshot, rollback, validate, undo, redo |
| **Catalog** | `catalog_tools.py` | 6 | Search profiles/connectors/accessories, inspect profile/connector specs, query compatibility |
| **3D Modeling** | `modeling_tools.py` | 12 | Add profile by origin or 2 points, modify, move, rotate, copy, mirror, linear/circular array, batch execute |
| **Assembly** | `assembly_tools.py` | 10 | Add connectors/panels/endcaps/feet/casters/corner pieces/brackets, detect joints, auto-connect, validate |
| **Parametric Design** | `design_tools.py` | 7 | `create_frame`, `create_workbench`, `create_rack`, `create_gantry`, `create_enclosure`, `create_custom_structure`, `update_parameters` |
| **Engineering Analysis** | `analysis_tools.py` | 10 | Collision check, connectivity, envelope dimensions, duplicates, missing connectors, weight, bbox, beam deflection, cut optimizer, profile recommender |
| **Exporters** | `export_tools.py` | 6 | `export_step`, `export_dxf`, `export_bom`, `export_cutlist`, `export_drawing` (PDF), `export_project_report` (MD + JSON) |
| **3D Visualization** | `view_tools.py` | 7 | Headless OpenGL FBO screenshots, camera aim, projection state, isolate objects, highlight objects, fit-all, 6 standard views |

---

## Requirements

- **OS**: Windows 10 / 11 (64-bit)
- **MayCAD**: Local licensed installation of **MayCAD 64-bit** (tested on **MayCAD 12.10 Build 292** at `C:\Program Files\MayTec\MayCad-64`; override via `MAYCAD_INSTALL_DIR` environment variable if installed elsewhere)
- **Python**: Python `>= 3.10` (recommended `3.13` via `uv` or standard `venv`)
- **OpenGL**: Working Windows OpenGL graphics driver for headless FBO rendering (`view_*` and `export_drawing`)

---

## Installation & Quick Start

### 1. Clone and Install

```powershell
git clone https://github.com/wubianluori/maycad-mcp.git
cd maycad-mcp
.\scripts\install.ps1
```

If MayCAD is installed in a custom directory:

```powershell
$env:MAYCAD_INSTALL_DIR = "D:\Program Files\MayTec\MayCad-64"
.\scripts\install.ps1
```

### 2. Verify Health Diagnostics & Run Tests

```powershell
# Check MayCAD installation, Py27 kernel, catalog DB, OpenGL FBO, and transfer.exe
.\scripts\health_check.ps1

# Run the complete unit and live MayCAD integration suite
.\scripts\run_tests.ps1
```

### 3. Start the MCP Server

```powershell
# Default: STDIO transport (for AI desktop/IDE clients)
.\scripts\start_mcp.ps1

# Streamable HTTP transport (localhost-bound, recommended with Bearer token)
.\scripts\start_mcp.ps1 -Transport streamable-http -HostAddr 127.0.0.1 -Port 8765 -AuthToken "your-secret-token"
```

### 4. Connect Your AI Client

Ready-to-edit client templates are provided in [configs/](configs/) and explained in [docs/CLIENTS.md](docs/CLIENTS.md):

| Client | Template |
| --- | --- |
| Antigravity | [configs/antigravity.mcp_config.json](configs/antigravity.mcp_config.json) |
| Claude Desktop | [configs/claude_desktop_config.json](configs/claude_desktop_config.json) |
| Claude Code | [configs/claude_code.mcp.json](configs/claude_code.mcp.json) |
| OpenAI Codex | [configs/codex.config.toml](configs/codex.config.toml) |
| Cursor | [configs/cursor.mcp.json](configs/cursor.mcp.json) |
| Generic STDIO / HTTP | [configs/generic_mcp.json](configs/generic_mcp.json) |

Replace `C:\path\to\maycad-mcp` in the chosen config with your cloned directory path and set `PYTHONUTF8=1`.

---

## CLI & Python SDK Usage

### Standalone CLI (`maycad`)

The CLI works completely independently of the MCP Server with UTF-8 Chinese path support, `--json`, `--dry-run`, `--timeout`, and automatic `.maycad_backups/` write protection ([docs/CLI.md](docs/CLI.md)):

```powershell
# Inspect environment
maycad doctor --json

# Search catalog & inspect profile moments of inertia
maycad catalog search 4040 --series 40 --json
maycad catalog profile PROF40-4040L --json

# Generate a 2000 x 800 x 900 mm workbench, resize to 2400 mm, export STEP & BOM & screenshot
maycad design create-workbench --output bench.scene --length 2000 --width 800 --height 900 --json
maycad design update-parameters --project bench.scene --params-json '{"length_mm": 2400}' --output bench_2400.scene --json
maycad export step --project bench_2400.scene --output bench_2400.step --json
maycad export bom --project bench_2400.scene --output bom.csv --format csv --json
maycad view screenshot --project bench_2400.scene --output iso.png --view isometric --width 900 --height 900 --json
```

### Python SDK (`MayCADSDK`)

```python
from maycad_mcp.sdk import MayCADSDK

sdk = MayCADSDK()
status = sdk.run_diagnostics()
assert status["ok"]

# Create a parametric frame and auto-connect joints with native MayTec connectors
sdk.create_frame("cube.scene", frame_type="cube_frame", length_mm=800, width_mm=600, height_mm=600)
sdk.auto_connect("cube.scene", style="internal")

# Run geometry interference check, export STEP + BOM, and render isometric PNG
collisions = sdk.check_collision("cube.scene")
sdk.export_step("cube.scene", "cube.step")
sdk.export_bom("cube.scene", "cube_bom.json", fmt="json")
sdk.screenshot("cube.scene", "cube_iso.png", view="isometric", width=960, height=960)
```

---

## Repository Structure

```text
maycad-mcp/
├── src/maycad_mcp/
│   ├── sdk/                # Unified MayCADSDK public facade
│   ├── server.py           # Official MCP Server (STDIO & Bearer Streamable HTTP)
│   ├── cli.py              # Standalone `maycad` CLI
│   ├── tools/              # 75 MCP tools across 9 domain modules
│   ├── backends/           # Isolated python27.dll loopback-TCP worker, safety locks, read-only UI monitor
│   ├── scene/              # .scene v14 XML + AES-256-CBC lossless parser & atomic writer
│   ├── catalog/            # Read-only interface over fdcatalogMAYTEC.bindata
│   ├── geometry/           # Millimeter coordinate transforms, outer/centerline/cut envelopes, OBB SAT, joints
│   ├── modeling/           # Add, move, rotate, resize, copy, mirror, array, batch operations
│   ├── assembly/           # Connectors, panels, endcaps, leveling feet, casters, corner pieces, brackets
│   ├── parametric/         # 13 parametric frame/workbench/gantry/enclosure topologies & linked updates
│   ├── analysis/           # Interference, missing connectors, 1D FFD cut optimizer, beam deflection heuristic
│   ├── exporters/          # AP214 STEP (transfer.exe verified), DXF, BOM, CutList, PDF, Markdown/JSON reports
│   └── visualization/      # Headless hardware OpenGL FBO screenshot controller
├── tests/
│   ├── unit/               # Unit tests for catalog, geometry, safety locks, .scene roundtrip
│   ├── integration/        # Live Py27 kernel, catalog, SDK E2E, exporters/CLI, STDIO MCP tests
│   └── fixtures/           # 13 minimal contrast .scene fixtures & diff summary
├── examples/
│   ├── workbench_acceptance/ # 17-step live MCP workbench acceptance suite & exports
│   └── eight_corners_demo/   # 8-distinct-corner cube frame built live via MCP STDIO
├── configs/                # Ready-to-use MCP client configurations
├── scripts/                # PowerShell install, health check, test, and launch helpers
├── docs/                   # SCENE_FORMAT.md, TOOLS.md, CLI.md, CLIENTS.md, TROUBLESHOOTING.md, roadmap
├── RESEARCH.md             # Deep reverse-engineering & architecture research report on MayCAD 12.10
├── CHANGELOG.md            # Release changelog
└── LICENSE                 # MIT License
```

---

## Documentation Index

- [Technical Architecture Research (`RESEARCH.md`)](RESEARCH.md) — Complete MayCAD 12.10 binary, bytecode, registry, UIA, and kernel investigation report
- [`.scene` v14 Format Specification (`docs/SCENE_FORMAT.md`)](docs/SCENE_FORMAT.md) — Empirical reverse-engineering across 16 official samples and 13 contrast scenes
- [MCP Tools Reference (`docs/TOOLS.md`)](docs/TOOLS.md) — Complete specification of all 75 MCP tools
- [CLI Manual (`docs/CLI.md`)](docs/CLI.md) — Subcommands, exit codes, `--json`, and `--dry-run` usage
- [Client Integration Guide (`docs/CLIENTS.md`)](docs/CLIENTS.md) — Antigravity, Codex, Claude Code, Claude Desktop, Cursor, HTTP setup
- [Known Issues & Roadmap (`docs/KNOWN_ISSUES_AND_ROADMAP.md`)](docs/KNOWN_ISSUES_AND_ROADMAP.md) — Verified capability boundaries and future enhancements
- [Troubleshooting (`docs/TROUBLESHOOTING.md`)](docs/TROUBLESHOOTING.md) — Common Windows/MayCAD/OpenGL issues and fixes
- [Workbench 17-Step Acceptance Report (`examples/workbench_acceptance/ACCEPTANCE_REPORT.md`)](examples/workbench_acceptance/ACCEPTANCE_REPORT.md)

---

## License & Legal Notice

- `maycad-mcp` is released under the [MIT License](LICENSE).
- **MayCAD** and **MayTec** are trademarks of **MayTec Aluminium Systemtechnik GmbH**. This project is an independent third-party automation and interoperability bridge and is not affiliated with or endorsed by MayTec.
- Users must hold a valid local license for MayCAD to run live kernel operations. No proprietary MayCAD executables, DLLs, bytecode archives, or product databases are included in this repository.