plan_conversion
Generate optimal conversion plans for document format changes, ensuring proper workflow and handling complex multi-step transformations between PDF, DOCX, HTML, and Markdown formats.
Instructions
๐ฏ MANDATORY FIRST STEP - Smart Document Conversion Planner - โ ๏ธ CRITICAL: This tool MUST be executed BEFORE any document conversion operation! When users request any format conversion (e.g., 'convert MD to PDF', 'DOCX to HTML'), you MUST call this tool first to get the optimal conversion plan, then follow the plan's steps exactly. This ensures proper conversion workflow and handles complex multi-step conversions. For PDF conversions, note that playwright-mcp integration is required for final PDF generation, followed by process_pdf_post_conversion for watermarks/QR codes. Supports all format conversion path planning.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sourceFormat | Yes | Source file format (e.g.: pdf, docx, html, markdown, md, txt) | |
| targetFormat | Yes | Target file format (e.g.: pdf, docx, html, markdown, md, txt) | |
| sourceFile | No | Source file path (optional, used to generate specific conversion parameters) | |
| preserveStyles | No | Whether to preserve style formatting | |
| includeImages | No | Whether to include images | |
| theme | No | Conversion theme (applicable to HTML/DOCX output) | github |
| quality | No | Conversion quality requirements | balanced |
Implementation Reference
- src/tools/conversionPlanner.ts:6-40 (schema)Input schema (ConversionRequest) and output schema (ConversionPlan) with supporting types for the plan_conversion tool.interface ConversionRequest { sourceFormat: string; targetFormat: string; sourceFile?: string; requirements?: { preserveStyles?: boolean; includeImages?: boolean; theme?: string; quality?: 'fast' | 'balanced' | 'high'; }; } interface ConversionStep { stepNumber: number; toolName: string; description: string; inputFormat: string; outputFormat: string; parameters: Record<string, any>; estimatedTime: string; notes?: string; } interface ConversionPlan { success: boolean; sourceFormat: string; targetFormat: string; conversionPath: string[]; steps: ConversionStep[]; totalSteps: number; estimatedTotalTime: string; recommendations: string[]; warnings?: string[]; error?: string; }
- src/tools/conversionPlanner.ts:111-215 (handler)The handler function that executes the plan_conversion tool logic, planning document format conversion paths using heuristics and predefined mappings.async planConversion(request: ConversionRequest): Promise<ConversionPlan> { try { const sourceFormat = this.normalizeFormat(request.sourceFormat); const targetFormat = this.normalizeFormat(request.targetFormat); // ้ช่ฏๆ ผๅผๆฏๆ if (!this.isFormatSupported(sourceFormat)) { return { success: false, sourceFormat, targetFormat, conversionPath: [], steps: [], totalSteps: 0, estimatedTotalTime: '0ๅ้', recommendations: [], error: `ไธๆฏๆ็ๆบๆ ผๅผ: ${sourceFormat}`, }; } if (!this.isFormatSupported(targetFormat)) { return { success: false, sourceFormat, targetFormat, conversionPath: [], steps: [], totalSteps: 0, estimatedTotalTime: '0ๅ้', recommendations: [], error: `ไธๆฏๆ็็ฎๆ ๆ ผๅผ: ${targetFormat}`, }; } // ็ธๅๆ ผๅผ if (sourceFormat === targetFormat) { return { success: true, sourceFormat, targetFormat, conversionPath: [sourceFormat], steps: [ { stepNumber: 1, toolName: 'read_document', description: 'ๆไปถๅทฒ็ปๆฏ็ฎๆ ๆ ผๅผ๏ผๆ ้่ฝฌๆข', inputFormat: sourceFormat, outputFormat: targetFormat, parameters: {}, estimatedTime: 'ๅณๆถ', }, ], totalSteps: 1, estimatedTotalTime: 'ๅณๆถ', recommendations: ['ๆไปถๆ ผๅผๅทฒๅน้ ๏ผๆ ้่ฝฌๆข'], }; } // ๆฅๆพ่ฝฌๆข่ทฏๅพ const conversionPath = this.findConversionPath(sourceFormat, targetFormat); if (!conversionPath || conversionPath.length === 0) { return { success: false, sourceFormat, targetFormat, conversionPath: [], steps: [], totalSteps: 0, estimatedTotalTime: '0ๅ้', recommendations: [], error: `ๆ ๆณๆพๅฐไป ${sourceFormat} ๅฐ ${targetFormat} ็่ฝฌๆข่ทฏๅพ`, }; } // ็ๆ่ฝฌๆขๆญฅ้ชค const steps = this.generateConversionSteps(conversionPath, request); const totalTime = this.calculateTotalTime(steps); const recommendations = this.generateRecommendations(sourceFormat, targetFormat, request); const warnings = this.generateWarnings(sourceFormat, targetFormat, conversionPath); return { success: true, sourceFormat, targetFormat, conversionPath, steps, totalSteps: steps.length, estimatedTotalTime: totalTime, recommendations, warnings, }; } catch (error: any) { return { success: false, sourceFormat: request.sourceFormat, targetFormat: request.targetFormat, conversionPath: [], steps: [], totalSteps: 0, estimatedTotalTime: '0ๅ้', recommendations: [], error: `่งๅ่ฝฌๆข่ทฏๅพๆถๅบ้: ${error.message}`, }; } }