UNPKG

mcp-google-drive

Version:

Advanced MCP server for Google Drive integration with full CRUD operations, file management, and sharing capabilities. Supports both OAuth2 and Service Account authentication.

66 lines 3 kB
import { SearchFilesHandler } from "./core/SearchFilesHandler.js"; import { GetFileHandler } from "./core/GetFileHandler.js"; import { ListFilesHandler } from "./core/ListFilesHandler.js"; import { GetFileContentHandler } from "./core/GetFileContentHandler.js"; import { CreateFileHandler } from "./core/CreateFileHandler.js"; import { UpdateFileHandler } from "./core/UpdateFileHandler.js"; import { DeleteFileHandler } from "./core/DeleteFileHandler.js"; import { CopyFileHandler } from "./core/CopyFileHandler.js"; import { MoveFileHandler } from "./core/MoveFileHandler.js"; import { CreateFolderHandler } from "./core/CreateFolderHandler.js"; import { GetFilePermissionsHandler } from "./core/GetFilePermissionsHandler.js"; import { ShareFileHandler } from "./core/ShareFileHandler.js"; import { GetDriveInfoHandler } from "./core/GetDriveInfoHandler.js"; import { ListSharedDrivesHandler } from "./core/ListSharedDrivesHandler.js"; import { GetFileRevisionsHandler } from "./core/GetFileRevisionsHandler.js"; /** * Handles incoming tool calls, validates arguments, calls the appropriate service, * and formats the response. * * @param request The CallToolRequest containing tool name and arguments. * @param drive The authenticated Google Drive API instance. * @returns A Promise resolving to the CallToolResult. */ export async function handleCallTool(request, drive) { const { name, arguments: args } = request.params; try { console.error(`[${new Date().toISOString()}] [DEBUG] MCP-Google-Drive: Executing tool: ${name}`); const handler = getHandler(name); return await handler.runTool(args, drive); } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); console.error(`[${new Date().toISOString()}] [ERROR] MCP-Google-Drive: Error executing tool '${name}': ${errorMessage}`); throw error; } } // Handler map for all available tools const handlerMap = { // Search and discovery "search_files": new SearchFilesHandler(), "get_file": new GetFileHandler(), "list_files": new ListFilesHandler(), "get_file_content": new GetFileContentHandler(), // File operations "create_file": new CreateFileHandler(), "update_file": new UpdateFileHandler(), "delete_file": new DeleteFileHandler(), "copy_file": new CopyFileHandler(), "move_file": new MoveFileHandler(), "create_folder": new CreateFolderHandler(), // Permissions and sharing "get_file_permissions": new GetFilePermissionsHandler(), "share_file": new ShareFileHandler(), // Drive operations "get_drive_info": new GetDriveInfoHandler(), "list_shared_drives": new ListSharedDrivesHandler(), "get_file_revisions": new GetFileRevisionsHandler(), }; function getHandler(toolName) { const handler = handlerMap[toolName]; if (!handler) { throw new Error(`Unknown tool: ${toolName}`); } return handler; } //# sourceMappingURL=callTool.js.map