Skip to main content
Glama

Get Diagnostics

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));
        }
      }
    );
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It discloses that the tool may open the document to trigger computation, which is useful behavioral context. However, it omits details like whether this is a read-only operation, potential side effects of opening files, error handling, or response format, leaving gaps for a tool with no annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is two concise sentences with zero waste. The first sentence states the core purpose, and the second adds critical behavioral context. Every word earns its place, and it is front-loaded with essential information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is incomplete for a tool that performs file operations and returns diagnostics. It lacks details on output structure, error cases, or performance implications. However, it does cover the primary action and a key behavioral trait, making it minimally adequate but with clear gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all three parameters. The description adds no additional parameter semantics beyond what the schema provides, such as explaining the relationship between parameters or usage nuances. This meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Get compiler errors, warnings, and diagnostics') and resource ('for a file'), distinguishing it from siblings like get_completion or get_hover. It adds operational detail ('Opens the document to trigger computation if needed') that further clarifies its unique behavior.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage when diagnostics are needed for a file, but provides no explicit guidance on when to choose this tool over alternatives like get_code_actions or apply_code_action. It mentions opening the document if needed, which hints at a prerequisite, but lacks clear when-not-to-use or comparison statements.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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