Skip to main content
Glama

generate_pdf

Convert web pages or HTML content into PDF documents using browser automation. Specify URL or HTML with options for headers, formatting, and margins.

Instructions

Generate PDF from URL or HTML content

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes
htmlNo
optionsNo

Implementation Reference

  • Core handler function that executes the PDF generation logic by sending an HTTP POST request to the Browserless /pdf endpoint and returning the PDF buffer.
    async generatePdf(request: PdfRequest): Promise<BrowserlessResponse<PdfResponse>> {
      try {
        const response: AxiosResponse<Buffer> = await this.httpClient.post('/pdf', request, {
          responseType: 'arraybuffer',
          headers: {
            'Content-Type': 'application/json',
          },
        });
    
        return {
          success: true,
          data: {
            pdf: Buffer.from(response.data),
            filename: `document-${Date.now()}.pdf`,
          },
        };
      } catch (error) {
        return this.handleError(error);
      }
    }
  • Zod schema definition for PdfRequest input validation, including options for PDF generation.
    export const PdfRequestSchema = z.object({
      url: z.string().optional(),
      html: z.string().optional(),
      options: PdfOptionsSchema.optional(),
      addScriptTag: z.array(ScriptTagSchema).optional(),
      addStyleTag: z.array(StyleTagSchema).optional(),
      cookies: z.array(CookieSchema).optional(),
      headers: z.record(z.string()).optional(),
      viewport: ViewportSchema.optional(),
      waitForEvent: WaitForEventSchema.optional(),
      waitForFunction: WaitForFunctionSchema.optional(),
      waitForSelector: WaitForSelectorSchema.optional(),
      waitForTimeout: z.number().optional(),
    });
    
    export type PdfRequest = z.infer<typeof PdfRequestSchema>;
  • src/index.ts:51-79 (registration)
    MCP tool registration for 'generate_pdf', including description and input schema.
    {
      name: 'generate_pdf',
      description: 'Generate PDF from URL or HTML content',
      inputSchema: {
        type: 'object',
        properties: {
          url: { type: 'string' },
          html: { type: 'string' },
          options: {
            type: 'object',
            properties: {
              displayHeaderFooter: { type: 'boolean' },
              printBackground: { type: 'boolean' },
              format: { type: 'string' },
              landscape: { type: 'boolean' },
              margin: {
                type: 'object',
                properties: {
                  top: { type: 'string' },
                  bottom: { type: 'string' },
                  left: { type: 'string' },
                  right: { type: 'string' },
                },
              },
            },
          },
        },
        required: ['url'],
      },
  • Server-side MCP CallTool handler for generate_pdf, which delegates to client.generatePdf and formats the response as MCP content.
    case 'generate_pdf': {
      const result = await this.client!.generatePdf(args as any);
      if (result.success && result.data) {
        return {
          content: [
            {
              type: 'text',
              text: `PDF generated successfully. Filename: ${result.data.filename}`,
            },
            {
              type: 'binary',
              mimeType: 'application/pdf',
              data: result.data.pdf.toString('base64'),
            },
          ],
        };
      } else {
        throw new Error(result.error || 'Failed to generate PDF');
      }
    }
  • TypeScript interface for the PDF response containing the buffer and filename.
    export interface PdfResponse {
      pdf: Buffer;
      filename: string;
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states what the tool does but doesn't describe any behavioral traits such as performance characteristics, error handling, authentication requirements, rate limits, or what happens when both 'url' and 'html' parameters are provided. For a tool with 3 parameters and no annotation coverage, this is a significant gap.

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 extremely concise at just 6 words, front-loading the core functionality with zero wasted words. Every word earns its place by specifying the action, output format, and input sources.

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?

Given the tool's complexity (3 parameters with nested objects, no output schema, and no annotations), the description is incomplete. It doesn't explain the relationship between 'url' and 'html' parameters, the purpose of the 'options' object, expected output format, or error conditions. The agent lacks sufficient context to use this tool effectively.

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?

Schema description coverage is 0%, so the description must compensate by explaining parameters. It mentions 'URL or HTML content', which hints at the 'url' and 'html' parameters, but doesn't explain the 'options' parameter or its nested properties. With 3 parameters (one complex nested object) and no schema descriptions, the description adds minimal value beyond what the bare schema provides.

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: 'Generate PDF from URL or HTML content'. It specifies the verb ('Generate') and resource ('PDF'), and indicates the input sources ('URL or HTML content'). However, it doesn't distinguish this from sibling tools like 'export_page' or 'take_screenshot' which might have similar functionality, preventing a perfect score.

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. It doesn't mention any prerequisites, constraints, or comparison with sibling tools like 'export_page' or 'take_screenshot'. The agent must infer usage from the tool name and parameters 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/Lizzard-Solutions/browserless-mcp'

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