Skip to main content
Glama

Analyze Error

analyze_error

Analyze error output to generate a deterministic fix brief using project context and relevant files.

Instructions

Analyze provided error output and return a deterministic project-local fix brief.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
error_outputYes
commandNo
cwdNo
package_contextNo
relevant_filesNo
environmentNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
analysis_idYes
fingerprintYes
stackYes
likely_causeYes
best_first_fixYes
verificationYes
prior_project_fixesYes
avoidYes
confidenceYes

Implementation Reference

  • Main handler for the analyze_error tool. Parses input, normalizes error, detects stack, generates fingerprint, matches against memory, builds a fix brief, and returns a structured FixBrief with confidence score.
    export async function analyzeError(input: AnalyzeErrorInput): Promise<FixBrief> {
      const parsed = analyzeErrorInputSchema.parse(input);
      const redactedInput = redactUnknown(parsed);
      const normalized = normalizeError(redactedInput.error_output);
      const stack = detectStack({ input: redactedInput, normalized });
      const fingerprint = generateFingerprint(normalized, stack);
      const projectCwd = resolveProjectCwd(redactedInput.cwd);
      const analysisId = generateAnalysisId(fingerprint, projectCwd);
    
      rememberAnalysisProjectPath(analysisId, projectCwd);
      await writeAnalysisRegistry({
        analysis_id: analysisId,
        fingerprint,
        project_path: projectCwd
      });
    
      const memory = await readMemory(projectCwd);
      const memoryMatches = matchMemory({
        records: memory,
        fingerprint,
        stack,
        keywords: normalized.keywords
      });
    
      const priorProjectFixes = memoryMatches.successes.map(toPriorProjectFix);
      const avoid = memoryMatches.failures.map(toAvoidFix);
      const brief = buildBrief({
        input: redactedInput,
        normalized,
        stack,
        priorProjectFixes,
        avoid
      });
    
      const output = fixBriefSchema.parse({
        analysis_id: analysisId,
        fingerprint,
        stack,
        ...brief,
        prior_project_fixes: priorProjectFixes,
        avoid,
        confidence: confidenceFor({
          stack,
          input: redactedInput,
          hasExactMemoryMatch: [...memoryMatches.successes, ...memoryMatches.failures].some((match) =>
            match.matchedBy.includes("fingerprint")
          )
        })
      });
    
      return fixBriefSchema.parse(redactUnknown(output));
    }
  • confidenceFor: Computes a confidence score (0.35-0.9) based on stack detection, presence of package_context, relevant_files, command, and exact memory fingerprint match.
    function confidenceFor({
      stack,
      input,
      hasExactMemoryMatch
    }: {
      stack: string;
      input: AnalyzeErrorInput;
      hasExactMemoryMatch: boolean;
    }): number {
      let confidence = 0.35;
    
      if (stack !== "unknown") {
        confidence += 0.2;
      }
      if (input.package_context) {
        confidence += 0.1;
      }
      if (input.relevant_files && input.relevant_files.length > 0) {
        confidence += 0.1;
      }
      if (input.command) {
        confidence += 0.05;
      }
      if (hasExactMemoryMatch) {
        confidence += 0.15;
      }
    
      return Math.min(0.9, Number(confidence.toFixed(2)));
    }
  • writeAnalysisRegistry: Persists analysis metadata (analysis_id, fingerprint, project_path) to a registry file for restart recovery.
    async function writeAnalysisRegistry({
      analysis_id,
      fingerprint,
      project_path
    }: {
      analysis_id: string;
      fingerprint: string;
      project_path: string;
    }): Promise<void> {
      try {
        await appendAnalysisRegistryRecord({
          timestamp: new Date().toISOString(),
          analysis_id,
          fingerprint,
          project_path
        });
      } catch {
        // The registry is a convenience for restart recovery; analysis should still work without it.
      }
    }
  • Input schema (analyzeErrorInputSchema) using Zod defining the required error_output and optional command, cwd, package_context, relevant_files, environment fields. Also exports the AnalyzeErrorInput TypeScript type.
    import { z } from "zod";
    
    export const relevantFileSchema = z.object({
      path: z.string().optional(),
      language: z.string().optional(),
      excerpt: z.string().optional(),
      content: z.string().optional(),
      metadata: z.record(z.unknown()).optional()
    });
    
    export const analyzeErrorInputSchema = z.object({
      error_output: z.string().min(1, "error_output is required"),
      command: z.string().optional(),
      cwd: z.string().optional(),
      package_context: z.record(z.unknown()).optional(),
      relevant_files: z.array(relevantFileSchema).optional(),
      environment: z.record(z.unknown()).optional()
    });
    
    export type AnalyzeErrorInput = z.infer<typeof analyzeErrorInputSchema>;
  • src/server.ts:21-36 (registration)
    Registration of the 'analyze_error' tool in the MCP server via server.registerTool with title, description, input/output schemas, and the async handler that calls analyzeError and returns text content.
    server.registerTool(
      "analyze_error",
      {
        title: "Analyze Error",
        description: "Analyze provided error output and return a deterministic project-local fix brief.",
        inputSchema: analyzeErrorInputSchema.shape,
        outputSchema: fixBriefSchema.shape
      },
      async (args) => {
        const output = await analyzeError(args);
        return {
          content: [{ type: "text", text: JSON.stringify(output, null, 2) }],
          structuredContent: output
        };
      }
    );
Behavior2/5

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

With no annotations provided, the description carries full burden but only states the output is 'deterministic' and 'project-local'. It does not disclose if the tool modifies state (e.g., reads files, changes anything), required permissions, or potential side effects, leaving agents to infer behaviors.

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 a single concise sentence that front-loads the core purpose. However, it sacrifices critical parameter and usage details, which is a minor structural flaw given the tool's complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Despite having a rich input schema and output schema, the description omits explanation of parameter roles, return format, and usage context. For a complex analysis tool, this is incomplete, though the output schema may partially mitigate return value clarity.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 6 parameters with 0% description coverage, yet the description adds no parameter information beyond mentioning 'error output' in the purpose. The other parameters (command, cwd, relevant_files, etc.) remain unexplained, forcing agents to guess their semantics.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool analyzes error output and returns a deterministic project-local fix brief. It uses a specific verb ('analyze') and resource ('error output'), and the mention of 'fix brief' distinguishes it from the sibling tool 'remember_fix_result' which likely stores results.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus the sibling 'remember_fix_result' or other alternatives. The description implicitly suggests using it when an error occurs, but does not specify prerequisites or exclude scenarios.

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/stfade/moth'

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