Skip to main content
Glama

playwright_save_as_pdf

Convert web pages to PDF files with customizable formatting options including page size, margins, and background graphics.

Instructions

Save the current page as a PDF file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
outputPathYesDirectory path where PDF will be saved
filenameNoName of the PDF file (default: page.pdf)
formatNoPage format (e.g. 'A4', 'Letter')
printBackgroundNoWhether to print background graphics
marginNoPage margins

Implementation Reference

  • Implements the core logic: generates PDF options from args, calls page.pdf(), registers the saved PDF as an MCP resource, and returns a success response with the resource URI.
    async execute(args: any, context: ToolContext): Promise<ToolResponse> {
      return this.safeExecute(context, async (page) => {
        const filename = args.filename || "page.pdf";
        const options = {
          path: path.resolve(args.outputPath || ".", filename),
          format: args.format || "A4",
          printBackground: args.printBackground !== false,
          margin: args.margin || {
            top: "1cm",
            right: "1cm",
            bottom: "1cm",
            left: "1cm",
          },
        };
    
        await page.pdf(options);
        let resourceLink: Awaited<ReturnType<typeof registerFileResource>> | undefined;
        let savedLocation = options.path;
        try {
          resourceLink = await registerFileResource({
            filePath: options.path,
            name: filename,
            mimeType: "application/pdf",
            server: this.server,
          });
          if (resourceLink?.uri) {
            savedLocation = resourceLink.uri;
          }
        } catch (error) {
          console.warn("Failed to register PDF as resource:", error);
        }
        return {
          ...createSuccessResponse(`Saved page as PDF: ${savedLocation}`),
          ...(resourceLink ? { resourceLinks: [resourceLink] } : {}),
        };
      });
    }
  • Defines the tool name, description, and input schema for validation including required outputPath and optional PDF options.
      name: "playwright_save_as_pdf",
      description: "Save the current page as a PDF file",
      inputSchema: {
        type: "object",
        properties: {
          outputPath: { type: "string", description: "Directory path where PDF will be saved" },
          filename: { type: "string", description: "Name of the PDF file (default: page.pdf)" },
          format: { type: "string", description: "Page format (e.g. 'A4', 'Letter')" },
          printBackground: { type: "boolean", description: "Whether to print background graphics" },
          margin: {
            type: "object",
            description: "Page margins",
            properties: {
              top: { type: "string" },
              right: { type: "string" },
              bottom: { type: "string" },
              left: { type: "string" },
            },
          },
        },
        required: ["outputPath"],
      },
    },
  • Dispatches tool calls matching 'playwright_save_as_pdf' to the SaveAsPdfTool instance's execute method in the main handleToolCall switch statement.
    case "playwright_save_as_pdf":
      return await saveAsPdfTool.execute(args, context);
  • src/tools.ts:514-514 (registration)
    Includes the tool in BROWSER_TOOLS array, which determines when to ensure browser context is available before execution.
    "playwright_save_as_pdf",
  • Imports the SaveAsPdfTool class required for instantiation and execution.
    import { SaveAsPdfTool } from "./tools/browser/output.js";
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It mentions saving but doesn't disclose whether this is a read-only operation, if it modifies browser state, what happens on failure, or any performance implications. For a tool that creates files, this is insufficient.

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, clear sentence with zero wasted words. It's front-loaded with the core action and efficiently communicates the essential function without unnecessary elaboration.

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

Completeness2/5

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

For a tool with 5 parameters, no annotations, and no output schema, the description is inadequate. It doesn't explain what 'current page' means contextually, how the PDF is generated, error conditions, or return values. Given the complexity and lack of structured data, more completeness is needed.

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%, so the schema fully documents all 5 parameters. The description adds no additional parameter semantics beyond implying PDF generation from the current page. This meets the baseline for high schema coverage but doesn't enhance 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 action ('Save') and resource ('current page as a PDF file'), making the tool's function immediately understandable. However, it doesn't differentiate from sibling tools like 'playwright_screenshot' which also captures page content, missing an opportunity for clearer distinction.

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?

No guidance is provided on when to use this tool versus alternatives like 'playwright_screenshot' for image capture or other PDF-related operations. The description lacks context about prerequisites (e.g., requires a page to be loaded) or typical use cases.

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/aakashH242/mcp-playwright'

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