UNPKG

mcp-gdrive-enhanced-markov

Version:

MCP server for Google Drive and Sheets with write capabilities, AI-powered PDF analysis, SQLite document indexing, and advanced directory exploration tools

209 lines (208 loc) 10.2 kB
export const schema = { name: "gdrive_search_guide", description: "Interactive guide to help users choose the best Google Drive search method based on their needs and current index status", inputSchema: { type: "object", properties: { intent: { type: "string", description: "What you want to find (e.g., 'business documents', 'contracts', 'financial reports', 'recent files')", }, checkIndex: { type: "boolean", description: "Check current indexing status and provide setup guidance (default: true)", optional: true, }, }, required: ["intent"], }, }; export async function gdrive_search_guide(args) { try { const intent = args.intent.toLowerCase(); const checkIndex = args.checkIndex !== false; let content = `# 🔍 Google Drive Search Guide\n\n`; content += `**Your Goal:** ${args.intent}\n\n`; // Analyze intent and provide recommendations const recommendations = analyzeSearchIntent(intent); content += `## 🎯 Recommended Approach\n\n`; content += `**Best Tool:** \`${recommendations.primaryTool}\`\n`; content += `**Why:** ${recommendations.reasoning}\n\n`; // Show the specific command to use content += `## 🚀 Quick Start Command\n\n`; content += `\`\`\`\n${recommendations.command}\`\`\`\n\n`; // Show alternative approaches if (recommendations.alternatives.length > 0) { content += `## 🔄 Alternative Options\n\n`; recommendations.alternatives.forEach((alt, index) => { content += `${index + 1}. **${alt.tool}** - ${alt.description}\n`; content += ` \`${alt.command}\`\n\n`; }); } // Index guidance if (checkIndex) { content += `---\n\n`; content += `## 📚 Enhanced Search with Indexing\n\n`; content += `**Current Status:** Unknown (use \`gdrive_search_indexed\` to test)\n\n`; content += `**Quick Index Setup:**\n`; content += `\`\`\`\n`; content += `gdrive_create_index\n`; content += `gdrive_index_smart\n`; content += `\`\`\`\n\n`; content += `**Benefits of Indexing:**\n`; content += `• 🧠 AI-powered content analysis and summaries\n`; content += `• 🏷️ Automatic document type classification\n`; content += `• 🎯 Relevance scoring for better results\n`; content += `• 🔍 Search inside document content, not just filenames\n`; content += `• 📊 Advanced filtering by document type and business context\n\n`; content += `**When to Use Each Tool:**\n\n`; content += `| Tool | Best For | Setup Required |\n`; content += `|------|----------|----------------|\n`; content += `| \`gdrive_find_documents\` | Quick file discovery, choosing specific versions | None |\n`; content += `| \`gdrive_search\` | Fast filename/basic content search | None |\n`; content += `| \`gdrive_search_indexed\` | Intelligent content search with AI summaries | Index setup |\n`; content += `| \`gdrive_search_advanced\` | Business document filtering (contracts, proposals) | Index setup |\n`; content += `| \`gdrive_intelligent_analysis\` | Automatic multi-document analysis | Index setup |\n\n`; } // Context-specific tips content += `## 💡 Pro Tips for "${args.intent}"\n\n`; content += generateContextualTips(intent); return { content: [{ type: "text", text: content }], isError: false }; } catch (error) { console.error('Error in gdrive_search_guide:', error); return { content: [{ type: "text", text: `Error generating search guide: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } function analyzeSearchIntent(intent) { // Business documents if (intent.includes('business') || intent.includes('plan') || intent.includes('strategy')) { return { primaryTool: 'gdrive_find_documents', reasoning: 'Perfect for discovering business documents with clear file selection options', command: 'gdrive_find_documents query:"business plan" fileType:"pdf" maxResults:5', alternatives: [ { tool: 'gdrive_search_indexed', description: 'If you want AI-powered content analysis (requires indexing)', command: 'gdrive_search_indexed query:"business plan" limit:5' } ] }; } // Contracts and legal if (intent.includes('contract') || intent.includes('legal') || intent.includes('agreement')) { return { primaryTool: 'gdrive_search_advanced', reasoning: 'Specialized for contract discovery with business context filtering', command: 'gdrive_search_advanced docType:"contract" limit:10', alternatives: [ { tool: 'gdrive_find_documents', description: 'For basic contract discovery without indexing', command: 'gdrive_find_documents query:"contract" fileType:"pdf"' } ] }; } // Financial documents if (intent.includes('financial') || intent.includes('budget') || intent.includes('money') || intent.includes('revenue')) { return { primaryTool: 'gdrive_find_documents', reasoning: 'Great for finding financial spreadsheets and reports with file type filtering', command: 'gdrive_find_documents query:"financial" fileType:"spreadsheet" maxResults:5', alternatives: [ { tool: 'gdrive_search_advanced', description: 'For indexed financial documents with AI analysis', command: 'gdrive_search_advanced query:"financial" limit:5' } ] }; } // Recent files if (intent.includes('recent') || intent.includes('latest') || intent.includes('new')) { return { primaryTool: 'gdrive_search', reasoning: 'Fast search with recent file ordering and date filtering', command: 'gdrive_search query:"*" modifiedAfter:"2025-06-01" pageSize:10', alternatives: [ { tool: 'gdrive_find_documents', description: 'For recent files with specific document types', command: 'gdrive_find_documents query:"" modifiedAfter:"2025-06-01"' } ] }; } // Specific file types if (intent.includes('pdf') || intent.includes('document') || intent.includes('spreadsheet')) { const fileType = intent.includes('pdf') ? 'pdf' : intent.includes('spreadsheet') ? 'spreadsheet' : 'document'; return { primaryTool: 'gdrive_find_documents', reasoning: `Optimized for discovering and selecting specific ${fileType} files`, command: `gdrive_find_documents query:"" fileType:"${fileType}" maxResults:10`, alternatives: [ { tool: 'gdrive_search', description: 'For faster basic search by file type', command: `gdrive_search query:"" fileType:"${fileType}"` } ] }; } // Default recommendation return { primaryTool: 'gdrive_find_documents', reasoning: 'Balanced approach with clear file selection and comprehensive metadata', command: `gdrive_find_documents query:"${intent}" maxResults:5`, alternatives: [ { tool: 'gdrive_search', description: 'For faster basic search', command: `gdrive_search query:"${intent}"` }, { tool: 'gdrive_search_indexed', description: 'For AI-powered content search (if indexed)', command: `gdrive_search_indexed query:"${intent}"` } ] }; } function generateContextualTips(intent) { if (intent.includes('business') || intent.includes('plan')) { return `• Use specific terms like "business plan", "strategy", "executive summary"\n` + `• Try different file types: PDFs for final plans, Docs for drafts\n` + `• Check modification dates to find the latest version\n` + `• Consider indexing for content-based search within documents`; } if (intent.includes('contract') || intent.includes('legal')) { return `• Search for keywords like "agreement", "contract", "terms"\n` + `• Use date filtering to find contracts by execution date\n` + `• Index documents to search contract terms and conditions\n` + `• Look in organized folders like /Legal/ or /Contracts/`; } if (intent.includes('financial')) { return `• Try terms like "budget", "forecast", "projections", "revenue"\n` + `• Filter by spreadsheet type for financial models\n` + `• Use date ranges to find quarterly or annual reports\n` + `• Index for searching specific financial metrics within documents`; } if (intent.includes('recent')) { return `• Use date filtering with modifiedAfter parameter\n` + `• Sort results by modification time\n` + `• Consider checking multiple file types\n` + `• Use broader search terms for comprehensive results`; } return `• Start with broad terms, then refine with specific keywords\n` + `• Use file type filtering to narrow results\n` + `• Try both filename and content search approaches\n` + `• Consider setting up indexing for enhanced search capabilities`; }