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'], },

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