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}`, }; } }