Skip to main content
Glama
BrowserGenie

BrowserGenie MCP Server

by BrowserGenie

compare_snapshots

Compare two page state snapshots to detect differences and verify state changes after browser actions. Supports text or DOM comparison modes.

Instructions

Compare two page state snapshots (from browser_snapshot or read_page_html) and return the differences. Use this to verify state changes after an action.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
beforeYesFirst snapshot string (captured before action)
afterYesSecond snapshot string (captured after action)
modeNoComparison mode: text (line-by-line) or dom (element-level)text

Implementation Reference

  • The handler function for the compare_snapshots tool. It accepts 'before' and 'after' snapshot strings and an optional 'mode' ('dom' or 'text', default 'text'). In 'dom' mode, it compares HTML tags. In 'text' mode, it performs line-by-line diff.
    server.tool(
      'compare_snapshots',
      'Compare two page state snapshots (from browser_snapshot or read_page_html) and return the differences. Use this to verify state changes after an action.',
      {
        before: z.string().describe('First snapshot string (captured before action)'),
        after: z.string().describe('Second snapshot string (captured after action)'),
        mode: z.enum(['dom', 'text']).optional().default('text').describe('Comparison mode: text (line-by-line) or dom (element-level)'),
      },
      async ({ before, after, mode }) => {
        if (mode === 'dom') {
          // Simple DOM diff approach: compare tag sequences
          const beforeTags: string[] = before.match(/<[^>]+>/g) || [];
          const afterTags: string[] = after.match(/<[^>]+>/g) || [];
          const added = afterTags.filter((t) => !beforeTags.includes(t));
          const removed = beforeTags.filter((t) => !afterTags.includes(t));
          return {
            content: [{
              type: 'text',
              text: `DOM Diff:\nAdded (${added.length}):\n${added.slice(0, 50).join('\n')}\n\nRemoved (${removed.length}):\n${removed.slice(0, 50).join('\n')}`,
            }],
          };
        }
    
        // Text mode: line-by-line diff
        const beforeLines = before.split('\n');
        const afterLines = after.split('\n');
        const changes: string[] = [];
        const maxLen = Math.max(beforeLines.length, afterLines.length);
        for (let i = 0; i < maxLen; i++) {
          if (beforeLines[i] !== afterLines[i]) {
            if (beforeLines[i] === undefined) {
              changes.push(`+ ${afterLines[i]}`);
            } else if (afterLines[i] === undefined) {
              changes.push(`- ${beforeLines[i]}`);
            } else {
              changes.push(`- ${beforeLines[i]}`);
              changes.push(`+ ${afterLines[i]}`);
            }
          }
        }
        return {
          content: [{
            type: 'text',
            text: `Text Diff (${changes.length} changes):\n${changes.slice(0, 200).join('\n')}`,
          }],
        };
      }
    );
  • Input schema for compare_snapshots tool: 'before' (string), 'after' (string), and optional 'mode' (enum 'dom'|'text', default 'text').
    {
      before: z.string().describe('First snapshot string (captured before action)'),
      after: z.string().describe('Second snapshot string (captured after action)'),
      mode: z.enum(['dom', 'text']).optional().default('text').describe('Comparison mode: text (line-by-line) or dom (element-level)'),
    },
  • The tool is registered via server.tool('compare_snapshots', ...) inside registerAccessibilityTools() at line 75 of accessibility.ts.
    server.tool(
      'compare_snapshots',
      'Compare two page state snapshots (from browser_snapshot or read_page_html) and return the differences. Use this to verify state changes after an action.',
      {
        before: z.string().describe('First snapshot string (captured before action)'),
        after: z.string().describe('Second snapshot string (captured after action)'),
        mode: z.enum(['dom', 'text']).optional().default('text').describe('Comparison mode: text (line-by-line) or dom (element-level)'),
      },
      async ({ before, after, mode }) => {
        if (mode === 'dom') {
          // Simple DOM diff approach: compare tag sequences
          const beforeTags: string[] = before.match(/<[^>]+>/g) || [];
          const afterTags: string[] = after.match(/<[^>]+>/g) || [];
          const added = afterTags.filter((t) => !beforeTags.includes(t));
          const removed = beforeTags.filter((t) => !afterTags.includes(t));
          return {
            content: [{
              type: 'text',
              text: `DOM Diff:\nAdded (${added.length}):\n${added.slice(0, 50).join('\n')}\n\nRemoved (${removed.length}):\n${removed.slice(0, 50).join('\n')}`,
            }],
          };
        }
    
        // Text mode: line-by-line diff
        const beforeLines = before.split('\n');
        const afterLines = after.split('\n');
        const changes: string[] = [];
        const maxLen = Math.max(beforeLines.length, afterLines.length);
        for (let i = 0; i < maxLen; i++) {
          if (beforeLines[i] !== afterLines[i]) {
            if (beforeLines[i] === undefined) {
              changes.push(`+ ${afterLines[i]}`);
            } else if (afterLines[i] === undefined) {
              changes.push(`- ${beforeLines[i]}`);
            } else {
              changes.push(`- ${beforeLines[i]}`);
              changes.push(`+ ${afterLines[i]}`);
            }
          }
        }
        return {
          content: [{
            type: 'text',
            text: `Text Diff (${changes.length} changes):\n${changes.slice(0, 200).join('\n')}`,
          }],
        };
      }
    );
  • registerAccessibilityTools is called from registerAllTools() in the tools index, which wires it into the MCP server.
    registerAccessibilityTools(server, bridge);
Behavior2/5

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

No annotations provided, yet description fails to disclose any behavioral traits such as output format, performance implications for large snapshots, error conditions, or side effects. Only states 'return the differences' without structure.

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?

Two concise sentences that front-load the action and purpose with no wasted words. Every sentence adds value.

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

Completeness3/5

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

Minimally adequate for a simple comparison tool with well-documented parameters, but lacks details on output format and error handling, which are not covered by schema or annotations.

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 descriptions cover all three parameters with clear explanations (e.g., mode: 'text (line-by-line) or dom (element-level)'), so the description adds minimal extra semantic value. Baseline of 3 is appropriate due to high schema coverage.

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?

Clearly states 'compare two page state snapshots' and 'return the differences', with explicit purpose to verify state changes after an action. Distinguishes from siblings like diff_page_source and compare_screenshots by naming the source tools (browser_snapshot, read_page_html).

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

Usage Guidelines3/5

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

Provides a clear use case ('verify state changes after an action') but does not specify when not to use this tool versus alternatives like diff_page_source or compare_screenshots. No exclusions or prerequisites mentioned.

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/BrowserGenie/mcp'

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