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
64 lines (63 loc) • 2.63 kB
JavaScript
import { z } from 'zod';
import { db } from './database.js';
export const name = 'gdrive_search_indexed';
export const description = 'Search the indexed Google Drive documents using the local SQLite database';
export const inputSchema = z.object({
query: z.string().describe('Search query - searches in file names, synopsis, and extracted metadata'),
limit: z.number().optional().default(25).describe('Maximum number of results to return'),
docType: z.enum(['invoice', 'contract', 'proposal', 'report']).optional().describe('Filter by document type')
});
export const schema = {
name,
description,
inputSchema: {
type: 'object',
properties: {
query: { type: 'string', description: 'Search query - searches in file names, synopsis, and extracted metadata' },
limit: { type: 'number', description: 'Maximum number of results to return', default: 25 },
docType: { type: 'string', enum: ['invoice', 'contract', 'proposal', 'report'], description: 'Filter by document type' }
},
required: ['query']
}
};
export async function gdrive_search_indexed(args) {
try {
let results;
if (args.docType) {
// Search by specific document type
results = db.searchByType(args.docType, args.limit ?? 25);
}
else {
// General search
results = await db.searchDocuments(args.query, args.limit ?? 25);
}
if (results.length === 0) {
return {
content: [{ type: 'text', text: 'No documents found matching your search criteria' }],
isError: false
};
}
const output = [`Found ${results.length} document(s):\n`];
results.forEach((doc, index) => {
output.push(`${index + 1}. ${doc.name}`);
output.push(` ID: ${doc.id} | Drive ID: ${doc.drive_id}`);
output.push(` Type: ${doc.doc_type || 'unknown'}`);
output.push(` Path: ${doc.drive_path || 'Unknown path'}`);
output.push(` Synopsis: ${doc.synopsis || 'No synopsis available'}`);
if (doc.score) {
output.push(` Relevance: ${doc.score}/10`);
}
output.push('');
});
return {
content: [{ type: 'text', text: output.join('\n') }],
isError: false
};
}
catch (error) {
return {
content: [{ type: 'text', text: `Error searching documents: ${error instanceof Error ? error.message : 'Unknown error'}` }],
isError: true
};
}
}