Skip to main content
Glama

analyze_screenshot

Analyze test screenshots using OCR and visual analysis to extract text, compare UI states, and provide detailed image analysis for QA validation.

Instructions

🔍 Analyze test screenshot with OCR and visual analysis - returns image to Claude Vision for detailed analysis

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
screenshotUrlNoScreenshot URL to download and analyze
screenshotPathNoLocal path to screenshot file
testIdNoTest ID for context
enableOCRNoEnable OCR text extraction (slower)
analysisTypeNobasic=metadata+OCR only, detailed=includes image for Claude Visiondetailed
expectedStateNoExpected UI state for comparison

Implementation Reference

  • Core handler function that implements the analyze_screenshot tool logic. Analyzes image buffer for metadata (using Sharp), optional OCR (Tesseract.js), UI elements detection, and device info detection.
    export async function analyzeScreenshot(
      buffer: Buffer,
      options: {
        enableOCR?: boolean;
        ocrLanguage?: string;
      } = {}
    ): Promise<ScreenshotAnalysis> {
      const { enableOCR = false, ocrLanguage = 'eng' } = options;
      
      // Extract metadata
      const metadata = await getImageMetadata(buffer);
      
      // Optional OCR
      let ocrResult: OCRResult | undefined;
      let uiElements: ScreenshotAnalysis['uiElements'] | undefined;
      
      if (enableOCR) {
        try {
          ocrResult = await extractTextOCR(buffer, { lang: ocrLanguage });
          const uiDetection = detectUIElements(ocrResult.text);
          uiElements = {
            hasLoadingIndicator: uiDetection.hasLoadingIndicator,
            hasErrorDialog: uiDetection.hasErrorDialog,
            hasEmptyState: uiDetection.hasEmptyState,
            hasNavigationBar: uiDetection.hasNavigationBar
          };
        } catch (error) {
          console.warn('OCR failed, continuing without text extraction:', error);
        }
      }
      
      // Device detection
      const deviceInfo = detectDeviceInfo(metadata);
      
      return {
        metadata,
        ocrText: ocrResult,
        deviceInfo: {
          detectedDevice: deviceInfo.detectedDevice,
          statusBarVisible: metadata.height > 2000, // Rough heuristic
          navigationBarVisible: uiElements?.hasNavigationBar
        },
        uiElements
      };
    }
  • Output schema/type definition for the screenshot analysis result, including metadata, OCR results, device info, and UI elements.
    export interface ScreenshotAnalysis {
      metadata: ImageMetadata;
      ocrText?: OCRResult;
      deviceInfo?: {
        detectedDevice?: string;
        statusBarVisible?: boolean;
        navigationBarVisible?: boolean;
      };
      uiElements?: {
        hasLoadingIndicator?: boolean;
        hasErrorDialog?: boolean;
        hasEmptyState?: boolean;
        hasNavigationBar?: boolean;
      };
    }
  • Input/output schema for image metadata extracted by Sharp.
    export interface ImageMetadata {
      width: number;
      height: number;
      format: string;
      size: number;
      orientation: 'portrait' | 'landscape' | 'square';
      aspectRatio: string;
      hasAlpha: boolean;
      colorSpace?: string;
    }
  • Helper function to extract detailed image metadata using Sharp library.
    export async function getImageMetadata(buffer: Buffer): Promise<ImageMetadata> {
      try {
        const image = sharp(buffer);
        const metadata = await image.metadata();
        const stats = await image.stats();
        
        const width = metadata.width || 0;
        const height = metadata.height || 0;
        
        let orientation: 'portrait' | 'landscape' | 'square' = 'square';
        if (width > height) orientation = 'landscape';
        else if (height > width) orientation = 'portrait';
        
        const gcd = (a: number, b: number): number => b === 0 ? a : gcd(b, a % b);
        const divisor = gcd(width, height);
        const aspectRatio = `${width / divisor}:${height / divisor}`;
        
        return {
          width,
          height,
          format: metadata.format || 'unknown',
          size: buffer.length,
          orientation,
          aspectRatio,
          hasAlpha: metadata.hasAlpha || false,
          colorSpace: metadata.space
        };
      } catch (error) {
        throw new Error(`Failed to extract image metadata: ${error instanceof Error ? error.message : error}`);
      }
    }
  • Helper function for OCR text extraction using Tesseract.js, configurable language and PSM.
    export async function extractTextOCR(
      buffer: Buffer,
      options: {
        lang?: string;
        psm?: number;
      } = {}
    ): Promise<OCRResult> {
      const { lang = 'eng', psm = 3 } = options;
      
      let worker: Worker | null = null;
      try {
        worker = await createWorker(lang, 1, {
          logger: () => {}, // Suppress logs
        });
        
        await worker.setParameters({
          tessedit_pageseg_mode: psm as any,
        });
        
        const { data } = await worker.recognize(buffer);
        
        const words = data.words.map(word => ({
          text: word.text,
          confidence: word.confidence,
          bbox: {
            x: word.bbox.x0,
            y: word.bbox.y0,
            width: word.bbox.x1 - word.bbox.x0,
            height: word.bbox.y1 - word.bbox.y0
          }
        }));
        
        const lines = data.lines.map(line => line.text);
        
        return {
          text: data.text.trim(),
          confidence: data.confidence,
          words,
          lines
        };
      } catch (error) {
        throw new Error(`OCR extraction failed: ${error instanceof Error ? error.message : error}`);
      } finally {
        if (worker) {
          await worker.terminate();
        }
      }
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions OCR and visual analysis, and that it 'returns image to Claude Vision for detailed analysis,' which gives some insight into processing behavior. However, it fails to disclose critical traits: whether this is a read-only or mutating operation, performance implications (e.g., 'slower' is noted in schema but not description), authentication needs, rate limits, or error handling. For a tool with 6 parameters and no annotations, this is a significant gap.

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 is appropriately sized and front-loaded: a single sentence efficiently conveys the core functionality (analyze screenshot with OCR/visual analysis) and key behavioral detail (returns to Claude Vision). Every word earns its place with no redundancy or fluff, making it easy to scan and understand quickly.

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?

Given the tool's complexity (6 parameters, no output schema, no annotations), the description is moderately complete. It covers the purpose and high-level behavior but lacks details on when to use it vs. siblings, full behavioral traits, and output expectations. Without annotations or output schema, the description should do more to compensate, but it provides a basic foundation that's adequate for simple use cases.

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 schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds minimal value beyond the schema: it implies the tool uses OCR and visual analysis, which relates to 'enableOCR' and 'analysisType' parameters, but doesn't provide additional syntax, format details, or usage examples. With high schema coverage, the baseline is 3, and the description doesn't significantly enhance parameter understanding.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Analyze test screenshot with OCR and visual analysis' specifies the verb (analyze) and resource (test screenshot) with the methods used (OCR and visual analysis). It distinguishes from sibling tools like 'download_test_screenshot' (which only downloads) and 'analyze_test_execution_video' (which analyzes videos). However, it doesn't explicitly mention what makes it unique from other analysis tools in the list.

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?

The description provides minimal guidance: it mentions the tool returns 'image to Claude Vision for detailed analysis,' which implies when detailed visual analysis is needed. However, it lacks explicit when-to-use criteria, doesn't specify alternatives among siblings (e.g., when to use this vs. 'analyze_test_failure'), and offers no exclusions or prerequisites. This leaves usage context largely implied.

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/maksimsarychau/mcp-zebrunner'

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