Skip to main content
Glama

get_call_stack

Retrieve the current call stack when execution is paused, showing the chain of function calls with file locations and scope information, including async traces and source map support.

Instructions

Retrieves the current call stack when execution is paused. Shows the chain of function calls that led to the current location, including function names, file locations, and scope information. If source maps are available, original source locations are included.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
session_idYesID of the debugging session. The session must be paused.
include_asyncNoWhether to include asynchronous stack traces (Promise chains, async/await). Defaults to true.

Implementation Reference

  • src/server.ts:256-278 (registration)
    Tool registration for 'get_call_stack' with input schema definition (session_id required, include_async optional boolean).
    {
      name: 'get_call_stack',
      description:
        'Retrieves the current call stack when execution is paused. ' +
        'Shows the chain of function calls that led to the current location, ' +
        'including function names, file locations, and scope information. ' +
        'If source maps are available, original source locations are included.',
      inputSchema: {
        type: 'object',
        properties: {
          session_id: {
            type: 'string',
            description: 'ID of the debugging session. The session must be paused.',
          },
          include_async: {
            type: 'boolean',
            description:
              'Whether to include asynchronous stack traces (Promise chains, async/await). Defaults to true.',
          },
        },
        required: ['session_id'],
      },
    },
  • Handler implementation for 'get_call_stack' tool call. Validates params via Zod, calls sessionManager.getCallStack(), and formats the response with call frames (ID, function name, generated/original location, scope chain) and optional async stack trace.
    case 'get_call_stack': {
      const params = z
        .object({
          session_id: z.string(),
          include_async: z.boolean().optional(),
        })
        .parse(args);
    
      const {callFrames, asyncStackTrace} = sessionManager.getCallStack(
        params.session_id,
        params.include_async ?? true
      );
    
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(
              {
                call_frames: callFrames.map((frame) => ({
                  call_frame_id: frame.callFrameId,
                  function_name: frame.functionName,
                  generated_location: {
                    script_id: frame.generatedLocation.scriptId,
                    line_number: frame.generatedLocation.lineNumber,
                    column_number: frame.generatedLocation.columnNumber,
                  },
                  original_location: frame.originalLocation
                    ? {
                        source_url: frame.originalLocation.sourceUrl,
                        line_number: frame.originalLocation.lineNumber,
                        column_number: frame.originalLocation.columnNumber,
                        function_name: frame.originalLocation.functionName,
                      }
                    : undefined,
                  scope_chain: frame.scopeChain.map((scope) => ({
                    type: scope.type,
                    name: scope.name,
                  })),
                })),
                async_stack_trace: asyncStackTrace
                  ? {
                      description: asyncStackTrace.description,
                    }
                  : undefined,
              },
              null,
              2
            ),
          },
        ],
  • SessionManager.getCallStack() - retrieves the enriched call stack for a paused session. Calls enrichCallFrames() and optionally includes asyncStackTrace from paused state.
    getCallStack(
      sessionId: string,
      includeAsync = true
    ): {
      callFrames: EnrichedCallFrame[];
      asyncStackTrace?: Protocol.Runtime.StackTrace;
    } {
      const session = this.getSession(sessionId);
      this.ensurePaused(session);
    
      const enrichedFrames = this.enrichCallFrames(session);
    
      return {
        callFrames: enrichedFrames,
        asyncStackTrace: includeAsync
          ? session.pausedState?.asyncStackTrace
          : undefined,
      };
    }
  • EnrichCallFrames() private helper - maps raw CDP call frames to EnrichedCallFrame objects, resolving original source locations via sourceMapManager.
    private enrichCallFrames(session: ManagedSession): EnrichedCallFrame[] {
      if (!session.pausedState) return [];
    
      return session.pausedState.callFrames.map((frame) => {
        const enriched: EnrichedCallFrame = {
          callFrameId: frame.callFrameId,
          functionName: frame.functionName,
          generatedLocation: {
            scriptId: frame.location.scriptId,
            lineNumber: frame.location.lineNumber,
            columnNumber: frame.location.columnNumber ?? 0,
          },
          scopeChain: frame.scopeChain,
          this: frame.this,
        };
    
        // Try to map to original location.
        const original = session.sourceMapManager.getOriginalLocation(
          frame.location.scriptId,
          frame.location.lineNumber + 1, // source-map uses 1-based lines.
          frame.location.columnNumber ?? 0
        );
    
        if (original) {
          enriched.originalLocation = {
            sourceUrl: original.source,
            lineNumber: original.line ?? 0,
            columnNumber: original.column ?? 0,
            functionName: original.name ?? undefined,
          };
        }
    
        return enriched;
      });
    }
  • EnrichedCallFrame interface type definition, defining the structure of each call frame returned by get_call_stack.
    export interface EnrichedCallFrame {
      callFrameId: string;
      functionName: string;
      generatedLocation: {
        scriptId: string;
        lineNumber: number;
        columnNumber: number;
      };
      originalLocation?: {
        sourceUrl: string;
        lineNumber: number;
        columnNumber: number;
        functionName?: string;
      };
      scopeChain: Protocol.Debugger.Scope[];
      this: Protocol.Runtime.RemoteObject;
    }
Behavior5/5

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

With no annotations provided, the description fully covers behavior: it lists the information included in the call stack (function names, file locations, scope information) and mentions that original source locations are included if source maps are available. This sufficiently discloses the tool's output and conditions.

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

Conciseness5/5

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

The description consists of three sentences with no wasted words. The first sentence immediately states the main purpose, and the following sentences provide necessary details. It is well-structured and front-loaded.

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

Completeness5/5

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

Given there is no output schema, the description adequately explains what the tool returns (function names, file locations, scope info) and the condition under which it works (execution paused). It also mentions source maps, which adds completeness without requiring additional explanation.

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 input schema has 100% description coverage, so the baseline is 3. The description does not add new information about the parameters beyond the schema, but it provides context about the output that indirectly helps understand the parameters. No contradiction or extra detail on parameters.

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 that the tool retrieves the current call stack when execution is paused. It uses a specific verb ('retrieves') and resource ('call stack'), and distinguishes itself from sibling debugger tools like 'step_into' or 'evaluate_expression' which have different purposes.

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

Usage Guidelines4/5

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

The description specifies that the tool should be used 'when execution is paused', providing clear context. However, it does not explicitly mention when not to use it or list alternative tools for different scenarios, though the sibling names imply other debugger operations.

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/johngrimes/mcp-js-debugger'

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