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
73 lines (72 loc) • 2.6 kB
JavaScript
import { z } from 'zod';
import { db } from './database.js';
export const name = 'gdrive_get_indexed_doc';
export const description = 'Get the full metadata for an indexed document from the SQLite database';
export const inputSchema = z.object({
documentId: z.number().describe('The document ID from the search results')
});
export const schema = {
name,
description,
inputSchema: {
type: 'object',
properties: {
documentId: { type: 'number', description: 'The document ID from the search results' }
},
required: ['documentId']
}
};
export async function gdrive_get_indexed_doc(args) {
try {
const doc = await db.getDocument(args.documentId);
if (!doc) {
return {
content: [{ type: 'text', text: `Document with ID ${args.documentId} not found` }],
isError: true
};
}
const output = [
`Document Details:`,
`================`,
`Name: ${doc.name}`,
`Drive ID: ${doc.drive_id}`,
`Path: ${doc.drive_path || 'Unknown'}`,
`Type: ${doc.doc_type || 'unknown'}`,
`MIME Type: ${doc.mime_type}`,
`Size: ${doc.size ? `${(doc.size / 1024 / 1024).toFixed(2)} MB` : 'Unknown'}`,
`Modified: ${doc.modified_time || 'Unknown'}`,
`Indexed: ${doc.indexed_ts_utc || 'Unknown'}`,
``,
`Synopsis:`,
`${doc.synopsis || 'No synopsis available'}`,
``
];
if (doc.ai_json) {
output.push(`Extracted Fields:`);
output.push(`-----------------`);
const fields = doc.ai_json;
for (const [key, value] of Object.entries(fields)) {
if (value !== null && value !== undefined) {
if (Array.isArray(value)) {
output.push(`${key}: ${value.join(', ')}`);
}
else {
output.push(`${key}: ${value}`);
}
}
}
}
output.push('');
output.push(`To read the full file content, use: gdrive_read_file with fileId: ${doc.drive_id}`);
return {
content: [{ type: 'text', text: output.join('\n') }],
isError: false
};
}
catch (error) {
return {
content: [{ type: 'text', text: `Error getting document: ${error instanceof Error ? error.message : 'Unknown error'}` }],
isError: true
};
}
}