Skip to main content
Glama
kbyk004-diy

Playwright-Lighthouse MCP Server

by kbyk004-diy

take-screenshot

Capture screenshots of web pages for any URL. Specify if full-page capture is needed. Supports website documentation, analysis, and testing.

Instructions

Takes a screenshot of the currently open page

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fullPageNoIf true, captures a screenshot of the entire page
urlYesURL of the website you want to capture

Implementation Reference

  • The handler function for the 'take-screenshot' tool. It navigates to the provided URL, captures a screenshot (full page optional), saves it to a file, and returns the image data along with file path.
    async ({ url, fullPage }) => { try { // Automatically launch browser and navigate to URL await navigateToUrl(url); const screenshot = await page!.screenshot({ fullPage, type: "jpeg", quality: 80 }); // Create directory for screenshots if it doesn't exist const screenshotsDir = path.join(__dirname, "../screenshots"); if (!existsSync(screenshotsDir)) { mkdirSync(screenshotsDir, { recursive: true }); } // Save screenshot const screenshotPath = path.join(screenshotsDir, `screenshot-${Date.now()}.jpg`); writeFileSync(screenshotPath, screenshot); // Close browser after taking screenshot await closeBrowser(); return { content: [ { type: "text" as const, text: `Screenshot captured. ${fullPage ? "(Full page)" : ""}`, }, { type: "text" as const, text: `Saved to: ${screenshotPath}`, }, { type: "image" as const, data: screenshot.toString("base64"), mimeType: "image/jpeg", }, ], }; } catch (error) { // Close browser even when an error occurs await closeBrowser(); return { content: [ { type: "text" as const, text: `An error occurred while taking screenshot: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } }
  • Zod schema defining the input parameters for the 'take-screenshot' tool: url (required string URL) and fullPage (optional boolean).
    url: z.string().url().describe("URL of the website you want to capture"), fullPage: z.boolean().default(false).describe("If true, captures a screenshot of the entire page"), },
  • src/index.ts:445-504 (registration)
    Registration of the 'take-screenshot' tool on the MCP server using server.tool(name, description, schema, handler).
    server.tool( "take-screenshot", "Takes a screenshot of the currently open page", { url: z.string().url().describe("URL of the website you want to capture"), fullPage: z.boolean().default(false).describe("If true, captures a screenshot of the entire page"), }, async ({ url, fullPage }) => { try { // Automatically launch browser and navigate to URL await navigateToUrl(url); const screenshot = await page!.screenshot({ fullPage, type: "jpeg", quality: 80 }); // Create directory for screenshots if it doesn't exist const screenshotsDir = path.join(__dirname, "../screenshots"); if (!existsSync(screenshotsDir)) { mkdirSync(screenshotsDir, { recursive: true }); } // Save screenshot const screenshotPath = path.join(screenshotsDir, `screenshot-${Date.now()}.jpg`); writeFileSync(screenshotPath, screenshot); // Close browser after taking screenshot await closeBrowser(); return { content: [ { type: "text" as const, text: `Screenshot captured. ${fullPage ? "(Full page)" : ""}`, }, { type: "text" as const, text: `Saved to: ${screenshotPath}`, }, { type: "image" as const, data: screenshot.toString("base64"), mimeType: "image/jpeg", }, ], }; } catch (error) { // Close browser even when an error occurs await closeBrowser(); return { content: [ { type: "text" as const, text: `An error occurred while taking screenshot: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } } );
  • Helper function used by the tool to launch browser if needed, get a page, and navigate to the specified URL.
    async function navigateToUrl(url: string) { try { const page = await getPage(); await page.goto(url, { waitUntil: "load" }); return page; } catch (error) { throw error; } }

Other Tools

Related 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/kbyk004-diy/playwright-lighthouse-mcp'

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