export_analysis
Export Excel analysis results like pivot tables and statistics to a new file for sharing or further processing.
Instructions
Export analysis results (pivot tables, statistics, etc.) to a new file
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| analysisType | Yes | Type of analysis to export | |
| sourceFile | Yes | Path to the source data file | |
| outputFile | Yes | Path for the output file | |
| analysisParams | Yes | Parameters for the analysis (depends on analysisType) |
Implementation Reference
- src/handlers/file-operations.ts:240-290 (handler)The exportAnalysis method implements the core logic of the 'export_analysis' tool. It processes different analysis types (pivot_table, statistical_analysis), prepares tabular data, writes it to an output file using the internal writeFile method, and returns a success response with export details.async exportAnalysis(args: ToolArgs): Promise<ToolResponse> { const { analysisType, sourceFile, outputFile, analysisParams } = args; let exportData: any[][] = []; switch (analysisType) { case 'pivot_table': { // This would need to call the analytics handler - simplified for now exportData = [ ['Group', 'Value', 'Count'], // Results would go here ]; break; } case 'statistical_analysis': { exportData = [ ['Metric', 'Value'], ['Column', 'Sample Column'], // Statistical results would go here ]; break; } // Add other analysis types as needed default: throw new Error(`Unsupported analysis type: ${analysisType}`); } // Write the analysis results to file await this.writeFile({ filePath: outputFile, data: exportData.slice(1), // Remove headers headers: exportData[0] // Use first row as headers }); return { content: [ { type: 'text', text: JSON.stringify({ success: true, analysisType, sourceFile, outputFile, rowsExported: exportData.length, }, null, 2), }, ], }; }
- src/index.ts:696-721 (schema)The tool schema definition for 'export_analysis' including name, description, and detailed inputSchema specifying parameters like analysisType, sourceFile, outputFile, and analysisParams.name: 'export_analysis', description: 'Export analysis results (pivot tables, statistics, etc.) to a new file', inputSchema: { type: 'object', properties: { analysisType: { type: 'string', description: 'Type of analysis to export', enum: ['pivot_table', 'statistical_analysis', 'correlation', 'data_profile'], }, sourceFile: { type: 'string', description: 'Path to the source data file', }, outputFile: { type: 'string', description: 'Path for the output file', }, analysisParams: { type: 'object', description: 'Parameters for the analysis (depends on analysisType)', }, }, required: ['analysisType', 'sourceFile', 'outputFile', 'analysisParams'], }, },
- src/index.ts:1249-1251 (registration)Registration of the 'export_analysis' tool in the MCP server's CallToolRequestHandler switch statement, mapping the tool name to the FileOperationsHandler's exportAnalysis method.case 'export_analysis': return await this.fileOpsHandler.exportAnalysis(toolArgs); case 'format_cells':