Skip to main content
Glama
andytango
by andytango

screenshot

Capture screenshots of web pages or specific elements for documentation, testing, or content extraction. Configure viewport dimensions, image format, and quality settings.

Instructions

Capture a screenshot of the page or a specific element

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fullPageNoCapture full scrollable page
selectorNoElement to screenshot (screenshots viewport if not specified)
formatNopng
qualityNoImage quality (jpeg/webp only)
widthNoViewport width in pixels (default 1024)
heightNoViewport height in pixels (default 768)
scaleNoDevice scale factor (default 1, use 2 for retina)
tabIdNoTab ID to operate on (uses active tab if not specified)

Implementation Reference

  • The core handler function that executes the screenshot tool. It gets the page, sets viewport, captures screenshot of element or page, converts to base64, and returns as image content block.
    async ({ fullPage, selector, format, quality, width, height, scale, tabId }) => {
      const pageResult = await getPageForOperation(tabId);
      if (!pageResult.success) {
        return handleResult(pageResult);
      }
    
      const page = pageResult.data;
      const imageFormat = (format ?? 'png') as ScreenshotFormat;
    
      // Set viewport with sensible defaults for reasonable image sizes
      const viewportWidth = width ?? 1024;
      const viewportHeight = height ?? 768;
      const deviceScaleFactor = scale ?? 1;
    
      try {
        // Set viewport before screenshot to control resolution
        await page.setViewport({
          width: viewportWidth,
          height: viewportHeight,
          deviceScaleFactor,
        });
    
        let screenshotData: Uint8Array;
    
        if (selector) {
          // Screenshot specific element
          const element = await page.$(selector);
    
          if (!element) {
            return handleResult(err(selectorNotFound(selector)));
          }
    
          screenshotData = await element.screenshot({
            type: imageFormat,
            quality: imageFormat === 'png' ? undefined : (quality ?? 100),
          });
        } else {
          // Screenshot page/viewport
          screenshotData = await page.screenshot({
            fullPage: fullPage ?? false,
            type: imageFormat,
            quality: imageFormat === 'png' ? undefined : (quality ?? 100),
          });
        }
    
        const base64Data = Buffer.from(screenshotData).toString('base64');
        const mimeType = imageFormat === 'png' ? 'image/png'
          : imageFormat === 'jpeg' ? 'image/jpeg'
          : 'image/webp';
    
        // Return as image content block for efficient processing by Claude
        return {
          content: [
            {
              type: 'image' as const,
              data: base64Data,
              mimeType,
            },
          ],
        };
      } catch (error) {
        return handleResult(err(normalizeError(error)));
      }
    }
  • Zod schema for validating input parameters to the screenshot tool, including options for fullPage, selector, format, quality, dimensions, and tabId.
    export const screenshotSchema = z.object({
      fullPage: z.boolean().optional().default(false).describe('Capture full scrollable page'),
      selector: z.string().optional().describe('Element to screenshot (screenshots viewport if not specified)'),
      format: z.enum(['png', 'jpeg', 'webp']).optional().default('png'),
      quality: z.number().int().min(0).max(100).optional().describe('Image quality (jpeg/webp only)'),
      width: z.number().int().min(200).max(4000).optional().describe('Viewport width in pixels (default 1024)'),
      height: z.number().int().min(200).max(4000).optional().describe('Viewport height in pixels (default 768)'),
      scale: z.number().min(0.5).max(3).optional().describe('Device scale factor (default 1, use 2 for retina)'),
      tabId: tabIdSchema,
    });
  • Registers the 'screenshot' tool on the MCP server using server.tool, providing name, description, input schema, and the handler function.
    server.tool(
      'screenshot',
      'Capture a screenshot of the page or a specific element',
      screenshotSchema.shape,
      async ({ fullPage, selector, format, quality, width, height, scale, tabId }) => {
        const pageResult = await getPageForOperation(tabId);
        if (!pageResult.success) {
          return handleResult(pageResult);
        }
    
        const page = pageResult.data;
        const imageFormat = (format ?? 'png') as ScreenshotFormat;
    
        // Set viewport with sensible defaults for reasonable image sizes
        const viewportWidth = width ?? 1024;
        const viewportHeight = height ?? 768;
        const deviceScaleFactor = scale ?? 1;
    
        try {
          // Set viewport before screenshot to control resolution
          await page.setViewport({
            width: viewportWidth,
            height: viewportHeight,
            deviceScaleFactor,
          });
    
          let screenshotData: Uint8Array;
    
          if (selector) {
            // Screenshot specific element
            const element = await page.$(selector);
    
            if (!element) {
              return handleResult(err(selectorNotFound(selector)));
            }
    
            screenshotData = await element.screenshot({
              type: imageFormat,
              quality: imageFormat === 'png' ? undefined : (quality ?? 100),
            });
          } else {
            // Screenshot page/viewport
            screenshotData = await page.screenshot({
              fullPage: fullPage ?? false,
              type: imageFormat,
              quality: imageFormat === 'png' ? undefined : (quality ?? 100),
            });
          }
    
          const base64Data = Buffer.from(screenshotData).toString('base64');
          const mimeType = imageFormat === 'png' ? 'image/png'
            : imageFormat === 'jpeg' ? 'image/jpeg'
            : 'image/webp';
    
          // Return as image content block for efficient processing by Claude
          return {
            content: [
              {
                type: 'image' as const,
                data: base64Data,
                mimeType,
              },
            ],
          };
        } catch (error) {
          return handleResult(err(normalizeError(error)));
        }
      }
    );
  • src/server.ts:27-27 (registration)
    Invokes registerMediaTools during server setup, which in turn registers the screenshot tool among media tools.
    registerMediaTools(server);
  • Type definition for supported screenshot formats used in the handler.
    export type ScreenshotFormat = 'png' | 'jpeg' | 'webp';
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral disclosure. It mentions capturing 'page or a specific element' but doesn't describe what happens (e.g., returns image data, saves to file, requires permissions, has visual rendering delays, or affects browser state). For a tool with 8 parameters and no annotation coverage, this leaves significant behavioral unknowns.

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 a single, efficient sentence that immediately communicates the core function. Every word earns its place with no redundancy or unnecessary elaboration. It's perfectly front-loaded with the essential information.

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?

For a complex screenshot tool with 8 parameters, no annotations, and no output schema, the description is insufficiently complete. It doesn't explain what the tool returns (image data format, file location, etc.), performance characteristics, error conditions, or how it interacts with the browser context. The agent lacks crucial information to use this tool effectively.

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 high at 88%, providing good documentation for most parameters. The description adds minimal value beyond the schema - it hints at the 'selector' parameter's behavior ('screenshots viewport if not specified') but this is already covered in the schema. With high schema coverage, the baseline of 3 is appropriate as 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.

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 a screenshot') and the target ('page or a specific element'), distinguishing it from all sibling tools which perform different browser automation functions like navigation, interaction, or content extraction. It uses precise language that immediately communicates the tool's function.

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?

The description implies usage context (when you need visual capture of a webpage or element) but provides no explicit guidance on when to choose this over alternatives like 'pdf' (which captures as PDF) or 'get_content' (which extracts text/HTML). There's no mention of prerequisites or limitations, leaving the agent to infer appropriate usage scenarios.

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/andytango/puppeteer-mcp'

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