get_diagnostics
Retrieve compiler errors, warnings, and diagnostic information for Svelte files to identify and resolve code issues during development.
Instructions
Get compiler errors, warnings, and diagnostics for a file. Opens the document to trigger computation if needed.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | Absolute path to the file | |
| minSeverity | No | Minimum severity to include: error, warning, info, hint. Default: warning | |
| waitMs | No | How long to wait for diagnostics (ms). Default: 5000. Increase for large files. |
Implementation Reference
- src/tools/diagnostics.ts:38-91 (handler)The async handler function that implements the logic for 'get_diagnostics' tool.
async ({ filePath, minSeverity, waitMs }): Promise<ToolResult> => { try { const prep = await prepareDocumentRequest(lsp, filePath); if ("error" in prep) return textResult(prep.error); const diagnostics = await lsp.waitForDiagnostics( prep.uri, waitMs ?? 5000 ); if (!diagnostics || diagnostics.length === 0) { return textResult( `No diagnostics found in ${basename(filePath)}.` ); } const minSev = parseSeverity(minSeverity); const lines: string[] = []; let count = 0; for (const diag of diagnostics) { const severity = diag.severity ?? 4; if (severity > minSev) continue; const sevLabel = severityLabel(severity); const line = (diag.range?.start?.line ?? 0) + 1; const code = typeof diag.code === "object" ? (diag.code as any)?.value?.toString() ?? "" : diag.code?.toString() ?? ""; const message = diag.message ?? ""; let entry = ` [${sevLabel}] ${basename(filePath)}:${line}`; if (code) entry += ` ${code}`; entry += `: ${message}`; lines.push(entry); count++; } if (count === 0) { return textResult( `No diagnostics at severity '${minSeverity ?? "warning"}' or above in ${basename(filePath)}.` ); } return textResult( `Found ${count} diagnostic(s) in ${basename(filePath)}:\n\n` + lines.join("\n") ); } catch (ex) { return textResult(formatError(ex)); } } ); - src/tools/diagnostics.ts:16-91 (registration)Registration of the 'get_diagnostics' tool in the MCP server.
server.registerTool( "get_diagnostics", { title: "Get Diagnostics", description: "Get compiler errors, warnings, and diagnostics for a file. Opens the document to trigger computation if needed.", inputSchema: z.object({ filePath: z.string().describe("Absolute path to the file"), minSeverity: z .string() .optional() .describe( "Minimum severity to include: error, warning, info, hint. Default: warning" ), waitMs: z .number() .optional() .describe( "How long to wait for diagnostics (ms). Default: 5000. Increase for large files." ), }), }, async ({ filePath, minSeverity, waitMs }): Promise<ToolResult> => { try { const prep = await prepareDocumentRequest(lsp, filePath); if ("error" in prep) return textResult(prep.error); const diagnostics = await lsp.waitForDiagnostics( prep.uri, waitMs ?? 5000 ); if (!diagnostics || diagnostics.length === 0) { return textResult( `No diagnostics found in ${basename(filePath)}.` ); } const minSev = parseSeverity(minSeverity); const lines: string[] = []; let count = 0; for (const diag of diagnostics) { const severity = diag.severity ?? 4; if (severity > minSev) continue; const sevLabel = severityLabel(severity); const line = (diag.range?.start?.line ?? 0) + 1; const code = typeof diag.code === "object" ? (diag.code as any)?.value?.toString() ?? "" : diag.code?.toString() ?? ""; const message = diag.message ?? ""; let entry = ` [${sevLabel}] ${basename(filePath)}:${line}`; if (code) entry += ` ${code}`; entry += `: ${message}`; lines.push(entry); count++; } if (count === 0) { return textResult( `No diagnostics at severity '${minSeverity ?? "warning"}' or above in ${basename(filePath)}.` ); } return textResult( `Found ${count} diagnostic(s) in ${basename(filePath)}:\n\n` + lines.join("\n") ); } catch (ex) { return textResult(formatError(ex)); } } );