Skip to main content
Glama
MAvinash24

Autodesk CAD MCP & RAG Assistant

by MAvinash24

Autodesk CAD MCP & RAG Assistant ๐Ÿš€

CI Pipeline License: MIT C++ Python Protocol FastAPI

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

git clone https://github.com/MAvinash24/autodesk-cad-mcp-agent.git
cd autodesk-cad-mcp-agent

Step 2: Install Python Dependencies

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++):

scripts\build.bat

Or manual MSVC compile:

cl /O2 /LD /EHsc core\geometry_engine.cpp /Fe:geometry.dll

On Linux:

g++ -O3 -shared -fPIC -o libgeometry.so core/geometry_engine.cpp

On macOS:

clang++ -O3 -shared -fPIC -o libgeometry.dylib core/geometry_engine.cpp

Step 4: Run the Microservice

python server/main.py

The server will bind to http://127.0.0.1:8000.


๐Ÿงช Running Automated Tests

Run the full test suite with verbose reporting:

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:

{
  "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 /

curl -X GET http://127.0.0.1:8000/

Response:

{
  "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

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:

{
  "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

curl -X GET "http://127.0.0.1:8000/api/v1/rag/search?query=extrude+fusion+volume&top_k=2"

Response:

{
  "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

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

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:

{
  "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.