About 如何创建和生成 MCP DLL 文件以供 CallFunc 调用
A guide for developers creating C# DLLs for the Revit MCP service, so methods can be invoked dynamically through CallFunc. It covers implementing the required interface, JSON-RPC 2.0 interaction, and building and placing the DLL.
Key features
- 01Implement the IMCPMethod interface
- 02Use JSON-RPC 2.0 interactions
- 03Build and deploy an MCP DLL
- 04Invoke methods through CallFunc
Use cases
- 01Create Revit elements such as levels
- 02Add custom methods to the Revit MCP service
MCP support
Explains how to implement DLL methods for dynamic invocation by the Revit MCP service and call them through CallFunc.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.
Tools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project README如何创建和生成 MCP DLL 文件以供 CallFunc 调用
本文档介绍如何创建一个 MCP DLL 文件,以供 CallFunc 方法调用。 MCP DLL 文件需要实现接口 xml.Revit.MCP.Public.IMCPMethod, 并按照 JSON-RPC 2.0 规范与 Revit 的 MCP 服务进行交互。
MCP DLL 的结构和实现
创建一个实现类
实现 IMCPMethod 接口
以下是一个实现类的示例,用于创建标高并返回新标高ElementModelRequest:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.UI;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using xml.Revit.MCP.Models;
using xml.Revit.MCP.Public;
using xml.Revit.Toolkit.Attributes;
using xml.Revit.Toolkit.Extensions;
using xml.Revit.Toolkit.Utils;
namespace xml.Revit.MCPServer
{
/// <summary>
/// 实现新增标高功能的类,继承自 IMCPMethod 接口。
/// </summary>
public sealed class TopLevelAdd : IMCPMethod
{
/// <summary>
/// 构造函数,初始化方法名称。
/// </summary>
public TopLevelAdd()
{
MethodName = "新增标高";
}
/// <summary>
/// 方法名称,用于标识当前功能。
/// </summary>
public string MethodName { get; private set; }
/// <summary>
/// 执行新增标高的核心逻辑。
/// </summary>
/// <param name="request">包含请求参数的 JsonRPCRequest 对象。</param>
/// <param name="uidoc">当前 Revit 的 UIDocument 对象。</param>
/// <returns>返回一个 JsonRPCResponse 对象,包含执行结果。</returns>
public JsonRPCResponse Execute(JsonRPCRequest request, UIDocument uidoc)
{
// 初始化响应对象
var jsonResponse = new JsonRPCResponse();
// 获取当前文档
var doc = uidoc.Document;
// 默认标高偏移量,单位为毫米
double elevationOffset = 3000d;
// 从请求参数中解析标高偏移量
var obj = request.Params as JObject;
if (obj != null)
{
elevationOffset = obj["offset"].Value<double>();
}
// 获取文档中的最高标高
var highestLevel = doc.OfClass<Level>().OrderBy(l => l.Elevation).LastOrDefault();
if (highestLevel == null)
{
throw new InvalidOperationException("未找到有效的标高。");
}
// 开启事务并创建新标高
doc.Transaction(t =>
{
var newLevel = Level.Create(
doc,
highestLevel.Elevation + elevationOffset.MMToFeet() // 偏移量转换为英尺
);
// 将新标高信息封装到响应结果中
jsonResponse.Result = new ElementModelRequest(newLevel);
});
return jsonResponse; // 返回响应对象
}
}
}
在 Visual Studio 中编译项目,生成 .dll 文件。
编译后,确保生成的 .dll 文件位于指定的 MCP 文件夹中。

通过以上步骤,您可以轻松创建和生成 MCP DLL 文件,并将其集成到 Revit 的 MCP 服务中进行动态调用。

mcp-tool
在大模型中直接通过CallFunc 按一下提示词即可实现
response = call_func(ctx, params=[
{"name": "新增标高", "params": {"offset": 3000}}
])
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.