google_drive_share_file
Share a file on Google Drive by specifying the file ID and recipient email. Set access roles (reader, writer, commenter, owner) and optionally include a custom message in the notification email.
Instructions
Share a file with another user
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| emailAddress | Yes | Email address of the user to share with | |
| fileId | Yes | ID of the file to share | |
| message | No | Custom message to include in the notification email | |
| role | No | Access role to grant (reader, writer, commenter, owner) | |
| sendNotification | No | Whether to send a notification email |
Implementation Reference
- handlers/drive.ts:100-119 (handler)Handler function that validates input arguments using isShareFileArgs and calls the GoogleDrive instance's shareFile method to perform the sharing operation.export async function handleDriveShareFile( args: any, googleDriveInstance: GoogleDrive ) { if (!isShareFileArgs(args)) { throw new Error("Invalid arguments for google_drive_share_file"); } const { fileId, emailAddress, role, sendNotification, message } = args; const result = await googleDriveInstance.shareFile( fileId, emailAddress, role, sendNotification, message ); return { content: [{ type: "text", text: result }], isError: false, }; }
- tools/drive/index.ts:118-147 (schema)MCP tool definition including name, description, and input schema for validating tool arguments.export const SHARE_FILE_TOOL: Tool = { name: "google_drive_share_file", description: "Share a file with another user", inputSchema: { type: "object", properties: { fileId: { type: "string", description: "ID of the file to share", }, emailAddress: { type: "string", description: "Email address of the user to share with", }, role: { type: "string", description: "Access role to grant (reader, writer, commenter, owner)", }, sendNotification: { type: "boolean", description: "Whether to send a notification email", }, message: { type: "string", description: "Custom message to include in the notification email", }, }, required: ["fileId", "emailAddress"], }, };
- server-setup.ts:206-210 (registration)Switch case in server request handler that routes 'call tool' requests for 'google_drive_share_file' to the drive handler.case "google_drive_share_file": return await driveHandlers.handleDriveShareFile( args, googleDriveInstance );
- utils/drive.ts:219-252 (helper)Core implementation in GoogleDrive class that uses Google Drive API to create permissions and share the file, returning a success message.async shareFile( fileId: string, emailAddress: string, role: string = "reader", sendNotification: boolean = true, message?: string ) { try { const response = await this.drive.permissions.create({ fileId: fileId, requestBody: { type: "user", role: role, emailAddress: emailAddress, }, sendNotificationEmail: sendNotification, emailMessage: message, }); // Get the file name const fileMetadata = await this.drive.files.get({ fileId: fileId, fields: "name", }); return `File '${fileMetadata.data.name}' shared with ${emailAddress} as ${role}.`; } catch (error) { throw new Error( `Failed to share file: ${ error instanceof Error ? error.message : String(error) }` ); } }
- utils/helper.ts:298-314 (schema)Type guard function for runtime validation of arguments matching the tool's input schema.export function isShareFileArgs(args: any): args is { fileId: string; emailAddress: string; role?: string; sendNotification?: boolean; message?: string; } { return ( args && typeof args.fileId === "string" && typeof args.emailAddress === "string" && (args.role === undefined || typeof args.role === "string") && (args.sendNotification === undefined || typeof args.sendNotification === "boolean") && (args.message === undefined || typeof args.message === "string") ); }