Skip to main content
Glama

puppeteer

Automate browser tasks by launching browsers, opening pages, executing JavaScript, and capturing screenshots for web scraping, testing, and debugging.

Instructions

Control browsers and pages with Puppeteer - launch/close browsers, open/close pages, execute JavaScript, take screenshots, and more

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesThe action to perform with Puppeteer

Implementation Reference

  • The main execution handler for the 'puppeteer' tool. It uses a switch statement on the action type to delegate to specific Puppeteer utility functions.
    export default async function puppeteer({ action }: InferSchema<typeof schema>) {
      try {
        switch (action.type) {
          // Browser actions
          case "list-browsers":
            return await listBrowsers()
    
          case "launch-browser":
            return await launchBrowser(action.headless, action.width, action.height, action.url)
    
          case "close-browser":
            return await closeBrowser(action.browserId)
    
          // Page actions
          case "list-pages":
            return await listPages()
    
          case "open-page":
            return await openPage(action.browserId, action.url)
    
          case "close-page":
            return await closePage(action.pageId)
    
          // Exec action
          case "exec-page":
            return await execPage(action.pageId, action.source)
    
          // Screenshot action
          case "take-screenshot":
            return await takeScreenshot(action.pageId, action.fullPage, action.format, action.quality)
    
          default:
            return JSON.stringify({
              success: false,
              error: "Invalid action type",
            }, null, 2)
        }
      } catch (error) {
        return JSON.stringify({
          success: false,
          error: error instanceof Error ? error.message : "Unknown error occurred",
        }, null, 2)
      }
    }
  • Zod schema defining the input parameters for the puppeteer tool using a discriminated union based on 'action.type'.
    export const schema = {
      action: z.discriminatedUnion("type", [
        // Browser actions
        z.object({
          type: z.literal("list-browsers"),
        }),
        z.object({
          type: z.literal("launch-browser"),
          headless: z.boolean()
            .optional()
            .default(false)
            .describe("Whether to run browser in headless mode. Defaults to false"),
          width: z.number()
            .optional()
            .default(1280)
            .describe("Browser window width in pixels. Defaults to 1280"),
          height: z.number()
            .optional()
            .default(720)
            .describe("Browser window height in pixels. Defaults to 720"),
          url: z.string()
            .optional()
            .describe("Optional URL to navigate to after launching the browser"),
        }),
        z.object({
          type: z.literal("close-browser"),
          browserId: z.string().describe("The ID of the browser instance to close"),
        }),
        // Page actions
        z.object({
          type: z.literal("list-pages"),
        }),
        z.object({
          type: z.literal("open-page"),
          browserId: z.string().describe("The ID of the browser instance to create a page in"),
          url: z.string().optional().describe("Optional URL to navigate to after creating the page"),
        }),
        z.object({
          type: z.literal("close-page"),
          pageId: z.string().describe("The ID of the page to close"),
        }),
        // Exec action
        z.object({
          type: z.literal("exec-page"),
          pageId: z.string()
            .describe("The ID of the page to execute code on"),
          source: z.string()
            .describe("JavaScript code to execute. Will be executed outside of the page context. You can run commands like await page.goto('https://example.com') or await page.evaluate(() => { ... }). The code you write should return a string value that will serve as the result of the tool call."),
        }),
        // Screenshot action
        z.object({
          type: z.literal("take-screenshot"),
          pageId: z.string()
            .describe("The ID of the page to take a screenshot of"),
          fullPage: z.boolean()
            .optional()
            .default(false)
            .describe("Whether to take a screenshot of the full scrollable page. Defaults to false"),
          format: z.enum(["png", "jpeg"])
            .optional()
            .default("png")
            .describe("Image format for the screenshot. Defaults to png"),
          quality: z.number()
            .min(0)
            .max(100)
            .optional()
            .describe("Quality of the screenshot, only applicable for jpeg format (0-100)"),
        }),
      ]).describe("The action to perform with Puppeteer"),
    }
  • Tool metadata that registers the tool with name 'puppeteer', description, and annotations for the MCP framework.
    export const metadata: ToolMetadata = {
      name: "puppeteer",
      description: "Control browsers and pages with Puppeteer - launch/close browsers, open/close pages, execute JavaScript, take screenshots, and more",
      annotations: {
        title: "Puppeteer Control",
        readOnlyHint: false,
        destructiveHint: false,
        idempotentHint: false,
      },
    }
Behavior3/5

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

Annotations provide basic hints (readOnlyHint=false, destructiveHint=false, idempotentHint=false), but the description adds context about browser/page lifecycle management and JavaScript execution. However, it lacks details on error handling, performance implications, resource cleanup, or authentication needs. No contradiction with annotations exists, as 'control' aligns with non-read-only operations.

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 front-loads the core purpose ('Control browsers and pages with Puppeteer') followed by a concise list of key actions. Every word earns its place, with no redundancy or unnecessary elaboration, making it easy for an agent to quickly grasp the tool's scope.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complex input schema (multiple action types) and lack of output schema, the description provides a high-level overview but lacks details on return values, error conditions, or advanced usage patterns. It's adequate for basic orientation but incomplete for guiding an agent through the full range of actions and their outcomes.

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 100%, with detailed parameter documentation in the schema itself. The description mentions general action categories but adds no specific parameter semantics beyond what's in the schema. This meets the baseline for high schema coverage, where the description doesn't need to compensate but also doesn't enhance parameter understanding.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose as 'Control browsers and pages with Puppeteer' and lists specific actions (launch/close browsers, open/close pages, execute JavaScript, take screenshots). It distinguishes from sibling tools like fetch, get-rules, graphql, and socket by focusing on browser automation. However, it doesn't explicitly differentiate from potential similar browser tools that might exist elsewhere.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. While it lists actions, it doesn't specify prerequisites (e.g., need to launch a browser before opening pages), sequencing requirements, or when to choose Puppeteer over other tools like fetch for web interactions. The agent must infer usage from the action list alone.

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/matiasngf/mcp-fetch'

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