get_current_view_info
Retrieve details of the active view in Revit, including view type, name, and scale, to access current project context.
Instructions
获取 Revit 当前活动视图的详细信息,包括视图类型、名称、比例等属性。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/get_current_view_info.ts:9-35 (handler)The core handler logic for the 'get_current_view_info' tool. It connects to Revit, sends the command, and returns the view information as JSON or an error message.async (args, extra) => { try { const response = await withRevitConnection(async (revitClient) => { return await revitClient.sendCommand("get_current_view_info", {}); }); return { content: [ { type: "text", text: JSON.stringify(response, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `get current view info failed: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } }
- src/tools/get_current_view_info.ts:4-37 (registration)Registers the 'get_current_view_info' tool on the MCP server with name, description, empty input schema, and inline handler. This function is dynamically invoked by src/tools/register.ts.export function registerGetCurrentViewInfoTool(server: McpServer) { server.tool( "get_current_view_info", "获取 Revit 当前活动视图的详细信息,包括视图类型、名称、比例等属性。", {}, async (args, extra) => { try { const response = await withRevitConnection(async (revitClient) => { return await revitClient.sendCommand("get_current_view_info", {}); }); return { content: [ { type: "text", text: JSON.stringify(response, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `get current view info failed: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } } ); }
- src/tools/register.ts:6-48 (registration)Central registration module that dynamically loads and registers all tools, including 'get_current_view_info' by calling registerGetCurrentViewInfoTool.export async function registerTools(server: McpServer) { // 获取当前文件的目录路径 const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); // 读取tools目录下的所有文件 const files = fs.readdirSync(__dirname); // 过滤出.ts或.js文件,但排除index文件和register文件 const toolFiles = files.filter( (file) => (file.endsWith(".ts") || file.endsWith(".js")) && file !== "index.ts" && file !== "index.js" && file !== "register.ts" && file !== "register.js" ); // 动态导入并注册每个工具 for (const file of toolFiles) { try { // 构建导入路径 const importPath = `./${file.replace(/\.(ts|js)$/, ".js")}`; // 动态导入模块 const module = await import(importPath); // 查找并执行注册函数 const registerFunctionName = Object.keys(module).find( (key) => key.startsWith("register") && typeof module[key] === "function" ); if (registerFunctionName) { module[registerFunctionName](server); console.error(`已注册工具: ${file}`); } else { console.warn(`警告: 在文件 ${file} 中未找到注册函数`); } } catch (error) { console.error(`注册工具 ${file} 时出错:`, error); } } }
- src/index.ts:14-14 (registration)Invocation of the tools registration in the main server setup.await registerTools(server);