get_levels
Extract all floor levels from a Revit model for efficient analysis and project management using the Revit MCP Server.
Instructions
获取 Revit 模型中的所有楼层
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/revitService.ts:88-95 (handler)Handler function for the 'get_levels' MCP tool. Delegates the execution to the underlying Revit socket client to fetch levels.async getLevels(): Promise<any[]> { try { return await this.client.getLevels(); } catch (error) { console.error('[RevitService] 获取楼层失败,使用模拟数据:', error); throw error; // 不使用模拟数据,直接抛出错误 } }
- src/revitSocketClient.ts:211-213 (helper)Low-level helper function that sends the 'get_levels' RPC request over the socket to the Revit server.public async getLevels(sortByElevation: boolean = true): Promise<any[]> { const response = await this.sendRequest<any[]>('get_levels', { }); return response;
- src/index.ts:161-167 (schema)Schema definition for the 'get_levels' tool used in tool discovery (ListTools response), specifying name, description, and empty input schema.name: "get_levels", description: "获取 Revit 模型中的所有楼层", inputSchema: { type: "object", properties: {} } }, {
- src/index.ts:201-238 (registration)Registers the CallToolRequestSchema handler, which dynamically maps tool name 'get_levels' to revitService.getLevels() execution.this.server.setRequestHandler( CallToolRequestSchema, async (request) => { // 获取工具名称 const toolName = request.params.name; // 将工具名称转换为 camelCase 方法名 const methodName = toolName.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase()); // 检查 RevitService 是否有对应的方法 if (typeof (this.revitService as any)[methodName] !== 'function') { throw new McpError( ErrorCode.MethodNotFound, `未知工具: ${toolName}` ); } try { // 动态调用对应的方法 const result = await (this.revitService as any)[methodName](request.params.arguments || {}); //const result = ''; return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Revit API 错误: ${error instanceof Error ? error.message : String(error)}` }], isError: true, } } } );