Skip to main content
Glama

compare_screenshots

Compare visual changes between two URLs by capturing screenshots at identical viewport sizes, calculating difference percentages, and verifying UI modifications.

Instructions

Before/after visual comparison. Captures screenshots of two URLs at the same viewport size, returns BOTH images for visual comparison, and calculates a difference percentage. Use this to verify UI changes, compare staging vs production, or check before/after states of a redesign.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlAYesFirst URL — the 'before' state (e.g., http://localhost:3000)
urlBYesSecond URL — the 'after' state (e.g., http://localhost:3001)
widthNoViewport width in pixels
heightNoViewport height in pixels

Implementation Reference

  • The compareScreenshots function implements the logic for comparing two URLs visually.
    export async function compareScreenshots(
      urlA: string,
      urlB: string,
      options?: { readonly width?: number; readonly height?: number }
    ): Promise<ComparisonResult> {
      const width = options?.width ?? 1440;
      const height = options?.height ?? 900;
    
      const screenshotA = await captureUrlScreenshot(urlA, width, height);
      const screenshotB = await captureUrlScreenshot(urlB, width, height);
    
      const differencePercent = calculateBase64DifferencePercent(
        screenshotA.base64,
        screenshotB.base64
      );
    
      return {
        screenshotA,
        screenshotB,
        differencePercent,
        urlA,
        urlB,
      };
    }
  • Type definitions for the comparison screenshot and result.
    export interface ComparisonScreenshot {
      readonly base64: string;
      readonly mimeType: "image/png";
      readonly width: number;
      readonly height: number;
      readonly url: string;
      readonly timestamp: string;
    }
    
    export interface ComparisonResult {
      readonly screenshotA: ComparisonScreenshot;
      readonly screenshotB: ComparisonScreenshot;
      readonly differencePercent: number;
      readonly urlA: string;
      readonly urlB: string;
    }
  • src/server.ts:404-412 (registration)
    The compare_screenshots tool is registered here with its input schema definition.
    server.tool(
      "compare_screenshots",
      "Before/after visual comparison. Captures screenshots of two URLs at the same viewport size, returns BOTH images for visual comparison, and calculates a difference percentage. Use this to verify UI changes, compare staging vs production, or check before/after states of a redesign.",
      {
        urlA: z.string().url().describe("First URL — the 'before' state (e.g., http://localhost:3000)"),
        urlB: z.string().url().describe("Second URL — the 'after' state (e.g., http://localhost:3001)"),
        width: z.number().optional().default(1440).describe("Viewport width in pixels"),
        height: z.number().optional().default(900).describe("Viewport height in pixels"),
      },
  • Helper function to calculate the percentage difference between two base64 strings.
    function calculateBase64DifferencePercent(
      base64A: string,
      base64B: string
    ): number {
      if (base64A === base64B) {
        return 0;
      }
    
      const maxLength = Math.max(base64A.length, base64B.length);
    
      if (maxLength === 0) {
        return 0;
      }
    
      let differingCharacters = 0;
    
      for (let i = 0; i < maxLength; i++) {
        if (base64A[i] !== base64B[i]) {
          differingCharacters++;
        }
      }
    
      const rawPercent = (differingCharacters / maxLength) * 100;
      return Math.round(rawPercent * 100) / 100;
    }
Behavior3/5

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

No annotations are provided, so the description carries the full disclosure burden. It successfully conveys core behavioral traits: simultaneous capture at identical viewport dimensions, dual image return, and quantitative diff calculation. However, it omits image format, storage persistence, caching behavior, and rate limiting constraints that would be necessary for a 4-5 score without annotation support.

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 sentences with zero redundancy. The first front-loads the core mechanism (before/after capture and comparison), while the second provides usage context. Every word earns its place; no filler or repetition of the tool name.

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?

Given the straightforward 4-parameter input schema with no nested objects, the description adequately covers the functional contract. It mentions the key return values (both images, percentage) despite lacking an output schema. Deduction because it omits the image format (base64 vs. URL) and specific data structure of the response.

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%, with all four parameters (urlA, urlB, width, height) fully documented in the schema. The description references the 'same viewport size' conceptually but does not add syntax details, validation rules, or semantic nuances beyond the schema definitions. Baseline 3 is appropriate given the schema's completeness.

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 provides a specific verb triad (captures, returns, calculates) with clear resources (screenshots, URLs, viewport). It effectively distinguishes from siblings like 'screenshot' (single capture) and 'responsive_screenshots' (multiple viewports) by emphasizing the dual-URL comparison and difference calculation.

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 second sentence provides explicit usage contexts ('verify UI changes, compare staging vs production, or check before/after states'), giving clear guidance on when to invoke. Lacks explicit 'when not to use' guidance or comparison to the single 'screenshot' tool, but the examples are concrete and actionable.

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/prembobby39-gif/uimax-mcp'

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