Skip to main content
Glama
lin037
by lin037

getDiagnosticsSummary

Generate a summary of project code quality by retrieving statistics on file counts, errors, and warnings using MCP Diagnostics for enhanced code analysis.

Instructions

获取诊断统计摘要,快速了解项目整体代码质量。返回文件总数、错误数量、警告数量的统计信息。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The primary handler function for the 'getDiagnosticsSummary' tool. It retrieves all diagnostics from the VSCodeDiagnosticsClient, iterates through them to count errors (severity 0) and warnings (severity 1), calculates the total file count, formats a summary object, and returns it as a JSON text content block.
    private async handleGetDiagnosticsSummary() { try { const diagnostics = await this.diagnosticsClient.getDiagnostics(); let errorCount = 0; let warningCount = 0; diagnostics.forEach((fileDiagnosticTuple) => { // fileDiagnosticTuple is a tuple [uri: any, diagnostics: Diagnostic[]] if (Array.isArray(fileDiagnosticTuple) && fileDiagnosticTuple.length === 2) { const diagnosticList = fileDiagnosticTuple[1]; if (Array.isArray(diagnosticList)) { diagnosticList.forEach((d) => { if (d && typeof d.severity === 'number') { // severity: 0=Error, 1=Warning in VS Code if (d.severity === 0) { errorCount++; } else if (d.severity === 1) { warningCount++; } } }); } } }); const summary = { fileCount: diagnostics.length, errorCount, warningCount, }; return { content: [ { type: 'text', text: JSON.stringify(summary, null, 2), }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `[handleGetDiagnosticsSummary] ${error instanceof Error ? error.message : String(error)}` ); } }
  • src/index.ts:86-93 (registration)
    Registers the 'getDiagnosticsSummary' tool in the ListToolsRequest handler, providing its name, description, and input schema (no parameters required).
    name: 'getDiagnosticsSummary', description: '获取诊断统计摘要,快速了解项目整体代码质量。返回文件总数、错误数量、警告数量的统计信息。', inputSchema: { type: 'object', properties: {}, additionalProperties: false, }, },
  • src/index.ts:114-116 (registration)
    Routes 'getDiagnosticsSummary' tool calls to the handleGetDiagnosticsSummary method in the CallToolRequest switch statement.
    case 'getDiagnosticsSummary': return await this.handleGetDiagnosticsSummary();
  • TypeScript interface defining the structure of the diagnostic summary returned by the tool (though the handler uses slightly different field names: fileCount, errorCount, warningCount).
    export interface DiagnosticSummary { totalFiles: number; errors: number; warnings: number; }
  • Supporting method in VSCodeDiagnosticsClient that fetches raw diagnostics data from the local VS Code extension server via HTTP, which is called by the main handler to obtain the data for summarization.
    async getDiagnostics(): Promise<FileDiagnostic[]> { try { // 使用 fetch API 请求本地服务器 const response = await fetch(this.diagnosticsUrl); // 检查响应是否成功 if (!response.ok) { // 如果HTTP状态码表示错误,则抛出错误 throw new Error(`HTTP error! status: ${response.status}`); } // 解析 JSON 数据 const data = await response.json(); return data as FileDiagnostic[]; } catch (error: any) { // 捕获并记录错误,例如服务器未运行或网络问题 // 捕获并记录错误,然后重新抛出一个更明确的错误 const errorMessage = `获取诊断失败: ${error.message}. 请确保配套的 "Diagnostics Server" VS Code 扩展已安装、已启用,并且 VS Code 正在运行中。`; console.error(errorMessage); throw new Error(errorMessage); } }

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/lin037/mcp-diagnostics-trae'

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