convert-to-pdf
Convert files from URLs or base64 encoding to PDF format for standardized document sharing and archiving.
Instructions
Convert various file formats to PDF.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| inputMethod | Yes | Input method | |
| file | Yes | URL or base64-encoded file content |
Implementation Reference
- src/index.ts:555-570 (handler)The asynchronous handler function that executes the 'convert-to-pdf' tool logic by making a POST request to an external API endpoint with the provided parameters.async ({ inputMethod, file }) => { const apiKey = process.env.DUMPLING_API_KEY; if (!apiKey) throw new Error("DUMPLING_API_KEY not set"); const response = await fetch(`${NWS_API_BASE}/api/v1/convert-to-pdf`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}`, }, body: JSON.stringify({ inputMethod, file }), }); if (!response.ok) throw new Error(`Failed: ${response.status} ${await response.text()}`); const data = await response.json(); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; }
- src/index.ts:551-554 (schema)Zod schema for input validation: inputMethod as 'url' or 'base64', and file as a string containing the URL or base64 content.{ inputMethod: z.enum(["url", "base64"]).describe("Input method"), file: z.string().describe("URL or base64-encoded file content"), },
- src/index.ts:548-571 (registration)The server.tool() registration that defines the tool name, description, input schema, and handler function.server.tool( "convert-to-pdf", "Convert various file formats to PDF.", { inputMethod: z.enum(["url", "base64"]).describe("Input method"), file: z.string().describe("URL or base64-encoded file content"), }, async ({ inputMethod, file }) => { const apiKey = process.env.DUMPLING_API_KEY; if (!apiKey) throw new Error("DUMPLING_API_KEY not set"); const response = await fetch(`${NWS_API_BASE}/api/v1/convert-to-pdf`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}`, }, body: JSON.stringify({ inputMethod, file }), }); if (!response.ok) throw new Error(`Failed: ${response.status} ${await response.text()}`); const data = await response.json(); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; } );