Skip to main content
Glama

get_diagnostics

Retrieve detailed diagnostic information for a document, including error and warning analysis, by providing the language identifier, file path, content, and project root for accurate code assessment.

Instructions

Get diagnostic information for a document

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYesThe current content of the file
filePathYesAbsolute or relative path to the source file
languageIdYesThe language identifier (e.g., "typescript", "javascript")
projectRootYesImportant: Root directory of the project for resolving imports and node_modules where the tsconfig.json or jsconfig.json is located

Implementation Reference

  • The handler function for the 'get_diagnostics' tool. It initializes an LSP server for the given language, constructs a TextDocumentItem from the provided file path and content, sets up a listener for diagnostics notifications, opens the document to trigger diagnostics, and resolves with the diagnostics or a timeout message.
    private async handleGetDiagnostics(args: any): Promise<any> {
      const { languageId, filePath, content, projectRoot } = args;
      console.log(`[handleGetDiagnostics] Processing request for ${languageId}`);
      
      const server = await this.getOrCreateServer(languageId, projectRoot);
      const actualRoot = server.workspaceRoot;
    
      const absolutePath = isAbsolute(filePath) ? filePath : join(actualRoot, filePath);
      const uri = `file://${absolutePath}`;
    
      // Ensure directory exists
      const fileDir = dirname(absolutePath);
      if (!existsSync(fileDir)) {
        mkdirSync(fileDir, { recursive: true });
      }
    
      const textDocument: TextDocumentItem = {
        uri,
        languageId,
        version: 1,
        text: content,
      };
    
      console.log(`[handleGetDiagnostics] Setting up diagnostics listener for ${uri}`);
      return new Promise((resolve) => {
        const listeners = this.diagnosticsListeners.get(uri) || [];
        const listener = (params: PublishDiagnosticsParams) => {
          console.log(`[handleGetDiagnostics] Received diagnostics for ${uri}:`, params);
          resolve({
            content: [
              {
                type: 'text',
                text: JSON.stringify(params.diagnostics, null, 2),
              },
            ],
          });
    
          // Remove listener after receiving diagnostics
          const index = listeners.indexOf(listener);
          if (index !== -1) {
            listeners.splice(index, 1);
          }
        };
        listeners.push(listener);
        this.diagnosticsListeners.set(uri, listeners);
    
        // Send document to trigger diagnostics
        console.log(`[handleGetDiagnostics] Sending document to server:`, textDocument);
        server.connection.sendNotification('textDocument/didOpen', {
          textDocument,
        } as DidOpenTextDocumentParams);
    
        // Set timeout
        setTimeout(() => {
          console.log(`[handleGetDiagnostics] Timeout reached for ${uri}`);
          const index = listeners.indexOf(listener);
          if (index !== -1) {
            listeners.splice(index, 1);
            resolve({
              content: [
                {
                  type: 'text',
                  text: 'No diagnostics received within timeout',
                },
              ],
            });
          }
        }, 2000);
      });
    }
  • src/index.ts:360-384 (registration)
    Registers the 'get_diagnostics' tool in the MCP server tools list, including its name, description, and input schema.
      name: 'get_diagnostics',
      description: 'Get diagnostic information for a document',
      inputSchema: {
        type: 'object',
        properties: {
          languageId: { 
            type: 'string',
            description: 'The language identifier (e.g., "typescript", "javascript")'
          },
          filePath: { 
            type: 'string',
            description: 'Absolute or relative path to the source file'
          },
          content: { 
            type: 'string',
            description: 'The current content of the file'
          },
          projectRoot: { 
            type: 'string',
            description: 'Important: Root directory of the project for resolving imports and node_modules where the tsconfig.json or jsconfig.json is located'
          },
        },
        required: ['languageId', 'filePath', 'content', 'projectRoot'],
      },
    },
  • Defines the input schema for the 'get_diagnostics' tool, specifying required parameters: languageId, filePath, content, projectRoot.
    inputSchema: {
      type: 'object',
      properties: {
        languageId: { 
          type: 'string',
          description: 'The language identifier (e.g., "typescript", "javascript")'
        },
        filePath: { 
          type: 'string',
          description: 'Absolute or relative path to the source file'
        },
        content: { 
          type: 'string',
          description: 'The current content of the file'
        },
        projectRoot: { 
          type: 'string',
          description: 'Important: Root directory of the project for resolving imports and node_modules where the tsconfig.json or jsconfig.json is located'
        },
      },
      required: ['languageId', 'filePath', 'content', 'projectRoot'],
    },
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure but only states the basic action. It doesn't reveal whether this is a read-only operation, if it has side effects, performance characteristics, or what the output looks like (e.g., error messages, warnings). This leaves significant gaps for a tool with four required parameters.

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 a single, direct sentence with no wasted words, making it highly concise and front-loaded. It efficiently communicates the core purpose without unnecessary elaboration.

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

Completeness2/5

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

Given the complexity of four required parameters and no annotations or output schema, the description is incomplete. It doesn't explain what 'diagnostic information' includes (e.g., errors, linting results) or provide context for parameter usage, leaving the agent with insufficient information to use the tool effectively beyond basic invocation.

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?

The input schema has 100% description coverage, clearly documenting all four parameters (content, filePath, languageId, projectRoot). The description adds no additional semantic context beyond the schema, such as how parameters interact or examples of valid values, so it 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.

Purpose4/5

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

The description clearly states the action ('Get') and resource ('diagnostic information for a document'), making the purpose understandable. However, it doesn't differentiate from sibling tools like 'get_completions' or 'get_hover', which likely also operate on documents but provide different types of information.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives like 'get_completions' or 'get_hover'. It lacks context about what 'diagnostic information' entails or scenarios where it's appropriate, offering no explicit or implied usage instructions.

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

Related 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/alexwohletz/language-server-mcp'

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