Skip to main content
Glama

take_screenshot

Capture browser screenshots as base64 PNG images for visual feedback during web automation. Supports viewport, full-page, or element-specific captures to analyze displayed content before interacting with buttons or forms.

Instructions

Capture a screenshot of the current browser page as a base64-encoded PNG image. Essential for visual feedback to understand what's displayed before deciding which buttons to click or forms to fill. Supports capturing the visible viewport, entire scrollable page, or specific elements. Returns the image as base64 string and data URL for easy display.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionIdYesSession ID obtained from initialize_session
fullPageNoCapture the entire scrollable page content (true) or just visible viewport (false). Use true for long pages (default: false)
selectorNoOptional CSS selector to capture only a specific element (e.g., '.chat-container', '#main-content')

Implementation Reference

  • Core implementation of the take_screenshot tool. Captures screenshot of the full page or specific element using Puppeteer and returns base64 encoded image.
    export async function takeScreenshot( sessionId, fullPage = false, selector = null ) { const session = getSession(sessionId); const { page } = session; let screenshotBuffer; if (selector) { const element = await page.$(selector); if (!element) { throw new Error(`Element with selector "${selector}" not found`); } screenshotBuffer = await element.screenshot(); } else { screenshotBuffer = await page.screenshot({ fullPage }); } const base64Image = screenshotBuffer.toString("base64"); return { success: true, sessionId, currentUrl: page.url(), title: await page.title(), screenshotBase64: base64Image, screenshotDataUrl: `data:image/png;base64,${base64Image}`, message: "Screenshot captured successfully", }; }
  • Defines the tool name, description, and input schema for validation in the MCP ListTools response.
    { name: "take_screenshot", description: "Capture a screenshot of the current browser page as a base64-encoded PNG image. Essential for visual feedback to understand what's displayed before deciding which buttons to click or forms to fill. Supports capturing the visible viewport, entire scrollable page, or specific elements. Returns the image as base64 string and data URL for easy display.", inputSchema: { type: "object", properties: { sessionId: { type: "string", description: "Session ID obtained from initialize_session", }, fullPage: { type: "boolean", description: "Capture the entire scrollable page content (true) or just visible viewport (false). Use true for long pages (default: false)", default: false, }, selector: { type: "string", description: "Optional CSS selector to capture only a specific element (e.g., '.chat-container', '#main-content')", }, }, required: ["sessionId"], },
  • src/index.js:429-438 (registration)
    Registers and dispatches the take_screenshot tool call in the MCP CallToolRequest handler by invoking the takeScreenshot function.
    case "take_screenshot": { const { sessionId, fullPage = false, selector } = args; if (!sessionId) { throw new McpError( ErrorCode.InvalidParams, "sessionId parameter is required" ); } result = await takeScreenshot(sessionId, fullPage, selector); break;
  • Re-exports the takeScreenshot function for centralized import in the main index.js file.
    export { takeScreenshot, getCurrentPageInfo } from "./visualInspection.js";
  • Imports the getSession helper function used by takeScreenshot to retrieve the browser session.
    import { getSession } from "./sessionManagement.js";

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/pyscout/webscout-mcp'

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