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
60 lines (59 loc) • 2.33 kB
JavaScript
import { z } from 'zod';
import { indexer } from './indexer.js';
import { db } from './database.js';
export const name = 'gdrive_reindex_changed';
export const description = 'Reindex Google Drive files that have been modified since a given date';
export const inputSchema = z.object({
sinceHours: z.number().optional().default(24).describe('Check for files modified in the last N hours'),
showStats: z.boolean().optional().default(true).describe('Show database statistics after reindexing')
});
export const schema = {
name,
description,
inputSchema: {
type: 'object',
properties: {
sinceHours: { type: 'number', description: 'Check for files modified in the last N hours', default: 24 },
showStats: { type: 'boolean', description: 'Show database statistics after reindexing', default: true }
},
required: []
}
};
export async function gdrive_reindex_changed(args) {
try {
const since = new Date(Date.now() - (args.sinceHours ?? 24) * 60 * 60 * 1000);
console.log(`Checking for files modified since: ${since.toISOString()}`);
const result = await indexer.reindexChanged(since);
const output = [
`Reindexing complete:`,
`- Files updated: ${result.indexed}`,
`- Errors: ${result.errors}`
];
if (result.errorDetails.length > 0) {
output.push('\nErrors encountered:');
result.errorDetails.forEach(err => {
output.push(`- ${err.fileName}: ${err.error}`);
});
}
if (args.showStats ?? true) {
const stats = db.getStats();
output.push('');
output.push('Database Statistics:');
output.push(`- Total documents: ${stats.total}`);
output.push('- By type:');
for (const [type, count] of Object.entries(stats.by_type)) {
output.push(` - ${type}: ${count}`);
}
}
return {
content: [{ type: 'text', text: output.join('\n') }],
isError: false
};
}
catch (error) {
return {
content: [{ type: 'text', text: `Error reindexing: ${error instanceof Error ? error.message : 'Unknown error'}` }],
isError: true
};
}
}