Skip to main content
Glama

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
NameRequiredDescriptionDefault
emailAddressYesEmail address of the user to share with
fileIdYesID of the file to share
messageNoCustom message to include in the notification email
roleNoAccess role to grant (reader, writer, commenter, owner)
sendNotificationNoWhether to send a notification email

Implementation Reference

  • 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, }; }
  • 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"], }, };
  • 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 );
  • 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) }` ); } }
  • 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") ); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/vakharwalad23/google-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server