Skip to main content
Glama

analyze_screenshot

Capture a screenshot of a web page and use AI to analyze and describe its visible content, with options for full-page capture, specific instructions, and detailed structural analysis.

Instructions

Take a screenshot and analyze it with AI (Gemma3) to describe what is visible on the page

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fullPageNoCapture full scrollable page
pathNoPath to save screenshot (optional)
pretextNoOptional context or specific instructions for what to look for in the analysis
modelNoAI model to use for analysis (default: gemma3:4b)gemma3:4b
detailedNoProvide detailed structural analysis of the page

Implementation Reference

  • Zod schema defining the input parameters for analyze_screenshot (fullPage, path, pretext, model, detailed)
    const AnalyzeScreenshotSchema = z.object({
      fullPage: z.boolean().default(false),
      path: z.string().optional(),
      pretext: z.string().optional(),
      model: z.string().default('gemma3:4b'),
      detailed: z.boolean().default(false)
    });
  • src/index.ts:330-361 (registration)
    Tool registration in the ListToolsRequestSchema handler, defining the tool's name, description, and input JSON schema
    {
      name: 'analyze_screenshot',
      description: 'Take a screenshot and analyze it with AI (Gemma3) to describe what is visible on the page',
      inputSchema: {
        type: 'object',
        properties: {
          fullPage: {
            type: 'boolean',
            default: false,
            description: 'Capture full scrollable page'
          },
          path: {
            type: 'string',
            description: 'Path to save screenshot (optional)'
          },
          pretext: {
            type: 'string',
            description: 'Optional context or specific instructions for what to look for in the analysis'
          },
          model: {
            type: 'string',
            default: 'gemma3:4b',
            description: 'AI model to use for analysis (default: gemma3:4b)'
          },
          detailed: {
            type: 'boolean',
            default: false,
            description: 'Provide detailed structural analysis of the page'
          }
        }
      }
    },
  • Main handler logic for the analyze_screenshot tool: takes a screenshot using Playwright, sends it to Ollama (Gemma3) for AI analysis, and returns the result
              case 'analyze_screenshot': {
                if (!currentPage) {
                  throw new Error('No browser page available. Launch a browser first.');
                }
    
                const params = AnalyzeScreenshotSchema.parse(args);
                
                // Take screenshot
                const screenshotPath = params.path || `screenshot-${Date.now()}.png`;
                const screenshotBuffer = await currentPage.screenshot({ 
                  fullPage: params.fullPage,
                  path: screenshotPath
                });
    
                try {
                  // Initialize Ollama client
                  const ollama = new Ollama({ host: 'http://localhost:11434' });
    
                  // Convert screenshot to base64
                  const base64Image = screenshotBuffer.toString('base64');
    
                  // Prepare the prompt
                  let prompt = 'Analyze this website screenshot and describe exactly what you see. ';
                  
                  if (params.detailed) {
                    prompt += 'Provide a detailed structural analysis including layout, navigation elements, content sections, forms, buttons, and any interactive elements. ';
                  } else {
                    prompt += 'Focus on the main content and key elements visible on the page. ';
                  }
    
                  if (params.pretext) {
                    prompt += `Additional context/instructions: ${params.pretext}. `;
                  }
    
                  prompt += 'Be specific about colors, text content, images, and the overall design and functionality of the page.';
    
                  // Make AI request
                  const response = await ollama.generate({
                    model: params.model,
                    prompt: prompt,
                    images: [base64Image],
                    stream: false
                  });
    
                  return {
                    content: [
                      {
                        type: 'text',
                        text: `AI Analysis of Screenshot (${screenshotPath}):
    
    ${response.response}
    
    Screenshot saved to: ${screenshotPath}
    Model used: ${params.model}
    Analysis type: ${params.detailed ? 'Detailed structural analysis' : 'General description'}`
                      }
                    ]
                  };
    
                } catch (aiError) {
                  // If AI analysis fails, still return screenshot info
                  const fallbackMessage = aiError instanceof Error ? aiError.message : String(aiError);
                  
                  return {
                    content: [
                      {
                        type: 'text',
                        text: `Screenshot taken and saved to: ${screenshotPath}
    
    AI Analysis Error: ${fallbackMessage}
    
    Note: Make sure Ollama is running locally with the ${params.model} model installed.
    You can install it with: ollama pull ${params.model}
    And start Ollama with: ollama serve`
                      }
                    ]
                  };
                }
              }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

B3.1/5.0
Behavior2/5

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

No annotations exist, so the description must fully disclose behavior. It only states the action (screenshot and AI analysis) without mentioning side effects (e.g., browser must be open), potential latency, error cases, or that the analysis is local. The description is minimal and omits important behavioral details.

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

Conciseness4/5

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

The description is a single sentence with no wasted words. It is appropriately front-loaded but somewhat under-specified. Still, it earns a 4 for conciseness.

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

Completeness2/5

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

Despite full schema coverage, the description is incomplete for a tool that both screenshots and analyzes. It does not clarify the return format (e.g., text description), that the analysis uses a model configurable via 'model' parameter, or that it assumes an active browser context. For a combined action tool, more context is needed.

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 coverage is 100%; the description does not elaborate on parameters beyond what the schema provides. It adds no extra meaning about how parameters affect behavior (e.g., 'pretext' for context, 'fullPage' for scroll capture). Baseline score of 3 is appropriate.

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 tool takes a screenshot and analyzes it with AI (Gemma3) to describe the page. It uses a specific verb-action ('Take a screenshot and analyze') and resource ('page'), distinguishing it from siblings like 'screenshot' (capture only) or 'get_page_info' (non-visual).

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?

No guidance is provided on when to use this tool versus alternatives such as 'screenshot' (for capture without analysis) or 'get_page_info' (for structured data). The description lacks explicit when-to-use, when-not-to-use, or comparison with siblings.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.