Skip to main content
Glama
kbyk004-diy

Playwright-Lighthouse MCP Server

by kbyk004-diy

take-screenshot

Capture screenshots of web pages for performance analysis, supporting full-page captures to document website appearance during testing.

Instructions

Takes a screenshot of the currently open page

Input Schema

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

Implementation Reference

  • The handler function that executes the take-screenshot tool. It navigates to the given URL, takes a JPEG screenshot (full page if specified), saves it to the screenshots directory, closes the browser, and returns text messages with the save path and the base64-encoded image.
    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 URL string) and 'fullPage' (optional boolean, defaults to false).
    {
      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)
    Registers the 'take-screenshot' tool with the MCP server using server.tool(), specifying the name, description, input schema, and handler function.
    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,
          };
        }
      }
    );

Tool Description Quality Score

Score is being calculated. Check back soon.

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

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