screenshot
Capture web page screenshots by providing a URL, with options for full-page capture and viewport dimensions.
Instructions
Captura screenshot de uma página web
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | URL da página para capturar | |
| fullPage | No | Capturar página inteira ou apenas viewport | |
| width | No | Largura do viewport em pixels | |
| height | No | Altura do viewport em pixels |
Implementation Reference
- src/tools/screenshot.ts:18-54 (handler)Core handler function for the screenshot tool: launches headless Chromium via Playwright, navigates to the provided URL, captures a PNG screenshot (full page or viewport), encodes to base64, determines dimensions, and returns a structured result.export async function screenshot( params: ScreenshotParams ): Promise<ScreenshotResult> { const { url, fullPage = false, width = 1920, height = 1080 } = params; const browser = await chromium.launch({ headless: true }); const page = await browser.newPage({ userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", }); try { await page.setViewportSize({ width, height }); await page.goto(url, { waitUntil: "networkidle", timeout: 30000 }); await page.waitForTimeout(1000); const screenshotBuffer = await page.screenshot({ fullPage, type: "png", }); const dimensions = await page.evaluate(() => ({ width: document.documentElement.scrollWidth, height: document.documentElement.scrollHeight, })); return { url, base64: screenshotBuffer.toString("base64"), width: fullPage ? dimensions.width : width, height: fullPage ? dimensions.height : height, timestamp: new Date().toISOString(), }; } finally { await browser.close(); } }
- src/tools/screenshot.ts:3-16 (schema)TypeScript interfaces defining the input parameters (ScreenshotParams) and output structure (ScreenshotResult) for the screenshot tool.interface ScreenshotParams { url: string; fullPage?: boolean; width?: number; height?: number; } interface ScreenshotResult { url: string; base64: string; width: number; height: number; timestamp: string; }
- src/index.ts:115-134 (schema)Zod schema for input validation of the screenshot tool parameters, used in MCP server.tool registration.{ url: z .string() .url() .describe("URL da página para capturar"), fullPage: z .boolean() .default(false) .describe("Capturar página inteira ou apenas viewport"), width: z .number() .int() .default(1920) .describe("Largura do viewport em pixels"), height: z .number() .int() .default(1080) .describe("Altura do viewport em pixels"), },
- src/index.ts:112-147 (registration)MCP server registration of the 'screenshot' tool, including description, input schema, and wrapper handler that invokes the core screenshot function and returns MCP-formatted content (text description + base64 image).server.tool( "screenshot", "Captura screenshot de uma página web", { url: z .string() .url() .describe("URL da página para capturar"), fullPage: z .boolean() .default(false) .describe("Capturar página inteira ou apenas viewport"), width: z .number() .int() .default(1920) .describe("Largura do viewport em pixels"), height: z .number() .int() .default(1080) .describe("Altura do viewport em pixels"), }, async (params) => { const result = await screenshot(params); return { content: [ { type: "text", text: `Screenshot capturado: ${result.width}x${result.height}`, }, { type: "image", data: result.base64, mimeType: "image/png" }, ], }; } );