Skip to main content
Glama
omgwtfwow

MCP Server for Crawl4AI

by omgwtfwow

generate_pdf

Convert webpages to PDF files by providing a URL. This tool captures webpage content and returns base64-encoded PDF data for easy download and sharing.

Instructions

[STATELESS] Convert webpage to PDF. Returns base64-encoded PDF data. Creates new browser each time. Cannot capture form fills or JS changes. For persistent PDFs use create_session + crawl(session_id, pdf:true).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesThe URL to convert to PDF

Implementation Reference

  • The primary handler function for the generate_pdf tool. It calls the underlying service to generate the PDF, validates the response, and formats it as an MCP resource (base64 PDF blob with URI and accompanying text).
    async generatePDF(options: PDFEndpointOptions) { try { const result: PDFEndpointResponse = await this.service.generatePDF(options); // Response has { success: true, pdf: "base64string" } if (!result.success || !result.pdf) { throw new Error('PDF generation failed - no PDF data in response'); } return { content: [ { type: 'resource', resource: { uri: `data:application/pdf;name=${encodeURIComponent(new URL(String(options.url)).hostname)}.pdf;base64,${result.pdf}`, mimeType: 'application/pdf', blob: result.pdf, }, }, { type: 'text', text: `PDF generated for: ${options.url}`, }, ], }; } catch (error) { throw this.formatError(error, 'generate PDF'); } }
  • src/server.ts:837-840 (registration)
    Tool dispatch registration in the MCP server request handler switch statement. Validates input with GeneratePdfSchema and delegates to ContentHandlers.generatePDF.
    case 'generate_pdf': return await this.validateAndExecute('generate_pdf', args, GeneratePdfSchema, async (validatedArgs) => this.contentHandlers.generatePDF(validatedArgs), );
  • Zod schema for validating generate_pdf tool inputs (requires URL).
    export const GeneratePdfSchema = createStatelessSchema( z.object({ url: z.string().url(), // Only url is supported - output_path not exposed as MCP needs base64 data }), 'generate_pdf', );
  • src/server.ts:176-189 (registration)
    Tool metadata registration in the MCP list_tools response, including name, description, and input schema definition.
    name: 'generate_pdf', description: '[STATELESS] Convert webpage to PDF. Returns base64-encoded PDF data. Creates new browser each time. Cannot capture form fills or JS changes. For persistent PDFs use create_session + crawl(session_id, pdf:true).', inputSchema: { type: 'object', properties: { url: { type: 'string', description: 'The URL to convert to PDF', }, }, required: ['url'], }, },
  • Underlying service method that makes the HTTP POST request to the Crawl4AI /pdf endpoint to generate the PDF base64 data.
    async generatePDF(options: PDFEndpointOptions): Promise<PDFEndpointResponse> { // Validate URL if (!validateURL(options.url)) { throw new Error('Invalid URL format'); } try { const response = await this.axiosClient.post('/pdf', { url: options.url, // output_path is omitted to get base64 response }); return response.data; } catch (error) { return handleAxiosError(error); } }

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/omgwtfwow/mcp-crawl4ai-ts'

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