UNPKG

docxmcp

Version:

A Model Context Protocol (MCP) server for processing .docx files into markdown with image extraction

46 lines (38 loc) 1.51 kB
import { processDocx, cleanupImages } from './docx-processor.js'; export async function handler(params) { try { // Process the document - filePath is required if (!params || !params.filePath) { throw new Error('filePath parameter is required'); } const result = await processDocx(params.filePath); // Build response content with markdown and image references let responseContent = result.markdown; // Add image information to the response if (result.images && result.images.length > 0) { responseContent += '\n\n---\nExtracted Images:\n\n'; result.images.forEach((image, index) => { responseContent += `${index + 1}. ${image.filename} - Saved to: ${image.path}\n`; }); responseContent += '\n\nNote: The images have been extracted and saved to the paths above. '; responseContent += 'Claude/Goose can use the image_processor tool to view these images by providing the file paths.'; } // Don't clean up images immediately - let Claude/Goose process them first // Schedule cleanup for later if (result.images && result.images.length > 0) { setTimeout(() => { cleanupImages(result.images).catch(console.error); }, 300000); // Clean up after 5 minutes } return { content: [{ type: 'text', text: responseContent }], messages: result.messages }; } catch (error) { console.error('Handler error:', error); throw error; } }