Compare Materials
compare_materialsCompare 2-3 3D printing materials across strength, flexibility, heat resistance, and other properties to choose the right filament for your project.
Instructions
Compare 2-3 material types side by side across all properties: strength, flexibility, heat resistance, food safety, print difficulty, and more. Useful for deciding which material to use for a project.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| materials | Yes | Array of 2-3 material type names to compare (e.g., ["PLA", "PETG", "ABS"]) |
Implementation Reference
- src/tools/compare-materials.ts:10-105 (handler)Registers and implements the compare_materials tool handler. Fetches 2-3 material profiles from DB and builds a comparison table with properties like print temp, strength, flexibility, UV resistance, food safety, etc., plus a 'When to use each' summary.
export function registerCompareMaterials( server: McpServer, db: Database.Database, ): void { server.registerTool( 'compare_materials', { title: 'Compare Materials', description: 'Compare 2-3 material types side by side across all properties: strength, flexibility, heat resistance, food safety, print difficulty, and more. Useful for deciding which material to use for a project.', inputSchema: { materials: z .array(z.string()) .min(2) .max(3) .describe( 'Array of 2-3 material type names to compare (e.g., ["PLA", "PETG", "ABS"])', ), }, }, async ({ materials }) => { const profiles: MaterialProfileRow[] = []; for (const name of materials) { let profile = getMaterialProfile(db, name); if (!profile) { profile = getMaterialProfile(db, name.toUpperCase()); } if (!profile) { return { isError: true, content: [ { type: 'text' as const, text: `Material "${name}" not found. Cannot compare. Available materials: ${getAvailableMaterialNames(db).join(', ')}`, }, ], }; } profiles.push(profile); } const names = profiles.map((p) => p.material_name); const header = `# Material Comparison: ${names.join(' vs ')}\n`; const properties: { label: string; getter: (p: MaterialProfileRow) => string }[] = [ { label: 'Print Temp', getter: (p) => `${p.print_temp_min}-${p.print_temp_max}°C` }, { label: 'Bed Temp', getter: (p) => `${p.bed_temp_min}-${p.bed_temp_max}°C` }, { label: 'Strength', getter: (p) => p.strength }, { label: 'Flexibility', getter: (p) => p.flexibility }, { label: 'UV Resistance', getter: (p) => p.uv_resistance }, { label: 'Food Safe', getter: (p) => p.food_safe }, { label: 'Moisture Sensitivity', getter: (p) => p.moisture_sensitivity }, { label: 'Difficulty', getter: (p) => p.difficulty }, { label: 'Enclosure Needed', getter: (p) => p.enclosure_needed ? 'Yes' : 'No' }, { label: 'Nozzle', getter: (p) => p.nozzle_notes ?? 'Standard' }, ]; // Build table const colWidth = 25; const labelWidth = 22; const separator = '-'.repeat(labelWidth + colWidth * names.length + names.length + 1); let table = `| ${'Property'.padEnd(labelWidth)}|`; for (const name of names) { table += ` ${name.padEnd(colWidth - 1)}|`; } table += '\n' + separator + '\n'; for (const prop of properties) { let row = `| ${prop.label.padEnd(labelWidth)}|`; for (const profile of profiles) { const val = prop.getter(profile); row += ` ${val.substring(0, colWidth - 2).padEnd(colWidth - 1)}|`; } table += row + '\n'; } // When to use summary const whenToUse = profiles .map( (p) => `- **${p.material_name}**: ${p.typical_uses} (${p.pros})`, ) .join('\n'); const text = [ header, table, '', '## When to use each', whenToUse, ].join('\n'); return { content: [{ type: 'text' as const, text }] }; }, ); } - src/tools/compare-materials.ts:20-28 (schema)Input schema defining the 'materials' parameter: an array of 2-3 strings representing material names to compare.
inputSchema: { materials: z .array(z.string()) .min(2) .max(3) .describe( 'Array of 2-3 material type names to compare (e.g., ["PLA", "PETG", "ABS"])', ), }, - src/server.ts:48-48 (registration)Registration call in the main server setup, passing the server instance and database to register the compare_materials tool.
registerCompareMaterials(server, db); - src/data/db.ts:280-288 (helper)Helper function that queries the database for a material profile by name. Used by the compare_materials handler to fetch each material's data.
export function getMaterialProfile( db: Database.Database, name: string, ): MaterialProfileRow | null { const row = db .prepare('SELECT * FROM material_profiles WHERE material_name = ?') .get(name) as MaterialProfileRow | undefined; return row ?? null; } - src/data/db.ts:337-344 (helper)Helper function that returns all available material names from the database. Used by compare_materials to list valid options when a material is not found.
export function getAvailableMaterialNames(db: Database.Database): string[] { const rows = db .prepare( 'SELECT DISTINCT material_name FROM material_profiles ORDER BY material_name', ) .all() as { material_name: string }[]; return rows.map((r) => r.material_name); }