convert-ifc-to-frag
Convert IFC files to .frag format using a file-system server for streamlined processing and querying of BIM data in the Fragment MCP Server.
Instructions
Convert an IFC file to a .frag file. Needs file-system server
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| inputPath | Yes | Full path of the IFC file to convert | |
| outputPath | Yes | Full path where the output .frags file will be saved |
Implementation Reference
- main.ts:15-62 (registration)Registration of the 'convert-ifc-to-frag' MCP tool, including name, description, input schema, and handler function.server.tool( 'convert-ifc-to-frag', 'Convert an IFC file to a .frag file. Needs file-system server', { inputPath: z.string().describe('Full path of the IFC file to convert'), outputPath: z .string() .describe('Full path where the output .frags file will be saved'), }, async ({ inputPath, outputPath }) => { if (!fs.existsSync(inputPath)) { return { content: [ { type: 'text', text: 'IFC file not found. Please provide a valid .ifc file path.', }, ], } } if (fs.existsSync(outputPath)) { return { content: [ { type: 'text', text: 'Output .frag file already exists. Please call load-frag directly', }, ], } } const model = await convertIfcToFragment(inputPath, outputPath) return { content: [ { type: 'text', text: `Converted IFC file to .frag format. Output saved to ${outputPath}. Model contains ${ model.getItemsWithGeometry().length } items with geometry: ${JSON.stringify( fetchCategoriesWithGeometry(fragments) )}`, }, ], } } )
- main.ts:18-23 (schema)Zod input schema defining parameters for the tool: inputPath and outputPath.{ inputPath: z.string().describe('Full path of the IFC file to convert'), outputPath: z .string() .describe('Full path where the output .frags file will be saved'), },
- main.ts:24-61 (handler)The inline handler function for the tool, which checks file existence and delegates conversion to the helper function.async ({ inputPath, outputPath }) => { if (!fs.existsSync(inputPath)) { return { content: [ { type: 'text', text: 'IFC file not found. Please provide a valid .ifc file path.', }, ], } } if (fs.existsSync(outputPath)) { return { content: [ { type: 'text', text: 'Output .frag file already exists. Please call load-frag directly', }, ], } } const model = await convertIfcToFragment(inputPath, outputPath) return { content: [ { type: 'text', text: `Converted IFC file to .frag format. Output saved to ${outputPath}. Model contains ${ model.getItemsWithGeometry().length } items with geometry: ${JSON.stringify( fetchCategoriesWithGeometry(fragments) )}`, }, ], } }
- fragments.ts:5-22 (helper)Core helper function that performs the IFC to .frag conversion using @thatopen/fragments library.export const convertIfcToFragment = async ( inputPath: string, outputPath: string ) => { const ifcFile = await fs.promises.readFile(inputPath) const typedArray = new Uint8Array(ifcFile) const serializer = new FRAGS.IfcImporter() serializer.wasm = { path: '/', absolute: false, } const bytes = await serializer.process({ bytes: typedArray, raw: false }) const model = new FRAGS.SingleThreadedFragmentsModel('model', bytes) await fs.promises.writeFile(outputPath, bytes) return model }