Content
# Revit MCP - Communicate with revit document using NLP
<img width="1919" height="1079" alt="image (1)" src="https://github.com/user-attachments/assets/42e33413-81c9-488c-bb5f-b65bdcd17a66" />
A desktop AI assistant built for **Autodesk Revit automation** using **WPF (.NET 8)**, **Google Gemini API**, and a custom **.NET MCP Server**.
The application allows users to enter natural language prompts like:
- "Get me the length of wall 954726"
- "List all rooms on Level 1"
- "Get floor area of Level 2"
- "Open this Revit file and close it after"
Gemini acts as the reasoning engine, deciding which tools to call and executing multi-step workflows automatically — opening Revit, extracting data, and closing the document without any human intervention.
---
## Solution Structure
```
Revit MCP/
├── UI/ # WPF Desktop Application (.NET 8)
├── RevitMCP.AI/ # Gemini AI orchestration layer (.NET 8)
├── RevitMCP.Server/ # .NET MCP Server (.NET 8)
└── RevitMCP.Addin/ # Revit Add-in (.NET Framework 4.8)
```
---
## Architecture
### 1. WPF Desktop UI (`UI`)
Modern desktop interface built with:
- Prompt input + Send button
- `.rvt` file path selector (Browse dialog)
- Status bar (Thinking... / Done / Error)
- Response display panel
- MVVM pattern (`MainViewModel`, `BaseViewModel`, `RelayCommand`)
- `async/await` throughout — UI never blocks
### 2. AI Reasoning Layer (`RevitMCP.AI`)
Handles the full Gemini tool-use loop:
- Sends user prompt + file path + MCP tool schema to Gemini
- Receives `tool_use` responses from Gemini
- Calls the MCP server via `McpClientService` (MCP protocol over stdio)
- Sends `tool_result` back to Gemini
- Loops until Gemini returns a final text answer
- Returns answer to WPF UI
**Key files:**
- `GeminiService.cs` — main orchestration, tool loop, conversation history
- `McpClientService.cs` — MCP client using `ModelContextProtocol` 1.3.0
- `AppConfig.cs` — reads Gemini API key from `appsettings.json`
- `Models/GeminiRequest.cs` — request shape including `thoughtSignature` support
- `Models/GeminiResponse.cs` — response shape
- `Models/ToolDefinition.cs` — MCP tool schema sent to Gemini
**Model:** `gemini-2.5-flash` via Google AI Studio API
### 3. .NET MCP Server (`RevitMCP.Server`)
Local console process that:
- Runs as a child process launched by `McpClientService`
- Communicates with Gemini layer over **stdio** (MCP protocol)
- Exposes Revit tools via `[McpServerTool]` attributes
- Forwards tool calls to the Revit add-in via **named pipe** (`RevitMCPPipe`)
**Exposed tools:**
- `open_revit_document(file_path)` — opens a `.rvt` file
- `get_wall_length(wall_id)` — returns wall length in meters
- `get_floor_area(level_name)` — returns floor area in m²
- `list_rooms_by_level(level_name)` — lists all rooms with areas
- `close_revit_document()` — closes the open document
**Key files:**
- `Program.cs` — MCP server host with stdio transport
- `Tools/RevitDocumentTools.cs` — open/close tools
- `Tools/RevitQueryTools.cs` — geometry and query tools
- `Pipe/RevitPipeClient.cs` — named pipe client with retry logic
### 4. Revit Add-in (`RevitMCP.Addin`)
A `.NET Framework 4.8` Revit add-in that:
- Loads automatically when Revit 2024 starts (via `.addin` manifest)
- Starts a named pipe server (`RevitMCPPipe`) on startup
- Listens for JSON commands from the MCP server
- Executes Revit DB API calls **on Revit's main thread** via `IExternalEventHandler`
- Returns real Revit data as JSON back over the pipe
**Key files:**
- `App.cs` — `IExternalApplication` entry point
- `PipeServer/RevitPipeServer.cs` — named pipe server + command router
- `Commands/RevitDataExtractor.cs` — Revit DB API queries (walls, floors, rooms)
**Manifest location:**
```
C:\ProgramData\Autodesk\Revit\Addins\2024\RevitMCP.addin
```
```
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<RevitAddIns>
<AddIn Type="Application">
<Assembly>dll_path</Assembly>
<AddInId>guid</AddInId>
<FullClassName>Namespace.classname</FullClassName>
<Name>REVIT_MCP</Name>
<Text>REVIT_MCP</Text>
<VendorId>Rushikesh</VendorId>
<VendorDescription>www.ru5hikesh.com</VendorDescription>
<AllowLoadIntoExistingSession>1</AllowLoadIntoExistingSession>
</AddIn>
</RevitAddIns>
```
---
## Full Request Flow
```
User types prompt in WPF UI
↓
GeminiService.SendPromptAsync()
↓ HTTPS
Google Gemini API (gemini-2.5-flash)
↓ tool_use: open_revit_document
McpClientService.CallToolAsync()
↓ stdio (MCP protocol)
RevitMCP.Server.exe
↓ named pipe (RevitMCPPipe)
RevitMCP.Addin (inside Revit.exe)
↓ Revit DB API
Real Revit data (.rvt file)
↑ JSON result
Back through pipe → MCP server → Gemini
↑ tool_result
Gemini reasons, calls more tools if needed
↑ final text answer
ResponseText shown in WPF UI
```
---
## Communication Boundaries
| Boundary | Protocol | Why |
|---|---|---|
| UI → AI layer | Direct C# method call | Same process |
| AI layer → Gemini | HTTPS (REST) | Cloud API |
| AI layer → MCP server | stdio (MCP protocol) | Parent/child process |
| MCP server → Revit add-in | Named pipe | Two independent processes |
| Add-in → Revit DB API | In-process | Same runtime |
---
## Why Two Runtime Boundaries?
The Revit add-in must be **.NET Framework 4.8** — Revit only loads Framework assemblies. Everything else is **.NET 8**. The named pipe is the only way to cross this runtime boundary cleanly.
---
## Prerequisites
- Autodesk Revit 2024 installed
- .NET 8 SDK
- .NET Framework 4.8
- Google Gemini API key (free tier from [aistudio.google.com](https://aistudio.google.com))
---
## Setup
**1. Add Gemini API key**
In `RevitMCP.AI/appsettings.json`:
```json
{
"GeminiApiKey": "your_key_here"
}
```
**2. Place the addin manifest**
Copy `RevitMCP.addin` to:
```
C:\ProgramData\Autodesk\Revit\Addins\2024\
```
**3. Build solution**
Build all 4 projects. Ensure `RevitMCP.Server.exe` ends up in the same output folder as `UI.exe`.
**4. Run**
1. Open Revit 2024 — add-in loads automatically
2. Open any `.rvt` file in Revit
3. Run the UI (`UI.exe`)
4. Browse to your `.rvt` file
5. Type a prompt and hit Send
---
## Tech Stack
| Layer | Technology |
|---|---|
| Desktop UI | WPF, .NET 8, MVVM |
| AI Reasoning | Google Gemini API (`gemini-2.5-flash`) |
| Tool Protocol | Model Context Protocol (MCP) 1.3.0 |
| MCP Server | .NET 8 Console, `ModelContextProtocol` NuGet |
| Revit Integration | .NET Framework 4.8, Revit DB API |
| Logging | Serilog |
| IPC | Named Pipes (`System.IO.Pipes`) |
---
## Goal
To make Revit data extraction accessible through plain English commands — no manual clicks, no scripting, no Revit API knowledge required from the user.