Diagnose Print Issue
diagnose_print_issueDiagnose 3D print issues by symptom. Get ranked causes and fixes, with optional material-specific filtering.
Instructions
Diagnose a 3D printing problem by symptom. Returns possible causes ranked by probability, with specific fixes for each. Optionally filter by material type for material-specific troubleshooting.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symptom | Yes | The print issue symptom (e.g., "stringing", "warping", "layer_adhesion", "clogging", "elephant_foot") | |
| material | No | Material type for material-specific diagnosis (e.g., "PLA", "PETG") |
Implementation Reference
- src/tools/diagnose-print-issue.ts:9-79 (handler)Full handler function that registers the 'diagnose_print_issue' tool on the MCP server. Takes symptom (required) and material (optional) inputs, queries the database for troubleshooting entries, sorts them by material-specificity then probability, and returns formatted results or an error with available symptoms if none found.
export function registerDiagnosePrintIssue( server: McpServer, db: Database.Database, ): void { server.registerTool( 'diagnose_print_issue', { title: 'Diagnose Print Issue', description: 'Diagnose a 3D printing problem by symptom. Returns possible causes ranked by probability, with specific fixes for each. Optionally filter by material type for material-specific troubleshooting.', inputSchema: { symptom: z .string() .describe( 'The print issue symptom (e.g., "stringing", "warping", "layer_adhesion", "clogging", "elephant_foot")', ), material: z .string() .optional() .describe( 'Material type for material-specific diagnosis (e.g., "PLA", "PETG")', ), }, }, async ({ symptom, material }) => { const entries = getTroubleshooting(db, symptom.toLowerCase(), material); if (entries.length === 0) { const available = getAvailableSymptoms(db); return { isError: true, content: [ { type: 'text' as const, text: `No troubleshooting data found for symptom "${symptom}". Available symptoms: ${available.join(', ')}`, }, ], }; } // Sort: material-specific first, then by probability const probOrder: Record<string, number> = { high: 0, medium: 1, low: 2 }; const sorted = [...entries].sort((a, b) => { // Material-specific entries first when material is provided if (material) { const aSpecific = a.material_name ? 0 : 1; const bSpecific = b.material_name ? 0 : 1; if (aSpecific !== bSpecific) return aSpecific - bSpecific; } return (probOrder[a.probability] ?? 1) - (probOrder[b.probability] ?? 1); }); const header = material ? `# Diagnosing "${symptom}" (${material})` : `# Diagnosing "${symptom}"`; const lines = [header, '']; for (const entry of sorted) { const materialTag = entry.material_name ? ` [${entry.material_name}-specific]` : ''; lines.push(`## ${entry.cause}${materialTag}`); lines.push(`- Probability: ${entry.probability}`); lines.push(`- Fix: ${entry.fix}`); lines.push(''); } return { content: [{ type: 'text' as const, text: lines.join('\n') }] }; }, ); } - Input schema defined inline using Zod. 'symptom' is a required string describing the print issue, 'material' is an optional string for filtering by material type.
inputSchema: { symptom: z .string() .describe( 'The print issue symptom (e.g., "stringing", "warping", "layer_adhesion", "clogging", "elephant_foot")', ), material: z .string() .optional() .describe( 'Material type for material-specific diagnosis (e.g., "PLA", "PETG")', ), }, - src/server.ts:50-50 (registration)Registration of the tool's register function in the main server creation, passing the server instance and database connection.
registerDiagnosePrintIssue(server, db); - src/server.ts:17-17 (registration)Import of the registration function in the server module.
import { registerDiagnosePrintIssue } from './tools/diagnose-print-issue.js'; - src/data/db.ts:307-328 (helper)Database helper that queries the 'troubleshooting' table by symptom and optionally by material. Returns rows ordered by probability descending.
export function getTroubleshooting( db: Database.Database, symptom: string, material?: string, ): TroubleshootingRow[] { if (material) { return db .prepare( `SELECT * FROM troubleshooting WHERE symptom = ? AND (material_name = ? OR material_name IS NULL) ORDER BY probability DESC`, ) .all(symptom, material) as TroubleshootingRow[]; } return db .prepare( `SELECT * FROM troubleshooting WHERE symptom = ? ORDER BY probability DESC`, ) .all(symptom) as TroubleshootingRow[]; }