Skip to main content
Glama
devskido

Playwright MCP Server

by devskido

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

  • Implementation of the SaveAsPdfTool class containing the execute method that saves the current Playwright page as a PDF file using page.pdf() with configurable options.
    export class SaveAsPdfTool extends BrowserToolBase {
      /**
       * Execute the save as PDF tool
       */
      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);
          return createSuccessResponse(`Saved page as PDF: ${options.path}`);
        });
      }
    } 
  • Tool schema definition including name, description, and input validation schema for the playwright_save_as_pdf tool.
    {
      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"],
      },
    },
  • Registration in the handleToolCall switch statement that routes calls to the SaveAsPdfTool's execute method.
    case "playwright_save_as_pdf":
      return await saveAsPdfTool.execute(args, context);
  • Instantiation of the SaveAsPdfTool instance during tool initialization.
    if (!saveAsPdfTool) saveAsPdfTool = new SaveAsPdfTool(server);
  • Import of the SaveAsPdfTool class.
    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 for behavioral disclosure. It mentions saving a PDF but doesn't describe important behaviors: whether this requires a page to be loaded first, if it works on all page states, what happens on failure, or if it modifies browser state. For a tool with potential side effects, 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 that immediately communicates the core function. There's no wasted verbiage or unnecessary elaboration. It's appropriately sized for a straightforward tool with well-documented parameters.

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 (including a nested object) and no annotations or output schema, the description is inadequate. It doesn't explain what 'current page' means contextually, doesn't mention prerequisites, and provides no information about return values or error conditions. The combination of complexity and lack of structured documentation requires more descriptive content.

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 parameters are well-documented in the schema. The description adds no additional parameter information beyond what's already in the schema descriptions. This meets the baseline for high schema coverage but doesn't provide extra context about parameter interactions or usage patterns.

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 purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'playwright_screenshot', which also captures page content but in image format rather than PDF.

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. For example, it doesn't mention when to choose PDF over screenshot formats or how it relates to other Playwright tools for page capture. The description only states what it does, not when it's appropriate.

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/devskido/customed-playwright'

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