Skip to main content
Glama
ZedMoster

Revit MCP Server

by ZedMoster

get_selected_elements

Retrieve currently selected elements in Revit UI with IDs, categories, and names using JSON-RPC 2.0 format for automation workflows.

Instructions

获取当前Revit UI中选择的元素,遵循JSON-RPC 2.0规范。

特性:

  • 获取当前用户在Revit界面中选择的所有元素

  • 返回元素的完整信息,包括ID、类别和名称

  • 无需额外参数,直接反映当前UI状态

  • 完善的错误处理机制

参数: ctx (Context): FastMCP上下文对象 method (str): JSON-RPC方法名,默认为"GetSelectedElements"

返回: 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 }

示例: # 获取当前选择的元素 response = get_selected_elements(ctx)

# 输出示例
{
    "jsonrpc":"2.0","id":"a39934f6-0ee9-4319-b820-1eba95a82c51",
    "result":
    [
        {"elementId":"355","familyName":"标高","name":"标高 1"},
        {"elementId":"2607","familyName":"标高","name":"标高 2"},
        {"elementId":"5855","familyName":"标高","name":"T.O. Fnd. 墙"}
    ],
    "error":[]
}

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
methodNoGetSelectedElements

Implementation Reference

  • The tool 'get_selected_elements' is included in the GENERAL_TOOLS list, which is 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
    ]
  • The register_tools function registers all tools in GENERAL_TOOLS (including get_selected_elements) using server.tool() decorator.
    def register_tools(server: FastMCP) -> None:
        """注册所有工具到MCP服务器"""
        # 注册建筑工具
        for tool in ARCHITECTURAL_TOOLS:
            server.tool()(tool)
    
        # 注册MEP工具
        for tool in MEP_TOOLS:
            server.tool()(tool)
    
        # 注册通用工具
        for tool in GENERAL_TOOLS:
            server.tool()(tool)
  • Test script demonstrating the JSON-RPC call to the Revit plugin for 'GetSelectedElements', likely corresponding to the MCP tool logic.
    # -*- coding: utf-8 -*-
    
    from _tcp import send_tcp_data
    
    # 构造 JSON-RPC 请求
    json_rpc_request = {
        "jsonrpc": "2.0",
        "method": "GetSelectedElements",
        "params": {},
    }
    
    # 发送更新元素数据
    send_tcp_data(json_rpc_request)
  • The tool is referenced in the asset_creation_strategy prompt docstring.
    - 使用get_commands()获取所有可用功能
    - 使用get_selected_elements()检查当前选中的元素
Behavior4/5

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

With no annotations provided, the description carries full burden and does well. It discloses key behavioral traits: '无需额外参数,直接反映当前UI状态' (no additional parameters needed, directly reflects current UI state), '完善的错误处理机制' (comprehensive error handling), and details about the JSON-RPC 2.0 response format including success/error structures. It also mentions the tool follows JSON-RPC 2.0 specification. The description adds substantial value beyond what would be in basic annotations.

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 appropriately sized but not optimally structured. It front-loads the purpose but includes extensive technical details (JSON-RPC format, full response structures, example) that could be streamlined. The '特性' (features) section is useful, but the detailed return format explanation and lengthy example add bulk. Every sentence earns its place, but the organization could be more efficient for an AI agent.

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

Completeness4/5

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

Given the tool's moderate complexity (read operation with JSON-RPC protocol), no annotations, no output schema, and 0% schema coverage, the description provides good completeness. It covers purpose, behavior, parameters, return format, and includes an example. The main gap is lack of explicit sibling differentiation, but otherwise it gives the agent sufficient information to understand and invoke the tool correctly.

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

Parameters4/5

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

The input schema has 0% description coverage with 1 parameter (method). The description compensates by explaining: '无需额外参数' (no additional parameters needed) and that 'method' defaults to 'GetSelectedElements'. It clarifies that parameters are minimal and primarily for JSON-RPC protocol compliance rather than functional input. For a tool with effectively 0 functional parameters, this provides good semantic context.

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

Purpose5/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 UI中选择的元素' (get currently selected elements in Revit UI). It specifies the exact resource (selected elements) and verb (get), and distinguishes from siblings like 'find_elements' (search) or 'show_elements' (display). The description is specific and unambiguous about what the tool does.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool: '获取当前用户在Revit界面中选择的所有元素' (get all elements currently selected by the user in the Revit interface). It implies this is for real-time UI state reflection rather than searching or filtering. However, it doesn't explicitly state when NOT to use it or name specific alternatives among siblings, though the context makes the use case evident.

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