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.

46 lines 1.52 kB
import { z } from "zod"; import { BaseToolHandler } from "./BaseToolHandler.js"; const UpdateFileSchema = z.object({ fileId: z.string(), name: z.string().optional(), description: z.string().optional(), content: z.string().optional(), }); export class UpdateFileHandler extends BaseToolHandler { async runTool(args, drive) { const validArgs = UpdateFileSchema.parse(args); const file = await this.updateFile(validArgs, drive); return { content: [{ type: "text", text: `File updated successfully: ${file.name} (ID: ${file.id})`, }], isError: false, }; } async updateFile(args, drive) { try { const fileMetadata = {}; if (args.name) fileMetadata.name = args.name; if (args.description) fileMetadata.description = args.description; const updateOptions = { fileId: args.fileId, resource: fileMetadata, fields: 'id,name', }; if (args.content) { updateOptions.media = { body: Buffer.from(args.content), }; } const response = await drive.files.update(updateOptions); return response.data; } catch (error) { throw this.handleGoogleApiError(error); } } } //# sourceMappingURL=UpdateFileHandler.js.map