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.5 kB
import { z } from "zod"; import { BaseToolHandler } from "./BaseToolHandler.js"; const CreateFileSchema = z.object({ name: z.string(), mimeType: z.string(), content: z.string(), parentId: z.string().optional(), description: z.string().optional(), }); export class CreateFileHandler extends BaseToolHandler { async runTool(args, drive) { const validArgs = CreateFileSchema.parse(args); const file = await this.createFile(validArgs, drive); return { content: [{ type: "text", text: `File created successfully: ${file.name} (ID: ${file.id})`, }], isError: false, }; } async createFile(args, drive) { try { const fileMetadata = { name: args.name, mimeType: args.mimeType, description: args.description, parents: args.parentId ? [args.parentId] : undefined, }; const media = { mimeType: args.mimeType, body: Buffer.from(args.content), }; const response = await drive.files.create({ resource: fileMetadata, media: media, fields: 'id,name,webViewLink', }); return response.data; } catch (error) { throw this.handleGoogleApiError(error); } } } //# sourceMappingURL=CreateFileHandler.js.map