docx_to_pdf
Convert DOCX files to PDF format by specifying input and output file paths for document processing.
Instructions
Convert DOCX files to PDF format
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| inputPath | Yes | Path to the input DOCX file | |
| outputPath | Yes | Path where the output PDF file should be saved |
Implementation Reference
- src/tools/docxTools.ts:112-137 (handler)Core handler function that performs DOCX to PDF conversion using libreoffice-convert.export async function convertDocxToPdf(inputPath: string, outputPath: string) { try { const ext = path.extname(inputPath).toLowerCase(); if (ext !== ".docx") { throw new Error("Input file must be a .docx file"); } if (path.extname(outputPath).toLowerCase() !== ".pdf") { throw new Error("Output file must have .pdf extension"); } const docxBuffer = await fs.readFile(inputPath); const pdfBuffer = await convertAsyncPromise(docxBuffer, ".pdf", undefined); await fs.writeFile(outputPath, pdfBuffer); return { success: true, data: `Successfully converted ${inputPath} to ${outputPath}`, }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : "Unknown error", }; } }
- src/tools/docxTools.ts:35-52 (registration)MCP Tool object definition including name, description, and input schema for registration.export const DOCX_TO_PDF_TOOL: Tool = { name: "docx_to_pdf", description: "Convert DOCX files to PDF format", inputSchema: { type: "object", properties: { inputPath: { type: "string", description: "Path to the input DOCX file", }, outputPath: { type: "string", description: "Path where the output PDF file should be saved", }, }, required: ["inputPath", "outputPath"], }, };
- src/tools/docxTools.ts:53-56 (schema)TypeScript interface defining the input arguments for the docx_to_pdf tool.export interface DocxToPdfArgs { inputPath: string; outputPath: string; }
- src/tools/docxTools.ts:101-110 (helper)Type guard function to validate input arguments for docx_to_pdf tool.export function isDocxToPdfArgs(args: unknown): args is DocxToPdfArgs { return ( typeof args === "object" && args !== null && "inputPath" in args && "outputPath" in args && typeof (args as DocxToPdfArgs).inputPath === "string" && typeof (args as DocxToPdfArgs).outputPath === "string" ); }
- src/index.ts:77-93 (registration)Tool dispatch handler in the MCP server that validates arguments and calls the convertDocxToPdf function.if (name === "docx_to_pdf") { if (!isDocxToPdfArgs(args)) { throw new Error("Invalid arguments for docx_to_pdf"); } const result = await convertDocxToPdf(args.inputPath, args.outputPath); if (!result.success) { return { content: [{ type: "text", text: `Error: ${result.error}` }], isError: true, }; } return { content: [{ type: "text", text: fileOperationResponse(result.data) }], isError: false, }; }