Export PDF
pinchtab_pdfExport the current web page to a PDF file, returned as base64-encoded data. Capture page content in a portable format for sharing or archiving.
Instructions
Export the current page as a PDF. Returns the PDF as base64.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/content.ts:78-87 (handler)Handler for 'pinchtab_pdf' — sends a GET request to '/pdf' via the pinch client, returns the result as text content.
async () => { try { const result = await pinch("GET", "/pdf"); const text = typeof result === "string" ? result : toJson(result); return { content: [{ text, type: "text" as const }] }; } catch (error) { return toolError(error); } }, ); - src/tools/content.ts:71-87 (registration)Registration of the 'pinchtab_pdf' tool via server.registerTool with description and empty input schema.
server.registerTool( "pinchtab_pdf", { description: "Export the current page as a PDF. Returns the PDF as base64.", inputSchema: z.object({}), title: "Export PDF", }, async () => { try { const result = await pinch("GET", "/pdf"); const text = typeof result === "string" ? result : toJson(result); return { content: [{ text, type: "text" as const }] }; } catch (error) { return toolError(error); } }, ); - src/tools/content.ts:73-76 (schema)Schema/definition for 'pinchtab_pdf' — takes no input parameters, returns base64 PDF data.
{ description: "Export the current page as a PDF. Returns the PDF as base64.", inputSchema: z.object({}), title: "Export PDF", - src/pinchtab/client.ts:6-49 (helper)The 'pinch' helper function called by the handler — makes HTTP requests to the PinchTab server; the pdf handler calls pinch('GET', '/pdf').
export async function pinch( method: string, path: string, body?: Record<string, unknown>, ): Promise<unknown> { if (!(await isPinchtabRunning())) { await ensurePinchtabRunning(); } const headers: Record<string, string> = { "Content-Type": "application/json", }; if (PINCHTAB_TOKEN) { headers["Authorization"] = `Bearer ${PINCHTAB_TOKEN}`; } const url = `${PINCHTAB_URL}${path}`; let res: Response; try { res = await fetch(url, { body: body ? JSON.stringify(body) : undefined, headers, method, signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS), }); } catch (error) { if (error instanceof DOMException && error.name === "TimeoutError") { throw new Error(`PinchTab ${method} ${path} timed out after ${REQUEST_TIMEOUT_MS / 1000}s`); } throw error; } if (!res.ok) { const text = await res.text(); throw new Error(`PinchTab ${method} ${path} → ${res.status}: ${text}`); } const contentType = (res.headers.get("content-type") ?? "").split(";")[0].toLowerCase().trim(); if (contentType === "application/json") { return res.json(); } return res.text(); } - src/utils.ts:23-30 (helper)The toolError helper used in the catch block of the pdf handler to format errors as MCP tool error responses.
export function toolError(error: unknown): ToolResult { const message = error instanceof Error ? error.message : String(error); return { content: [{ text: message, type: "text" as const }], isError: true, }; }