Skip to main content
Glama

run_static_analysis

Analyze code for unused variables, dead code, type errors, and syntax issues using native linters and compilers instead of LLM guessing. Supports TypeScript, Python, Rust, and Go.

Instructions

Run the project's native linter/compiler to find unused variables, dead code, type errors, and syntax issues. Delegates detection to deterministic tools instead of LLM guessing. Supports TypeScript, Python, Rust, Go.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
target_pathNoSpecific file or folder to lint (relative to root). Omit for full project.

Implementation Reference

  • The handler function `runStaticAnalysis` executes the logic for running linters or compilers based on file extension or project type.
    export async function runStaticAnalysis(options: StaticAnalysisOptions): Promise<string> {
      const targetPath = options.targetPath ? resolve(options.rootDir, options.targetPath) : options.rootDir;
      const ext = extname(targetPath);
    
      if (ext) {
        const linter = await detectAvailableLinter(options.rootDir, ext);
        if (!linter) return `No linter configured for ${ext} files.`;
    
        const args = [...linter.args];
        if ([".js", ".ts", ".tsx"].includes(ext)) args.push(targetPath);
        else if (ext === ".py") args.push(targetPath);
    
        const result = await runCommand(linter.cmd, args, options.rootDir);
    
        if (result.exitCode === 0 && !result.output) return "No issues found. Code is clean.";
        return `Static analysis (${result.tool}):\n\n${result.output.substring(0, 5000)}`;
      }
    
      const results: string[] = [];
      for (const [fileExt] of Object.entries(LINTER_MAP)) {
        const linter = await detectAvailableLinter(options.rootDir, fileExt);
        if (!linter) continue;
    
        const result = await runCommand(linter.cmd, linter.args, options.rootDir);
        if (result.output) {
          results.push(`[${result.tool}] ${fileExt} files:\n${result.output.substring(0, 2000)}`);
        }
      }
    
      return results.length > 0 ? results.join("\n\n") : "No linters available or no issues found.";
    }
  • src/index.ts:296-309 (registration)
    Registration of the `run_static_analysis` tool in the MCP server instance, mapping the tool name to the `runStaticAnalysis` handler.
    server.tool(
      "run_static_analysis",
      "Run the project's native linter/compiler to find unused variables, dead code, type errors, and syntax issues. " +
      "Delegates detection to deterministic tools instead of LLM guessing. Supports TypeScript, Python, Rust, Go.",
      {
        target_path: z.string().optional().describe("Specific file or folder to lint (relative to root). Omit for full project."),
      },
      withRequestActivity(async ({ target_path }) => ({
        content: [{
          type: "text" as const,
          text: await runStaticAnalysis({ rootDir: ROOT_DIR, targetPath: target_path }),
        }],
      })),
    );

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/ForLoopCodes/contextplus'

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