Skip to main content
Glama

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
NameRequiredDescriptionDefault
filePathYesAbsolute path to the file
minSeverityNoMinimum severity to include: error, warning, info, hint. Default: warning
waitMsNoHow long to wait for diagnostics (ms). Default: 5000. Increase for large files.

Implementation Reference

  • 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));
        }
      }
    );
  • 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));
        }
      }
    );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/adainrivers/SvelteLS.MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server