Skip to main content
Glama
lin037

MCP Diagnostics

by lin037

getDiagnostics

Retrieve diagnostic information (errors, warnings, hints) from all workspace files to enable intelligent code analysis and suggestions.

Instructions

获取当前工作区所有文件的诊断信息(错误/警告/提示)。返回完整的诊断列表,包含所有文件的详细错误信息。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Handler function for the 'getDiagnostics' tool. Fetches all diagnostics from VSCodeDiagnosticsClient and returns formatted JSON response.
    private async handleGetDiagnostics() {
      try {
        const diagnostics = await this.diagnosticsClient.getDiagnostics();
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(diagnostics, null, 2),
            },
          ],
        };
      } catch (error) {
        throw new McpError(
          ErrorCode.InternalError,
          `[handleGetDiagnostics] ${error instanceof Error ? error.message : String(error)}`
        );
      }
    }
  • Core helper method in VSCodeDiagnosticsClient that performs HTTP fetch to retrieve all diagnostics from the local VS Code extension server.
    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);
      }
    }
  • src/index.ts:46-54 (registration)
    Tool registration in the ListTools response, defining name, description, and input schema for 'getDiagnostics'.
    {
      name: 'getDiagnostics',
      description: '获取当前工作区所有文件的诊断信息(错误/警告/提示)。返回完整的诊断列表,包含所有文件的详细错误信息。',
      inputSchema: {
        type: 'object',
        properties: {},
        additionalProperties: false,
      },
    },
  • Input schema for the 'getDiagnostics' tool (no parameters required).
    inputSchema: {
      type: 'object',
      properties: {},
      additionalProperties: false,
    },
  • Dispatch handler in CallToolRequestSchema switch statement routing to the specific getDiagnostics handler.
    case 'getDiagnostics':
      return await this.handleGetDiagnostics();

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