Skip to main content
Glama

take_snapshot

Capture DOM snapshots with stable unique identifiers for automated browser testing and web scraping using Firefox DevTools. Retake snapshots after page navigation to maintain element references.

Instructions

Capture DOM snapshot with stable UIDs. Retake after navigation.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
maxLinesNoMax lines (default: 100)
includeAttributesNoInclude ARIA attributes (default: false)
includeTextNoInclude text (default: true)
maxDepthNoMax tree depth

Implementation Reference

  • Main handler for take_snapshot tool: validates args, calls FirefoxDevTools.takeSnapshot(), formats and truncates the DOM snapshot tree, constructs output with metadata.
    export async function handleTakeSnapshot(args: unknown): Promise<McpToolResponse> {
      try {
        const {
          maxLines: requestedMaxLines = DEFAULT_SNAPSHOT_LINES,
          includeAttributes = false,
          includeText = true,
          maxDepth,
        } = (args as {
          maxLines?: number;
          includeAttributes?: boolean;
          includeText?: boolean;
          maxDepth?: number;
        }) || {};
    
        // Apply hard cap on maxLines to prevent token overflow
        const maxLines = Math.min(Math.max(1, requestedMaxLines), TOKEN_LIMITS.MAX_SNAPSHOT_LINES_CAP);
        const wasCapped = requestedMaxLines > TOKEN_LIMITS.MAX_SNAPSHOT_LINES_CAP;
    
        const { getFirefox } = await import('../index.js');
        const firefox = await getFirefox();
    
        const snapshot = await firefox.takeSnapshot();
    
        // Import formatter to apply custom options
        const { formatSnapshotTree } = await import('../firefox/snapshot/formatter.js');
        const options: any = {
          includeAttributes,
          includeText,
        };
        if (maxDepth !== undefined) {
          options.maxDepth = maxDepth;
        }
        const formattedText = formatSnapshotTree(snapshot.json.root, 0, options);
    
        // Get snapshot text (truncated if needed)
        const lines = formattedText.split('\n');
    
        const truncated = lines.length > maxLines;
        const displayLines = truncated ? lines.slice(0, maxLines) : lines;
    
        // Build compact output
        let output = `📸 Snapshot (id=${snapshot.json.snapshotId})`;
        if (wasCapped) {
          output += ` [maxLines capped: ${TOKEN_LIMITS.MAX_SNAPSHOT_LINES_CAP}]`;
        }
        if (snapshot.json.truncated) {
          output += ' [DOM truncated]';
        }
        output += '\n\n';
    
        // Add snapshot tree
        output += displayLines.join('\n');
    
        if (truncated) {
          output += `\n\n[+${lines.length - maxLines} lines, use maxLines to see more]`;
        }
    
        return successResponse(output);
      } catch (error) {
        return errorResponse(
          new Error(
            `Failed to take snapshot: ${(error as Error).message}\n\n` +
              'The page may not be fully loaded or accessible.'
          )
        );
      }
    }
  • Tool schema defining name, description, and input parameters for take_snapshot.
    export const takeSnapshotTool = {
      name: 'take_snapshot',
      description: 'Capture DOM snapshot with stable UIDs. Retake after navigation.',
      inputSchema: {
        type: 'object',
        properties: {
          maxLines: {
            type: 'number',
            description: 'Max lines (default: 100)',
          },
          includeAttributes: {
            type: 'boolean',
            description: 'Include ARIA attributes (default: false)',
          },
          includeText: {
            type: 'boolean',
            description: 'Include text (default: true)',
          },
          maxDepth: {
            type: 'number',
            description: 'Max tree depth',
          },
        },
      },
    };
  • src/index.ts:103-147 (registration)
    Registration of all tool handlers in the toolHandlers Map, including take_snapshot mapped to handleTakeSnapshot.
    const toolHandlers = new Map<
      string,
      (input: unknown) => Promise<{ content: Array<{ type: string; text: string }>; isError?: boolean }>
    >([
      // Pages
      ['list_pages', tools.handleListPages],
      ['new_page', tools.handleNewPage],
      ['navigate_page', tools.handleNavigatePage],
      ['select_page', tools.handleSelectPage],
      ['close_page', tools.handleClosePage],
    
      // Script evaluation - DISABLED (see docs/future-features.md)
      // ['evaluate_script', tools.handleEvaluateScript],
    
      // Console
      ['list_console_messages', tools.handleListConsoleMessages],
      ['clear_console_messages', tools.handleClearConsoleMessages],
    
      // Network
      ['list_network_requests', tools.handleListNetworkRequests],
      ['get_network_request', tools.handleGetNetworkRequest],
    
      // Snapshot
      ['take_snapshot', tools.handleTakeSnapshot],
      ['resolve_uid_to_selector', tools.handleResolveUidToSelector],
      ['clear_snapshot', tools.handleClearSnapshot],
    
      // Input
      ['click_by_uid', tools.handleClickByUid],
      ['hover_by_uid', tools.handleHoverByUid],
      ['fill_by_uid', tools.handleFillByUid],
      ['drag_by_uid_to_uid', tools.handleDragByUidToUid],
      ['fill_form_by_uid', tools.handleFillFormByUid],
      ['upload_file_by_uid', tools.handleUploadFileByUid],
    
      // Screenshot
      ['screenshot_page', tools.handleScreenshotPage],
      ['screenshot_by_uid', tools.handleScreenshotByUid],
    
      // Utilities
      ['accept_dialog', tools.handleAcceptDialog],
      ['dismiss_dialog', tools.handleDismissDialog],
      ['navigate_history', tools.handleNavigateHistory],
      ['set_viewport_size', tools.handleSetViewportSize],
    ]);
  • src/index.ts:150-191 (registration)
    Registration of all tools in allTools array for ListToolsRequest, including takeSnapshotTool.
    const allTools = [
      // Pages
      tools.listPagesTool,
      tools.newPageTool,
      tools.navigatePageTool,
      tools.selectPageTool,
      tools.closePageTool,
    
      // Script evaluation - DISABLED (see docs/future-features.md)
      // tools.evaluateScriptTool,
    
      // Console
      tools.listConsoleMessagesTool,
      tools.clearConsoleMessagesTool,
    
      // Network
      tools.listNetworkRequestsTool,
      tools.getNetworkRequestTool,
    
      // Snapshot
      tools.takeSnapshotTool,
      tools.resolveUidToSelectorTool,
      tools.clearSnapshotTool,
    
      // Input
      tools.clickByUidTool,
      tools.hoverByUidTool,
      tools.fillByUidTool,
      tools.dragByUidToUidTool,
      tools.fillFormByUidTool,
      tools.uploadFileByUidTool,
    
      // Screenshot
      tools.screenshotPageTool,
      tools.screenshotByUidTool,
    
      // Utilities
      tools.acceptDialogTool,
      tools.dismissDialogTool,
      tools.navigateHistoryTool,
      tools.setViewportSizeTool,
    ];
  • FirefoxDevTools method called by the handler to capture the raw snapshot, delegates to this.snapshot.takeSnapshot().
    async takeSnapshot(): Promise<Snapshot> {
      if (!this.snapshot) {
        throw new Error('Not connected');
      }
      return await this.snapshot.takeSnapshot();
Behavior4/5

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

With no annotations provided, the description carries full burden and delivers well: it discloses the critical behavioral trait of 'stable UIDs' (persistent identifiers across captures) and the navigation constraint. It doesn't mention performance implications, error conditions, or what exactly gets captured beyond DOM, but covers essential operational context.

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?

Extremely concise with two sentences that each earn their place: first establishes core functionality with key trait, second provides crucial usage guidance. No wasted words, perfectly front-loaded with essential information.

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

Completeness4/5

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

For a 4-parameter tool with no annotations and no output schema, the description provides strong context about what the tool does and when to use it. It could benefit from mentioning what the snapshot output contains or format, but given the sibling tools (like clear_snapshot suggesting snapshot management), it's reasonably complete for the agent's needs.

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%, providing full parameter documentation. The description adds no parameter-specific information beyond what's in the schema, so it meets the baseline of 3. It doesn't explain how parameters interact with the 'stable UIDs' feature or navigation constraint.

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 specific action ('Capture DOM snapshot') and key behavioral trait ('with stable UIDs'), distinguishing it from sibling tools like screenshot_page or clear_snapshot. It explicitly mentions the resource (DOM) and unique functionality (UID persistence).

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 provides clear context for when to use ('Retake after navigation'), indicating this tool is for capturing page state that becomes invalid after navigation. However, it doesn't explicitly state when NOT to use it or name alternatives like screenshot_page for visual captures.

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/mozilla/firefox-devtools-mcp'

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