Skip to main content
Glama
ZedMoster

Revit MCP Server

by ZedMoster

active_view

Activate and open views in Autodesk Revit by providing view element IDs, with support for single or multiple views and automatic validation of view elements.

Instructions

激活并打开Revit中的视图,遵循JSON-RPC 2.0规范。 mcp_tool使用时params不要有任何注释信息

特性:

  • 支持打开单个或多个视图

  • 自动验证视图元素有效性

  • 过滤模板视图

  • 完善的错误处理机制

参数: ctx (Context): FastMCP上下文对象 method (str): JSON-RPC方法名,默认为"ActiveView" params (List[Dict]): 视图参数列表,每个字典包含: - elementId (Union[int, str]): 视图元素ID

返回: dict: JSON-RPC 2.0格式的响应,结构为: 成功时: { "jsonrpc": "2.0", "result": [ { "elementId": "视图元素ID", "name": "视图名称", "familyName": "视图族名称" }, ... ], "id": request_id } 失败时: { "jsonrpc": "2.0", "error": { "code": int, "message": str, "data": any }, "id": request_id }

错误代码: -32600: 无效请求 -32602: 无效参数(元素不是视图/是模板视图/无效元素) -32603: 内部错误 -32700: 解析错误

示例: # 激活单个视图 response = active_view(ctx, params=[{"elementId": 123456}])

# 激活多个视图(最后一个成功激活的视图将成为当前视图)
response = active_view(ctx, params=[
    {"elementId": 123456},
    {"elementId": "789012"}
])

# 输出示例
{
    "jsonrpc": "2.0",
    "result": [123456, 789012],
    "id": 1
}

注意: 1. 无法激活模板视图(会返回错误) 2. 如果传入多个视图ID,会依次尝试激活,最后一个成功的视图将成为当前视图 3. 返回的列表包含所有成功激活的视图ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
methodNoActiveView
paramsNo

Implementation Reference

  • The active_view tool is included in the GENERAL_TOOLS list, which contains general purpose Revit tools registered to the MCP server.
    GENERAL_TOOLS = [
        get_commands, execute_commands, call_func,
        find_elements, update_elements, delete_elements, parameter_elements, get_locations, move_elements,
        show_elements, active_view, get_selected_elements,
        link_dwg_and_activate_view, get_view_data
    ]
  • Registration loop that applies the MCP server.tool() decorator to all functions in GENERAL_TOOLS, including active_view.
    # 注册通用工具
    for tool in GENERAL_TOOLS:
        server.tool()(tool)
  • Test script demonstrating the RPC call to 'ActiveView' method, likely corresponding to the active_view MCP tool.
    send_tcp_data(json_rpc_request)
  • The send_command method in RevitConnection is used by tool handlers to send RPC commands to Revit, including for active_view which likely calls 'ActiveView' RPC.
    def send_command(self, command_type: str, params: Union[Dict[str, Any], List[Dict[str, Any]]] = None) -> Dict[
        str, Any]:
        """
        向Revit发送命令并返回响应
    
        参数:
            command_type (str): 命令类型
            params (Dict[str, Any] 或 List[Dict[str, Any]]): 命令参数
    
        返回:
            Dict[str, Any]: 命令响应
    
        异常:
            ConnectionError: 连接错误
            TimeoutError: 请求超时
            ValueError: 参数或响应无效
            Exception: 其他错误
        """
        # 确保连接
        if not self.sock and not self.connect():
            raise ConnectionError("无法连接到Revit")
    
        try:
            logger.info(f"发送命令: {command_type}")
            logger.debug(f"命令参数: {params}")
    
            # 导入并创建请求对象
            from .rpc import JsonRPCRequest, JsonRPCResponse
            command = JsonRPCRequest(method=command_type, params=params)
            command_json = json.dumps(command.__dict__)
    
            # 发送命令
            self.sock.sendall(command_json.encode('utf-8'))
            logger.debug("命令已发送,等待响应...")
    
            # 使用 receive_full_response 接收完整数据流
            response_data = self.receive_full_response()
            logger.debug(f"已接收 {len(response_data)} 字节数据")
    
            # 解析响应
            try:
                response_dict = json.loads(response_data.decode('utf-8'))
                response = JsonRPCResponse(
                    id=response_dict.get("id"),
                    result=response_dict.get("result"),
                    error=response_dict.get("error")
                )
            except json.JSONDecodeError as e:
                logger.error(f"无法解析Revit响应: {str(e)}")
                if response_data:
                    logger.error(f"原始响应 (前200字节): {response_data[:200]}")
                raise ValueError(f"无效的Revit响应: {str(e)}")
    
            # 处理错误
            if response.error:
                error_message = response.error.get("message", "未知错误")
                error_code = response.error.get("code", -1)
                error_data = response.error.get("data")
    
                logger.error(f"Revit错误 (代码: {error_code}): {error_message}")
                if error_data:
                    logger.error(f"错误数据: {error_data}")
    
                raise Exception(f"Revit错误: {error_message}")
    
            return response.result or {}
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key behaviors: supports single/multiple view activation, validates view element validity, filters template views, includes error handling, and specifies that the last successfully activated view becomes current. It also details error codes and response formats, though it doesn't cover permissions or rate limits.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with sections (特性, 参数, 返回, etc.), but it's verbose and includes redundant information (e.g., JSON-RPC 2.0 specification mentioned twice, example output partially repeats return structure). Some sentences, like the note about 'mcp_tool使用时params不要有任何注释信息', don't add clear value for an AI agent.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (2 parameters with 0% schema coverage, no output schema, no annotations), the description is highly complete. It covers purpose, parameters with semantics, return values with success/error structures, error codes, examples, and important behavioral notes (e.g., template view handling, multiple view activation behavior). No significant gaps remain for tool invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It thoroughly explains the parameters: 'ctx' as FastMCP context object, 'method' as JSON-RPC method name with default, and 'params' as a list of dictionaries with 'elementId' details. It provides examples and clarifies data types (Union[int, str]), adding significant value beyond the minimal schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: '激活并打开Revit中的视图' (activate and open views in Revit). It specifies the verb (activate/open) and resource (views in Revit), though it doesn't explicitly differentiate from sibling tools like 'get_view_data' or 'create_floor_plan_views'. The purpose is specific but lacks sibling comparison.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context through examples (activating single or multiple views) and notes (e.g., cannot activate template views). However, it doesn't explicitly state when to use this tool versus alternatives like 'get_view_data' or 'link_dwg_and_activate_view', nor does it provide clear prerequisites or exclusions beyond template view filtering.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ZedMoster/revit-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server