Skip to main content
Glama
lin037

MCP Diagnostics

by lin037

getDiagnosticsForPath

Retrieve diagnostic information for a specific file path, supporting flexible path formats including relative paths and filenames to identify code issues.

Instructions

🌟 推荐工具:根据文件路径获取诊断信息,支持灵活的路径匹配。可以使用相对路径、文件名等多种格式,比 getDiagnosticsForFile 更易用。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYes文件路径,支持多种格式: - 相对路径:src/index.ts - 文件名:index.ts - 带目录的文件名:test/TestJava.java 示例:要查看 index.ts 文件的问题,使用 "src/index.ts" 或 "index.ts"

Implementation Reference

  • Core handler implementing the getDiagnosticsForPath tool logic: fetches all diagnostics and applies flexible path matching (exact, suffix, filename, contains) to filter relevant file diagnostics.
    async getDiagnosticsForPath(filePath: string): Promise<FileDiagnostic[]> {
      const allDiagnostics = await this.getDiagnostics();
      
      // 标准化输入路径,统一使用正斜杠进行逻辑处理
      const normalizedPath = filePath.replace(/\\/g, '/').toLowerCase();
      
      // 多种匹配策略
      const matchedFiles = allDiagnostics.filter(d => {
        const uri = d.uri.toLowerCase();
        const cleanUri = uri.replace(/^file:\/\/\//, '').replace(/^file:\/\//, '').replace(/\\/g, '/');
        
        // 1. 精确匹配 (处理转换后的路径)
        if (cleanUri === normalizedPath) {
          return true;
        }
        
        // 2. 路径结尾匹配
        if (cleanUri.endsWith('/' + normalizedPath) || cleanUri.endsWith(normalizedPath)) {
          return true;
        }
        
        // 3. 文件名匹配
        const fileName = normalizedPath.split('/').pop() || normalizedPath;
        if (uri.endsWith('/' + fileName)) {
          return true;
        }
        
        // 4. 包含路径匹配
        if (cleanUri.includes(normalizedPath)) {
          return true;
        }
        
        return false;
      });
      
      console.error(`路径匹配结果: 输入=${filePath}, 找到=${matchedFiles.length}个匹配`);
      
      return matchedFiles;
    }
  • MCP server handler for getDiagnosticsForPath tool: validates input, delegates to VSCodeDiagnosticsClient, handles empty results and errors, formats response as MCP content.
    private async handleGetDiagnosticsForPath(args: { filePath: string }) {
      if (!args || !args.filePath) {
        throw new McpError(ErrorCode.InvalidParams, '缺少必需参数: filePath');
      }
      try {
        const diagnostics = await this.diagnosticsClient.getDiagnosticsForPath(args.filePath);
        if (!diagnostics || diagnostics.length === 0) {
          return {
            content: [
              {
                type: 'text',
                text: '未找到匹配该路径的文件。',
              },
            ],
          };
        }
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(diagnostics, null, 2),
            },
          ],
        };
      } catch (error) {
        throw new McpError(
          ErrorCode.InternalError,
          `[handleGetDiagnosticsForPath] ${error instanceof Error ? error.message : String(error)}`
        );
      }
  • src/index.ts:70-84 (registration)
    Registers the getDiagnosticsForPath tool in the MCP listTools response, providing name, description, and input schema.
    {
      name: 'getDiagnosticsForPath',
      description: '🌟 推荐工具:根据文件路径获取诊断信息,支持灵活的路径匹配。可以使用相对路径、文件名等多种格式,比 getDiagnosticsForFile 更易用。',
      inputSchema: {
        type: 'object',
        properties: {
          filePath: {
            type: 'string',
            description: '文件路径,支持多种格式:\n- 相对路径:src/index.ts\n- 文件名:index.ts\n- 带目录的文件名:test/TestJava.java\n示例:要查看 index.ts 文件的问题,使用 "src/index.ts" 或 "index.ts"',
          },
        },
        required: ['filePath'],
        additionalProperties: false,
      },
    },
  • Defines the input schema for the getDiagnosticsForPath tool, specifying the required 'filePath' string parameter.
    inputSchema: {
      type: 'object',
      properties: {
        filePath: {
          type: 'string',
          description: '文件路径,支持多种格式:\n- 相对路径:src/index.ts\n- 文件名:index.ts\n- 带目录的文件名:test/TestJava.java\n示例:要查看 index.ts 文件的问题,使用 "src/index.ts" 或 "index.ts"',
        },
      },
      required: ['filePath'],
      additionalProperties: false,
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It discloses that the tool supports flexible path matching (relative paths, filenames) and is easier to use than getDiagnosticsForFile, which adds some behavioral context. However, it doesn't cover other important aspects like what diagnostic information is returned, error handling, performance implications, or authentication needs. The description adds value but leaves significant gaps in behavioral disclosure.

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

Conciseness4/5

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

The description is concise with two sentences that efficiently convey key information: the tool's purpose and its flexibility compared to a sibling tool. It's front-loaded with the main function. However, the use of an emoji (🌟) and promotional language ('推荐工具' - recommended tool) adds minor fluff that doesn't earn its place in a tool definition.

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 the tool has 1 parameter with full schema coverage, no annotations, and no output schema, the description is moderately complete. It covers the purpose and some usage context but lacks details on what diagnostic information is returned (since no output schema exists), error cases, or deeper behavioral traits. For a tool that presumably returns diagnostic data, more context on the output would be helpful to compensate for the missing output schema.

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 schema description coverage is 100%, with the parameter 'filePath' fully documented in the input schema (including examples and supported formats). The description adds minimal value beyond the schema by mentioning '支持灵活的路径匹配' (supports flexible path matching) and '可以使用相对路径、文件名等多种格式' (can use relative paths, filenames, and other formats), but this largely repeats what's in the schema. Baseline 3 is appropriate as the schema does the heavy lifting.

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 tool's purpose: '根据文件路径获取诊断信息' (get diagnostic information based on file path). It specifies the resource (diagnostic information) and the mechanism (file path). However, it doesn't explicitly differentiate from sibling tools like getDiagnosticsForFile beyond saying it's '更易用' (easier to use), which is somewhat vague rather than specific functional differentiation.

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 provides some usage context by mentioning support for flexible path matching (relative paths, filenames) and comparing it to getDiagnosticsForFile as 'easier to use.' However, it doesn't explicitly state when to use this tool versus alternatives like getDiagnostics or getDiagnosticsSummary, nor does it provide clear exclusions or prerequisites. The guidance is implied rather than explicit.

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

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