Skip to main content
Glama

Tracer

tracer

Trace execution flow and debug complex issues by analyzing method calls, dependencies, and structural relationships in code.

Instructions

Trace execution flow and debug complex issues

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
taskYesWhat to trace and WHY you need this analysis (e.g., 'trace User.login() execution flow', 'map UserService dependencies', 'understand payment processing call chain')
traceModeNoType of tracing: 'ask' (prompts user to choose), 'precision' (execution flow), 'dependencies' (structural relationships)ask
targetDescriptionNoDetailed description of what to trace - method, function, class, or module name and context
filesNoRelevant files to focus tracing on (optional)
providerNoAI provider to usegemini

Implementation Reference

  • src/server.ts:384-392 (registration)
    Registers the 'tracer' tool with MCP server, specifying title, description, input schema, and delegates execution to aiHandlers.handleTracer
    // Register tracer tool
    server.registerTool("tracer", {
      title: "Tracer",
      description: "Trace execution flow and debug complex issues",
      inputSchema: TracerSchema.shape,
    }, async (args) => {
      const aiHandlers = await getHandlers();
      return await aiHandlers.handleTracer(args);
    });
  • Zod schema defining input parameters for the tracer tool: task, traceMode, targetDescription, files, provider.
    const TracerSchema = z.object({
      task: z.string().describe("What to trace and WHY you need this analysis (e.g., 'trace User.login() execution flow', 'map UserService dependencies', 'understand payment processing call chain')"),
      traceMode: z.enum(["precision", "dependencies", "ask"]).default("ask").describe("Type of tracing: 'ask' (prompts user to choose), 'precision' (execution flow), 'dependencies' (structural relationships)"),
      targetDescription: z.string().optional().describe("Detailed description of what to trace - method, function, class, or module name and context"),
      files: z.array(z.string()).optional().describe("Relevant files to focus tracing on (optional)"),
      provider: z.enum(["openai", "gemini", "azure", "grok"]).optional().default("gemini").describe("AI provider to use"),
    });
  • Core handler implementation for 'tracer' tool. Generates specialized AI prompts for code tracing in 'precision' (execution flow) or 'dependencies' (structural mapping) modes, analyzes codebase, and returns structured tracing results with status and code references.
      async handleTracer(params: z.infer<typeof TracerSchema>) {
        const providerName = params.provider || (await this.providerManager.getPreferredProvider(['openai', 'gemini', 'azure', 'grok']));
        const provider = await this.providerManager.getProvider(providerName);
        
        // Build trace mode specific system prompt
        const traceModePrompts = {
          ask: "STEP 1: Ask the user to choose between 'precision' or 'dependencies' tracing mode. Explain: PRECISION MODE traces execution flow, call chains, and usage patterns (best for methods/functions). DEPENDENCIES MODE maps structural relationships and bidirectional dependencies (best for classes/modules). Wait for user selection before proceeding.",
          precision: "Focus on execution flow analysis: trace method calls, function invocations, call chains, usage patterns, execution paths, conditional branches, and data flow through the system. Best for understanding how specific methods or functions work.",
          dependencies: "Focus on structural relationship analysis: map class dependencies, module relationships, inheritance hierarchies, interface implementations, import/export chains, and bidirectional dependencies. Best for understanding how components relate to each other.",
        };
    
        const systemPrompt = `You are an expert code tracer specializing in systematic code analysis and relationship mapping. Your role is to conduct thorough code tracing using structured investigation workflows.
    
    TRACING MODE: ${traceModePrompts[params.traceMode]}
    
    TRACE ANALYSIS METHODOLOGY:
    1. **Target Identification**: Locate and understand the target method/function/class/module
    2. **Context Analysis**: Understand the purpose, signature, and implementation details
    3. **Relationship Mapping**: ${params.traceMode === 'precision' ? 'Trace execution flow and call chains' : 'Map structural dependencies and relationships'}
    4. **Pattern Recognition**: Identify architectural patterns and design decisions
    5. **Comprehensive Documentation**: Document findings with precise file references and line numbers
    
    ${params.traceMode === 'precision' ? `
    PRECISION TRACING FOCUS:
    - Execution flow and call sequence
    - Method invocation patterns
    - Conditional execution paths
    - Data flow and transformations
    - Side effects and state changes
    - Entry points and usage scenarios
    ` : params.traceMode === 'dependencies' ? `
    DEPENDENCIES TRACING FOCUS:
    - Incoming dependencies (what depends on this)
    - Outgoing dependencies (what this depends on)
    - Type relationships (inheritance, implementation)
    - Structural patterns and architecture
    - Bidirectional relationship mapping
    - Module and package relationships
    ` : ''}
    
    INVESTIGATION WORKFLOW:
    This is a step-by-step analysis tool. You will:
    1. Start with systematic code investigation
    2. Gather evidence from actual code examination
    3. Build comprehensive understanding through multiple investigation steps
    4. Present findings in structured format with precise code references
    
    RESPONSE FORMAT:
    Provide detailed tracing analysis including:
    - **Target Analysis**: Complete understanding of what is being traced
    - **${params.traceMode === 'precision' ? 'Execution Flow' : 'Dependency Map'}**: ${params.traceMode === 'precision' ? 'Call chains and execution paths' : 'Structural relationships and dependencies'}
    - **Code References**: Specific file paths and line numbers
    - **Patterns and Insights**: Architectural observations and design patterns
    - **Usage Context**: How the traced element is used in the broader system`;
    
        // Build the tracing prompt
        let prompt = `Code Tracing Task: ${params.task}`;
        
        if (params.targetDescription) {
          prompt += `\n\nTarget Description: ${params.targetDescription}`;
        }
        
        prompt += `\n\nTracing Mode: ${params.traceMode}`;
        
        // Add file context if provided
        if (params.files && params.files.length > 0) {
          prompt += `\n\nFiles to focus on: ${params.files.join(", ")}`;
        } else {
          prompt += `\n\nPlease analyze all relevant files in the codebase to understand the target.`;
        }
    
        if (params.traceMode === 'ask') {
          prompt += `\n\nPLEASE START BY ASKING THE USER TO CHOOSE A TRACING MODE:
    - **PRECISION MODE**: Traces execution flow, call chains, and usage patterns (best for methods/functions)
    - **DEPENDENCIES MODE**: Maps structural relationships and bidirectional dependencies (best for classes/modules)
    
    Explain these options clearly and wait for the user to specify which mode to use before proceeding with the actual tracing analysis.`;
        } else {
          prompt += `\n\nPlease conduct systematic ${params.traceMode} tracing analysis. Examine the code thoroughly, trace all relevant relationships, and provide comprehensive findings with specific file references and line numbers.`;
        }
    
        try {
          const response = await provider.generateText({
            prompt,
            systemPrompt,
            temperature: 0.2, // Lower temperature for systematic analysis
            reasoningEffort: (providerName === "openai" || providerName === "azure" || providerName === "grok") ? "high" : undefined,
            useSearchGrounding: false, // Tracing focuses on local code analysis
            toolName: 'tracer',
          });
    
          // Build structured response
          const trace = {
            task: params.task,
            trace_mode: params.traceMode,
            target_description: params.targetDescription,
            files_analyzed: params.files || "comprehensive codebase analysis",
            trace_analysis: response.text,
            provider_used: providerName,
            model_used: response.model,
          };
    
          // Analyze response to determine trace completion status
          const analysisText = response.text.toLowerCase();
          const isAskingForMode = params.traceMode === 'ask' || analysisText.includes("choose") || analysisText.includes("which mode") || analysisText.includes("precision or dependencies");
          const hasCodeReferences = analysisText.includes("line") || analysisText.includes("file") || analysisText.includes(".js") || analysisText.includes(".ts") || analysisText.includes(".py");
          const hasTraceFindings = analysisText.includes("trace") || analysisText.includes("calls") || analysisText.includes("dependencies") || analysisText.includes("flow");
    
          let traceStatus = "in_progress";
          if (isAskingForMode) {
            traceStatus = "awaiting_mode_selection";
          } else if (hasCodeReferences && hasTraceFindings) {
            traceStatus = "analysis_complete";
          } else {
            traceStatus = "needs_more_investigation";
          }
    
          const result = {
            trace,
            trace_status: traceStatus,
            mode_selection_required: isAskingForMode,
            has_code_references: hasCodeReferences,
            has_trace_findings: hasTraceFindings,
            next_steps: isAskingForMode 
              ? "User must select tracing mode (precision or dependencies) before proceeding with analysis"
              : traceStatus === "needs_more_investigation"
              ? "Continue systematic code investigation to gather more tracing evidence"
              : "Tracing analysis complete with comprehensive findings",
            analysis_quality: hasCodeReferences && hasTraceFindings ? "comprehensive" : hasTraceFindings ? "moderate" : "preliminary",
          };
    
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify(result, null, 2),
              },
            ],
            metadata: {
              toolName: "tracer",
              traceMode: params.traceMode,
              traceStatus: traceStatus,
              provider: providerName,
              model: response.model,
              usage: response.usage,
              ...response.metadata,
            },
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify({
                  error: "Code tracing failed",
                  message: error instanceof Error ? error.message : "Unknown error",
                  task: params.task,
                  traceMode: params.traceMode,
                }, null, 2),
              },
            ],
            isError: true,
          };
        }
      }
  • src/server.ts:791-809 (registration)
    Registers the prompt template for the 'tracer' tool, enabling natural language invocation with args mapping to structured tool calls.
    server.registerPrompt("tracer", {
      title: "Code Tracer",
      description: "Trace execution flow and debug complex code relationships", 
      argsSchema: {
        task: z.string(),
        traceMode: z.string().optional(),
        targetDescription: z.string().optional(),
        files: z.string().optional(),
        provider: z.string().optional(),
      },
    }, (args) => ({
      messages: [{
        role: "user",
        content: {
          type: "text",
          text: `Trace this code: ${args.task}${args.traceMode ? ` (trace mode: ${args.traceMode})` : ''}${args.targetDescription ? `\n\nTarget to trace: ${args.targetDescription}` : ''}${args.files ? `\n\nFocus on files: ${args.files}` : ''}${args.provider ? ` (using ${args.provider} provider)` : ''}`
        }
      }]
    }));
  • Zod schema for tracer tool inputs, used for type inference in the handler function (duplicate of server.ts schema).
    const TracerSchema = z.object({
      task: z.string().describe("What to trace and WHY you need this analysis (e.g., 'trace User.login() execution flow', 'map UserService dependencies', 'understand payment processing call chain')"),
      traceMode: z.enum(["precision", "dependencies", "ask"]).default("ask").describe("Type of tracing: 'ask' (prompts user to choose), 'precision' (execution flow), 'dependencies' (structural relationships)"),
      targetDescription: z.string().optional().describe("Detailed description of what to trace - method, function, class, or module name and context"),
      files: z.array(z.string()).optional().describe("Relevant files to focus tracing on (optional)"),
      provider: z.enum(["openai", "gemini", "azure", "grok"]).optional().default("gemini").describe("AI provider to use"),
    });
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 high-level intent without disclosing behavioral traits. It doesn't mention what gets traced (e.g., code execution, dependencies), output format, permissions needed, rate limits, or side effects. 'Debug complex issues' is too vague to inform agent behavior.

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, efficient sentence without wasted words. It's front-loaded with the core purpose, though it could be more structured by explicitly separating tracing from debugging aspects.

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?

Given 5 parameters, no annotations, and no output schema, the description is incomplete. It doesn't explain what tracing entails, what the output looks like, or how it integrates with debugging, leaving significant gaps for a tool with multiple configuration options.

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?

Schema description coverage is 100%, so parameters are well-documented in the schema itself. The description adds no additional meaning about parameters beyond what's in the schema, maintaining the baseline score of 3 for adequate schema coverage.

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

Purpose3/5

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

The description 'Trace execution flow and debug complex issues' states a general purpose but lacks specificity about what resources are traced (code, systems, etc.) and doesn't distinguish from sibling tools like 'debug-issue' or 'analyze-code'. It uses vague terms like 'complex issues' without clarifying scope.

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 alternatives like 'debug-issue', 'analyze-code', or 'investigate'. The description implies debugging but doesn't specify context or exclusions, leaving the agent to guess based on tool names alone.

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/RealMikeChong/ultra-mcp'

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