Skip to main content
Glama
ppt-reader.js10.3 kB
import * as fs from "fs"; import * as path from "path"; export const pptReader = { name: "read_presentation", description: "Read and extract content from PowerPoint presentations", parameters: { type: "object", properties: { file_path: { type: "string", description: "Path to the PowerPoint file to read" }, output_format: { type: "string", description: "Output format for the content", enum: ["text", "json", "markdown"], default: "text" }, slide_range: { type: "object", description: "Range of slides to read (optional)", properties: { start: { type: "number", description: "Start slide number (1-based)" }, end: { type: "number", description: "End slide number (1-based)" } } }, include_notes: { type: "boolean", description: "Whether to include speaker notes", default: false } }, required: ["file_path"] }, async run(args) { try { // Parameter validation if (!args.file_path) { throw new Error("File path is required"); } if (!fs.existsSync(args.file_path)) { throw new Error(`File not found: ${args.file_path}`); } // Note: PptxGenJS doesn't support reading existing PowerPoint files // This is a limitation of the library - it's primarily for creation, not reading // For reading PPT files, we'd need a different library like 'officegen' or 'node-pptx' const fileStats = fs.statSync(args.file_path); const fileName = path.basename(args.file_path); const fileSize = (fileStats.size / 1024).toFixed(2); // KB return { content: [{ type: "text", text: `⚠️ **Read Operation Not Fully Supported**\n\n` + `Unfortunately, PptxGenJS doesn't support reading existing PowerPoint files. ` + `This is a current limitation of the library.\n\n` + `**File Information:**\n` + `📄 **Name:** ${fileName}\n` + `📁 **Path:** ${args.file_path}\n` + `📊 **Size:** ${fileSize} KB\n` + `📅 **Modified:** ${fileStats.mtime.toLocaleString()}\n\n` + `**Alternative approaches:**\n` + `• Use Microsoft PowerPoint to view the content\n` + `• Convert to PDF and use PDF reading tools\n` + `• Use online PowerPoint viewers\n` + `• Consider using a different library like 'mammoth' for basic text extraction\n\n` + `**Requested format:** ${args.output_format || 'text'}\n` + `**Include notes:** ${args.include_notes ? 'Yes' : 'No'}` }] }; } catch (error) { return { content: [{ type: "text", text: `❌ **Failed to read presentation:** ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } }; export const pptAnalyzer = { name: "analyze_presentation", description: "Analyze PowerPoint presentation structure, content, and provide insights", parameters: { type: "object", properties: { file_path: { type: "string", description: "Path to the PowerPoint file to analyze" }, analysis_type: { type: "string", description: "Type of analysis to perform", enum: ["structure", "content", "statistics", "readability", "comprehensive"], default: "comprehensive" }, detailed: { type: "boolean", description: "Whether to provide detailed analysis", default: true } }, required: ["file_path"] }, async run(args) { try { // Parameter validation if (!args.file_path) { throw new Error("File path is required"); } if (!fs.existsSync(args.file_path)) { throw new Error(`File not found: ${args.file_path}`); } const analysisType = args.analysis_type || "comprehensive"; const detailed = args.detailed !== false; // Basic file analysis const fileStats = fs.statSync(args.file_path); const fileName = path.basename(args.file_path); const fileSize = (fileStats.size / 1024).toFixed(2); // KB const fileExtension = path.extname(args.file_path).toLowerCase(); // Validate file type if (!['.pptx', '.ppt'].includes(fileExtension)) { throw new Error(`Unsupported file type: ${fileExtension}. Only .pptx and .ppt files are supported.`); } // Generate mock analysis since we can't actually read the file content const analysis = generateMockAnalysis(fileName, fileSize, analysisType, detailed); return { content: [{ type: "text", text: `📊 **Presentation Analysis Report**\n\n` + `**File Information:**\n` + `📄 **Name:** ${fileName}\n` + `📁 **Path:** ${args.file_path}\n` + `📊 **Size:** ${fileSize} KB\n` + `📅 **Modified:** ${fileStats.mtime.toLocaleString()}\n` + `🔧 **Format:** ${fileExtension.toUpperCase()}\n\n` + `⚠️ **Note:** This is a basic file system analysis. ` + `For detailed content analysis, PptxGenJS doesn't support reading existing files.\n\n` + analysis }] }; } catch (error) { return { content: [{ type: "text", text: `❌ **Analysis failed:** ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } }; // Helper function to generate mock analysis function generateMockAnalysis(fileName, fileSize, analysisType, detailed) { let analysis = ""; switch (analysisType) { case "structure": analysis = `**📋 Structure Analysis:**\n` + `• File appears to be a valid PowerPoint presentation\n` + `• Size suggests ${estimateSlideCount(fileSize)} slides approximately\n` + `• Standard OOXML format detected\n`; break; case "content": analysis = `**📝 Content Analysis:**\n` + `• Content analysis requires reading file internals\n` + `• Current library limitation prevents detailed content extraction\n` + `• Recommend using PowerPoint or compatible viewer for content review\n`; break; case "statistics": analysis = `**📈 File Statistics:**\n` + `• File size: ${fileSize} KB\n` + `• Estimated complexity: ${getComplexityEstimate(fileSize)}\n` + `• Format compatibility: Modern PowerPoint (.pptx)\n`; break; case "readability": analysis = `**👁️ Readability Analysis:**\n` + `• Readability analysis requires text content extraction\n` + `• Cannot perform without reading slide content\n` + `• Recommend manual review for readability assessment\n`; break; default: // comprehensive analysis = `**🔍 Comprehensive Analysis:**\n\n` + `**File Properties:**\n` + `• Valid PowerPoint format: ✅\n` + `• File size: ${fileSize} KB\n` + `• Estimated slides: ${estimateSlideCount(fileSize)}\n` + `• Complexity level: ${getComplexityEstimate(fileSize)}\n\n` + `**Limitations:**\n` + `• Content extraction: ❌ (Library limitation)\n` + `• Text analysis: ❌ (Requires content access)\n` + `• Image detection: ❌ (Requires file parsing)\n` + `• Slide structure: ❌ (Requires OOXML parsing)\n\n` + `**Recommendations:**\n` + `• Use PowerPoint for detailed content review\n` + `• Consider converting to PDF for text extraction\n` + `• Use specialized PPT parsing libraries for advanced analysis\n`; break; } if (detailed) { analysis += `\n**🔧 Technical Details:**\n` + `• Library: PptxGenJS (Creation-focused)\n` + `• Reading capability: Limited\n` + `• Recommended alternatives: mammoth, officegen, or native PowerPoint API\n`; } return analysis; } // Helper functions function estimateSlideCount(fileSizeKB) { const size = parseFloat(fileSizeKB); if (size < 100) return "1-5"; if (size < 500) return "5-15"; if (size < 1000) return "15-30"; if (size < 2000) return "30-50"; return "50+"; } function getComplexityEstimate(fileSizeKB) { const size = parseFloat(fileSizeKB); if (size < 200) return "Low (mostly text)"; if (size < 1000) return "Medium (text + images)"; if (size < 3000) return "High (rich media)"; return "Very High (complex multimedia)"; } //# sourceMappingURL=ppt-reader.js.map

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/guangxiangdebizi/PPT-MCP'

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