Dll to mcp tool

From shuotao/REVIT_MCP_study · View interactive version

Dll to mcp tool is an AI agent skill from the GitHub repository shuotao/REVIT_MCP_study. Wrap a standalone Revit IExternalCommand (.cs / DLL, WPF dialog allowed) into a revit-mcp MCP tool. Generates the C# command handler + switch case + TypeScript tool definition, builds, dual-path deploys, guides the restart, auto-verifies the tool is live, then commits (never pushes). Use when the us

How to use this skill

Skill file

DLL → revit-mcp tool

Convert a standalone Revit add-in command (single .cs, IExternalCommand, may contain a WPF dialog) into a revit-mcp MCP tool, following the established two-layer architecture.

This skill targets Tier 0 (current architecture): every tool is compiled into RevitMCP.dll, so a C# change requires the user to restart Revit once. The skill automates everything except the Revit restart, and auto-verifies the tool is live so the user never has to guess.

Core concept (explain to the user if they are non-expert)

A revit-mcp tool is two layers, not one DLL:

A WPF dialog in the source does not become a tool — it disappears and each field it collected becomes a tool parameter. The AI drives the tool headless; nobody clicks the dialog.

Inputs

A .cs file path (or pasted code) of a standalone IExternalCommand. Default assumptions: Revit 2026, C#, target Release.R26.

Repo paths (REVIT_MCP_study)

| What | Path |

|---|---|

| C# command handlers (partials) | MCP/Core/Commands/CommandExecutor.<Name>.cs |

| C# dispatch switch | MCP/Core/CommandExecutor.cs |

| TS tool modules | MCP-Server/src/tools/<area>-tools.ts |

| TS registry (profiles) | MCP-Server/src/tools/index.ts (generic bridge in revit-tools.ts, no edit needed) |

| C# build config | Release.R26 → output MCP/bin/Release.R26/RevitMCP.dll |

| Deploy targets (BOTH) | %APPDATA%\Autodesk\Revit\Addins\2026\RevitMCP\ and C:\ProgramData\Autodesk\Revit\Addins\2026\RevitMCP\ |

Procedure

1. Read & analyze

Read the .cs. Separate the WPF dialog (the inputs it collects) from the core logic (the Revit work). List every dialog field and what it feeds.

2. Propose tool split + param mapping — ASK

Use AskUserQuestion to confirm:

3. Confirm tool name + description — ASK

snake_case name(s), one-line Chinese description per tool, and inputSchema (params, required vs optional, defaults).

4. Generate C# handler

Create MCP/Core/Commands/CommandExecutor.<Name>.cs. Template:

using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Newtonsoft.Json.Linq;

#if REVIT2025_OR_GREATER
using IdType = System.Int64;
#else
using IdType = System.Int32;
#endif

namespace RevitMCP.Core
{
    public partial class CommandExecutor
    {
        #region <Name>

        private object <Name>(JObject parameters)
        {
            Document doc = _uiApp.ActiveUIDocument.Document;
            // ... ported core logic; read params via parameters["x"]?.Value<T>() / as JArray
            // wrap model edits in: using (Transaction trans = new Transaction(doc, "...")) { trans.Start(); ... trans.Commit(); }
            // use FilteredElementCollector + native ElementFilter (not LINQ Where for the heavy filter)
            // use Id.GetIdValue() for cross-version ElementId values
            return new { Success = true, /* structured stats that the dialog used to show */ };
        }

        #endregion
    }
}

Porting rules:

5. Wire C# dispatch

In MCP/Core/CommandExecutor.cs, add inside the switch:

                    case "<tool_name>":
                        result = <Name>(parameters);
                        break;

6. Generate TS tool

Add a Tool object to the most relevant MCP-Server/src/tools/<area>-tools.ts array (the bridge in revit-tools.ts maps toolName → commandName 1:1 automatically — no edit there). Match the existing inline style:

    {
        name: "<tool_name>",
        description: "<一句話中文描述>",
        inputSchema: {
            type: "object",
            properties: { /* params */ },
            // required: [...] only if truly required
        },
    },

If the tool belongs to a brand-new module file, also import + add it to the relevant profile arrays in MCP-Server/src/tools/index.ts.

7. Build both

8. Dual-path deploy (handle the Revit lock)

The active RevitMCP.dll (loaded from the APPDATA path) is locked while Revit runs. So:

  1. Check Get-Process Revit. If running, tell the user to save & close Revit, then continue.
  2. Copy MCP/bin/Release.R26/RevitMCP.dll to both:

(dual-path is required — otherwise an old copy can load first.)

  1. Verify both copies have the new size + timestamp.

9. Restart guidance (Tier 0 — user does this)

Tell the user, in order:

  1. Reopen Revit → open the model → enable the MCP service in the ribbon.
  2. In Claude Code, run /mcp → reconnect revit-mcp (this restarts only the node subprocess and reloads the tool list — no full Claude Code restart needed, and the current conversation is preserved).

10. Auto-verify (don't make the user guess)

After the user is back, verify the tool is live: load its schema with ToolSearch (select:mcp__revit-mcp__<tool_name>) or list revit-mcp tools, and report:

11. Live test

Call the new tool on the active project with a real argument. First re-anchor active state (get_project_info / get_all_levels / get_active_view) per repo CLAUDE.md, then call the tool and read the structured result back to the user.

12. Commit — only after live test passes (NEVER push)

Per the user's standing rule (one tool = one commit) and confirmed preference:

```

feat: add <tool_name> MCP tool (wrapped from <source>)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

```

13. Housekeeping — REMIND, don't auto-churn

After commit, remind (and offer to do, but don't silently do):

Guardrails

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.