Skip to main content
Glama
ZedMoster

Revit MCP Server

by ZedMoster

get_view_data

Extract all text and graphical entity data from the current Revit view, including text content with positions and geometric information for lines, arcs, and circles, organized by layers in JSON-RPC format.

Instructions

读取当前视图中所有信息,包括文本和图形实体数据,遵循JSON-RPC 2.0规范。

特性:

  • 提取所有文本内容及其位置信息

  • 提取所有图形对象(线、弧、圆等)的几何信息

  • 按图层组织返回的数据

  • 完善的错误处理机制

参数: ctx (Context): FastMCP上下文对象 method (str): JSON-RPC方法名,默认为"GetViewData" params (List[dict], optional): 可选参数,默认为None

返回: dict: JSON-RPC 2.0格式的响应,结构为: 成功时: { "jsonrpc": "2.0", "result": [ { "name": "图层名称", "type": "Text", "text": "文本内容", "point": {"X": x值, "Y": y值, "Z": z值} }, { "name": "图层名称", "type": "Line", "startPoint": {"X": x1, "Y": y1, "Z": z1}, "endPoint": {"X": x2, "Y": y2, "Z": z2} }, { "name": "图层名称", "type": "Arc", "startAngle": 起始角度, "endAngle": 结束角度, "centerPoint": {"X": x, "Y": y, "Z": z}, "radius": 半径值 }, { "name": "图层名称", "type": "Circle", "centerPoint": {"X": x, "Y": y, "Z": z}, "radius": 半径值 }, ... ], "id": request_id } 失败时: { "jsonrpc": "2.0", "error": { "code": int, "message": str, "data": any }, "id": request_id }

错误代码: -32600: 无效请求 -32603: 内部错误(导出或解析时) -32700: 解析错误

示例: # 获取当前视图所有图形数据 response = get_view_data(ctx)

# 处理文本数据
texts = [item for item in response.get("result", []) if item.get("type") == "Text"]

# 处理线段数据
lines = [item for item in response.get("result", []) if item.get("type") == "Line"]

# 处理圆弧数据
arcs = [item for item in response.get("result", []) if item.get("type") == "Arc"]

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
methodNoGetViewData
paramsNo

Implementation Reference

  • get_view_data is listed in GENERAL_TOOLS for registration as an MCP tool.
    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 get_view_data and other general tools to the FastMCP server using the @tool decorator.
    # 注册通用工具
    for tool in GENERAL_TOOLS:
        server.tool()(tool)
  • Call to register_tools which includes registration of get_view_data.
    register_tools(mcp)
  • Global helper to obtain persistent RevitConnection instance, likely used within tool handlers like get_view_data.
    def get_revit_connection() -> RevitConnection:
        """
        获取或创建持久的Revit连接
    
        返回:
            RevitConnection: 与Revit的连接对象
    
        异常:
            Exception: 连接失败时抛出
        """
        global _connection, _enabled
    
        if _connection is not None:
            try:
                # 测试连接是否有效
                result = _connection.send_command("get_polyhaven_status")
                _enabled = result.get("enabled", False)
                return _connection
            except Exception as e:
                logger.warning(f"现有连接已失效: {str(e)}")
                try:
                    _connection.disconnect()
                except:
                    pass
                _connection = None
    
        # 创建新连接
        if _connection is None:
            _connection = RevitConnection(host="localhost", port=_port)
            if not _connection.connect():
                logger.error("无法连接到Revit")
                _connection = None
                raise Exception(
                    "无法连接到Revit。请确保Revit插件正在运行。")
            logger.info("已创建新的持久连接到Revit")
    
        return _connection
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 traits: it's a read operation (提取/extracts data), organizes data by layers, includes error handling with specific codes, and follows JSON-RPC 2.0规范. However, it doesn't mention performance aspects like rate limits, data size limits, or whether it requires specific permissions. The error codes add valuable context beyond basic failure modes.

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 (特性, 参数, 返回, 错误代码, 示例), but it's overly verbose. The detailed return structure (with multiple example objects) and extensive example code could be condensed, as they repeat information. The core purpose is clear upfront, but later sections include redundant details that don't all earn their place.

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 no annotations, 0% schema coverage, and no output schema, the description does a good job compensating. It fully explains parameters, return format (with success/failure structures), error codes, and provides usage examples. However, it lacks context about when this tool is appropriate versus siblings, and doesn't cover edge cases like empty views or large data sets.

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?

Schema description coverage is 0%, so the description must compensate. It documents all 2 parameters: 'method' (JSON-RPC method name, defaults to 'GetViewData') and 'params' (optional list of dicts, defaults to None). It explains their roles in the JSON-RPC context, which the schema alone doesn't provide. However, it doesn't detail what 'params' might contain or when to use it, leaving some ambiguity.

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: '读取当前视图中所有信息,包括文本和图形实体数据' (reads all information from the current view, including text and graphic entity data). It specifies the verb (读取/read), resource (当前视图/current view), and scope (所有信息/all information). This distinguishes it from siblings like 'get_selected_elements' (which gets only selected elements) or 'find_elements' (which searches with criteria).

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing an active view), exclusions (e.g., not for editing), or comparisons to sibling tools like 'get_selected_elements' or 'find_elements'. The example shows basic usage but lacks contextual decision-making advice.

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