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

56 lines (55 loc) 2.26 kB
import { z } from 'zod'; export const name = 'gdrive_index_folder'; export const description = 'Recursively index all PDF files in a Google Drive folder using AI to extract metadata'; export const inputSchema = z.object({ folderId: z.string().describe('The Google Drive folder ID to index'), recurse: z.boolean().optional().default(true).describe('Whether to recursively index subfolders') }); export const schema = { name, description, inputSchema: { type: 'object', properties: { folderId: { type: 'string', description: 'The Google Drive folder ID to index' }, recurse: { type: 'boolean', description: 'Whether to recursively index subfolders', default: true } }, required: ['folderId'] } }; export async function gdrive_index_folder(args) { try { console.log(`Starting folder indexing for: ${args.folderId}`); // Create progress callback const progressCallback = (progress) => { console.log(`Indexing progress: ${progress.processed}/${progress.total} files processed, ${progress.errors} errors`); if (progress.currentFile) { console.log(`Currently processing: ${progress.currentFile}`); } }; const indexerWithProgress = new (await import('./indexer.js')).DriveIndexer(progressCallback); const result = await indexerWithProgress.indexFolder(args.folderId, args.recurse ?? true); const summary = [ `Indexing complete:`, `- Files indexed: ${result.indexed}`, `- Files skipped: ${result.skipped}`, `- Errors: ${result.errors}` ]; if (result.errorDetails.length > 0) { summary.push('\nErrors encountered:'); result.errorDetails.forEach(err => { summary.push(`- ${err.fileName}: ${err.error}`); }); } return { content: [{ type: 'text', text: summary.join('\n') }], isError: false }; } catch (error) { return { content: [{ type: 'text', text: `Error indexing folder: ${error instanceof Error ? error.message : 'Unknown error'}` }], isError: true }; } }