Skip to main content
Glama
cablate

Simple Document Processing MCP Server

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
NameRequiredDescriptionDefault
inputPathYesPath to the input DOCX file
outputPathYesPath where the output PDF file should be saved

Implementation Reference

  • 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", }; } }
  • 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"], }, };
  • TypeScript interface defining the input arguments for the docx_to_pdf tool.
    export interface DocxToPdfArgs { inputPath: string; outputPath: string; }
  • 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, }; }

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/cablate/mcp-doc-forge'

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