Autodesk CAD MCP & RAG Assistant
by MAvinash24
README.md
# Autodesk CAD MCP & RAG Assistant ๐
[](https://github.com/MAvinash24/autodesk-cad-mcp-agent)
[](https://opensource.org/licenses/MIT)
[](https://isocpp.org/)
[](https://python.org/)
[-purple.svg)](https://modelcontextprotocol.io)
[](https://fastapi.tiangolo.com/)
An enterprise-grade agentic microservice bridging high-speed **C++** 3D geometry evaluation with **Python (FastAPI)**, Anthropic's **Model Context Protocol (MCP)**, and a **RAG** (Retrieval-Augmented Generation) knowledge engine grounded on Autodesk APIs (Fusion 360, APS / Forge, Revit, and Inventor).
---
## ๐ Key Highlights
- **Model Context Protocol (MCP) JSON-RPC 2.0**: Full compliance with the Anthropic open standard, enabling autonomous agents (Claude Desktop, local LLMs) to discover tools via `tools/list` and invoke CAD calculations via `tools/call`.
- **Native C++ Geometry Core**: Offloads compute-heavy 3D mesh evaluation (bounding volumes, surface areas, and extents) to a compiled C++17 shared library (`geometry.dll` / `libgeometry.so`) via zero-overhead `ctypes`.
- **Zero-Crash Resilience**: Built-in high-performance pure-Python fallback path ensures uninterrupted service even when dynamic libraries are unavailable.
- **Autodesk Domain RAG Index**: In-memory semantic vector and keyword retrieval grounding LLMs on official Autodesk APIs (Fusion 360 `ExtrudeFeature`, APS `Model Derivative`, Revit `BoundingBoxXYZ`, Inventor `MassProperties`), eliminating hallucinations.
- **Dual Interface**: Exposes standardized MCP JSON-RPC (`/mcp`) and interactive OpenAPI/Swagger REST endpoints (`/api/v1/...`).
- **Production SDLC**: 100% test coverage with `pytest`, parameterized parity checks between C++ and Python engines, and a multi-OS GitHub Actions CI/CD matrix.
---
## ๐ System Architecture
```
+-----------------------------------+
| AI Host / Autonomous Agent |
| (Claude Desktop / Cursor / LLM)|
+-----------------------------------+
|
| JSON-RPC 2.0 (MCP Protocol)
v
+-----------------------------------------------------------------------------------+
| FastAPI Microservice (server/main.py) |
| |
| [ Endpoint: /mcp ] [ Endpoint: /api/v1/geometry ] |
| MCP Protocol router Direct REST CAD calculations |
| |
| [ Endpoint: /api/v1/rag ] [ Endpoint: / ] |
| Vector documentation search Health check & C++ engine telemetry |
+-----------------------------------------------------------------------------------+
| |
| |
v v
+-----------------------------+ +-----------------------------------+
| Semantic RAG Engine | | Native C++ Geometry Bridge |
| (server/rag_engine.py) | | (server/mcp_tools.py) |
| | | |
| - Tokenization & Scoring | | ctypes Foreign Function Interface|
| - Autodesk API Knowledge | +-----------------------------------+
| (Fusion, APS, Revit) | |
+-----------------------------+ v
| +-----------------------------------+
v | Compiled C++ Geometry Core |
data/autodesk_docs.json | (core/geometry_engine.cpp) |
| |
| - SIMD / O3 Optimized Loops |
| - Bounding Volume & Surface Area |
| - Extents & Centroid Math |
+-----------------------------------+
```
---
## ๐ Repository Structure
```
autodesk-cad-mcp-agent/
โ
โโโ core/
โ โโโ geometry_engine.cpp # High-speed C++ geometry evaluation core
โ โโโ CMakeLists.txt # CMake build configuration for shared library
โ
โโโ server/
โ โโโ __init__.py # Python package initialization
โ โโโ main.py # FastAPI REST & MCP JSON-RPC 2.0 Server
โ โโโ rag_engine.py # Semantic RAG retrieval engine
โ โโโ mcp_tools.py # MCP tool definitions & C++ ctypes bridge
โ
โโโ tests/
โ โโโ __init__.py # Tests package initialization
โ โโโ test_geometry.py # Pytest suite for geometry math & parity
โ โโโ test_mcp_api.py # Pytest suite for REST & MCP endpoints
โ
โโโ data/
โ โโโ autodesk_docs.json # Autodesk API & CAD engineering knowledge base
โ
โโโ scripts/
โ โโโ build.bat # 1-click Windows compilation script (MSVC/g++)
โ
โโโ .github/
โ โโโ workflows/ci.yml # Multi-OS GitHub Actions CI/CD matrix
โ
โโโ requirements.txt # Production and test Python dependencies
โโโ Makefile # Cross-platform build automation
โโโ .gitignore # Git ignore configuration
โโโ README.md # Comprehensive project documentation
```
---
## โก Quickstart Guide
### Prerequisites
- **Python**: Version 3.10 or higher
- **C++ Compiler**:
- **Windows**: MSVC 2019/2022 (Build Tools) or MinGW `g++`
- **Linux**: `g++` (GCC 9+)
- **macOS**: `clang++` (Apple Clang)
---
### Step 1: Clone Repository
```bash
git clone https://github.com/MAvinash24/autodesk-cad-mcp-agent.git
cd autodesk-cad-mcp-agent
```
### Step 2: Install Python Dependencies
```bash
pip install -r requirements.txt
```
### Step 3: Compile the C++ Engine
#### On Windows:
Run the included 1-click build batch script (automatically detects MSVC `cl` or `g++`):
```cmd
scripts\build.bat
```
*Or manual MSVC compile:*
```cmd
cl /O2 /LD /EHsc core\geometry_engine.cpp /Fe:geometry.dll
```
#### On Linux:
```bash
g++ -O3 -shared -fPIC -o libgeometry.so core/geometry_engine.cpp
```
#### On macOS:
```bash
clang++ -O3 -shared -fPIC -o libgeometry.dylib core/geometry_engine.cpp
```
---
### Step 4: Run the Microservice
```bash
python server/main.py
```
The server will bind to `http://127.0.0.1:8000`.
- **Interactive Swagger Documentation**: [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs)
- **ReDoc Documentation**: [http://127.0.0.1:8000/redoc](http://127.0.0.1:8000/redoc)
- **MCP JSON-RPC Endpoint**: `http://127.0.0.1:8000/mcp`
---
## ๐งช Running Automated Tests
Run the full test suite with verbose reporting:
```bash
pytest tests/ -v
```
### Test Coverage Summary:
- `test_geometry.py`: Validates unit cubes, bounding extents, empty arrays, degenerate single-point inputs, and strict parity between native C++ and pure-Python execution paths.
- `test_mcp_api.py`: Validates health telemetry, REST endpoints, MCP `initialize`, `ping`, `tools/list`, `tools/call`, and standardized JSON-RPC error codes (`-32601`, `-32602`).
---
## ๐ Connecting to Claude Desktop / MCP Clients
To use this CAD assistant inside **Claude Desktop**, add the server to your `claude_desktop_config.json`:
```json
{
"mcpServers": {
"autodesk-cad-agent": {
"command": "python",
"args": ["-m", "server.main"]
}
}
}
```
Once connected, Claude can autonomously reason:
> *"Claude, analyze this 3D bracket mesh with vertices `[0,0,0, 10,5,2]` and find the Fusion 360 API class to extrude it."*
Claude will:
1. Invoke `calculate_cad_mesh_metrics` via MCP to compute exact volume and surface area.
2. Invoke `search_autodesk_api_knowledge` to retrieve the `ExtrudeFeatureInput` specification.
3. Return synthesized, hallucination-free CAD automation code.
---
## ๐ก API Reference & Usage Examples
### 1. Health Check & Engine Telemetry
**GET** `/`
```bash
curl -X GET http://127.0.0.1:8000/
```
**Response:**
```json
{
"status": "healthy",
"service": "Autodesk CAD MCP + RAG Assistant",
"version": "1.0.0",
"geometry_engine": {
"is_native_cpp": true,
"engine_mode": "c++_native",
"library_path": "C:\\...\\geometry.dll"
},
"knowledge_base_count": 6,
"supported_protocols": ["MCP JSON-RPC 2.0", "REST / HTTP"]
}
```
---
### 2. High-Speed Geometry Calculation (REST)
**POST** `/api/v1/geometry/calculate`
```bash
curl -X POST http://127.0.0.1:8000/api/v1/geometry/calculate \
-H "Content-Type: application/json" \
-d '{"vertices": [0.0, 0.0, 0.0, 10.0, 5.0, 2.0]}'
```
**Response:**
```json
{
"status": "success",
"metrics": {
"bounding_volume": 100.0,
"surface_area": 160.0,
"vertex_count": 2,
"engine": "c++_native"
}
}
```
---
### 3. Autodesk API RAG Retrieval (REST)
**GET** `/api/v1/rag/search?query=extrude+fusion+volume`
```bash
curl -X GET "http://127.0.0.1:8000/api/v1/rag/search?query=extrude+fusion+volume&top_k=2"
```
**Response:**
```json
{
"query": "extrude fusion volume",
"count": 2,
"documents": [
{
"id": "doc-01",
"title": "Autodesk Fusion 360 API - ExtrudeFeature & Bounding Calculation",
"text": "The ExtrudeFeatureInput class in the Autodesk Fusion 360 API allows programmatic generation of solid bodies...",
"relevance_score": 0.5833,
"matched_keywords": ["extrude", "fusion", "volume"]
}
]
}
```
---
### 4. Model Context Protocol: `tools/list` (JSON-RPC 2.0)
**POST** `/mcp`
```bash
curl -X POST http://127.0.0.1:8000/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}}'
```
---
### 5. Model Context Protocol: `tools/call` (JSON-RPC 2.0)
**POST** `/mcp`
```bash
curl -X POST http://127.0.0.1:8000/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "calculate_cad_mesh_metrics",
"arguments": {
"vertices": [0.0, 0.0, 0.0, 2.0, 2.0, 2.0]
}
}
}'
```
**Response:**
```json
{
"jsonrpc": "2.0",
"id": 2,
"result": {
"content": [
{
"type": "text",
"text": "{\"bounding_volume\": 8.0, \"surface_area\": 24.0, \"vertex_count\": 2, \"engine\": \"c++_native\"}"
}
]
},
"error": null
}
```
---
## ๐ License
This project is open-source and licensed under the [MIT License](LICENSE).
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo issues