open_document.ts•1.07 kB
import { z } from 'zod';
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { withRevitConnection } from '../utils/ConnectionManager.js';
export function registerOpenDocumentTool(server: McpServer) {
server.tool(
'open_document',
'Open Document',
{
filePath: z.string().optional().describe('File Path'),
},
async (args, extra) => {
const params = {
filePath: args.filePath,
};
try {
const response = await withRevitConnection(async (revitClient) => {
return await revitClient.sendCommand('open_document', params);
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response, null, 2),
},
],
};
} catch (error) {
return {
content: [
{
type: 'text',
text: `document open failed: ${error instanceof Error ? error.message : String(error)}`,
},
],
};
}
}
);
}