Skip to main content
Glama
andytango
by andytango

pdf

Generate PDF documents from web pages with configurable format, orientation, margins, and background printing options.

Instructions

Generate a PDF of the current page

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatNoA4
landscapeNo
printBackgroundNo
marginNo
tabIdNoTab ID to operate on (uses active tab if not specified)

Implementation Reference

  • Full handler function for the 'pdf' tool. Generates a PDF of the page using Puppeteer page.pdf(), encodes it to base64, and returns it as PdfResult.
    server.tool(
      'pdf',
      'Generate a PDF of the current page',
      pdfSchema.shape,
      async ({ format, landscape, printBackground, margin, tabId }) => {
        const pageResult = await getPageForOperation(tabId);
        if (!pageResult.success) {
          return handleResult(pageResult);
        }
    
        const page = pageResult.data;
    
        try {
          const pdfData = await page.pdf({
            format: (format ?? 'A4') as PdfFormat,
            landscape: landscape ?? false,
            printBackground: printBackground ?? true,
            margin: margin ?? undefined,
          });
    
          const base64Data = Buffer.from(pdfData).toString('base64');
    
          return handleResult(ok({
            data: base64Data,
            size: pdfData.length,
          }));
        } catch (error) {
          return handleResult(err(normalizeError(error)));
        }
      }
    );
  • Zod schema defining input parameters for the pdf tool, including format, landscape, margins, etc.
    export const pdfSchema = z.object({
      format: z.enum(['Letter', 'Legal', 'Tabloid', 'Ledger', 'A0', 'A1', 'A2', 'A3', 'A4', 'A5', 'A6']).optional().default('A4'),
      landscape: z.boolean().optional().default(false),
      printBackground: z.boolean().optional().default(true),
      margin: z.object({
        top: z.string().optional(),
        right: z.string().optional(),
        bottom: z.string().optional(),
        left: z.string().optional(),
      }).optional(),
      tabId: tabIdSchema,
    });
  • TypeScript interface for the output of the pdf tool.
    export interface PdfResult {
      /** Base64-encoded PDF data */
      data: string;
    }
  • Type definition for PDF paper formats used in the pdf tool.
    export type PdfFormat = 'Letter' | 'Legal' | 'Tabloid' | 'Ledger' | 'A0' | 'A1' | 'A2' | 'A3' | 'A4' | 'A5' | 'A6';
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 states the action ('Generate a PDF') but doesn't describe what 'current page' means, whether this requires specific page states, what happens if generation fails, or any performance characteristics. The description provides minimal behavioral context beyond the basic action.

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 states the core functionality without unnecessary words. It's perfectly front-loaded with the essential information. Every word earns its place, making this an excellent example of conciseness.

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, nested objects, no annotations, and no output schema, the description is inadequate. It doesn't explain what 'current page' means in context of browser automation, doesn't describe the PDF generation process or output format, and provides no guidance on parameter usage. The description leaves too many open questions for effective tool invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With only 20% schema description coverage (only 'tabId' has a description), the description provides no information about any parameters. It doesn't mention format options, layout settings, or margin configurations that the schema reveals. The description fails to compensate for the low schema coverage, leaving most parameters undocumented.

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 ('Generate') and resource ('PDF of the current page'), making the purpose immediately understandable. It distinguishes from sibling tools like 'screenshot' by specifying PDF generation rather than image capture. However, it doesn't explicitly differentiate from all possible document generation tools, keeping it at a 4 rather than 5.

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 like 'screenshot' for visual captures or other document generation methods. It doesn't mention prerequisites (e.g., requires an active page/tab) or contextual constraints, leaving the agent to infer usage from the tool name 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/andytango/puppeteer-mcp'

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