Skip to main content
Glama

google_drive_update_file

Modify or replace the content of an existing file in Google Drive by specifying the file ID and new data. Ensure accurate updates with optional MIME type adjustments.

Instructions

Update the content of an existing file in Google Drive

Input Schema

NameRequiredDescriptionDefault
contentYesNew content of the file
fileIdYesID of the file to update
mimeTypeNoMIME type of the file (if different from original)

Input Schema (JSON Schema)

{ "properties": { "content": { "description": "New content of the file", "type": "string" }, "fileId": { "description": "ID of the file to update", "type": "string" }, "mimeType": { "description": "MIME type of the file (if different from original)", "type": "string" } }, "required": [ "fileId", "content" ], "type": "object" }

Implementation Reference

  • The main handler function for the google_drive_update_file tool. Validates input arguments using isUpdateFileArgs and delegates to GoogleDrive.updateFile method.
    export async function handleDriveUpdateFile( args: any, googleDriveInstance: GoogleDrive ) { if (!isUpdateFileArgs(args)) { throw new Error("Invalid arguments for google_drive_update_file"); } const { fileId, content, mimeType } = args; const result = await googleDriveInstance.updateFile( fileId, content, mimeType ); return { content: [{ type: "text", text: result }], isError: false, };
  • MCP tool schema definition for google_drive_update_file, including input schema and description.
    export const UPDATE_FILE_TOOL: Tool = { name: "google_drive_update_file", description: "Update the content of an existing file in Google Drive", inputSchema: { type: "object", properties: { fileId: { type: "string", description: "ID of the file to update", }, content: { type: "string", description: "New content of the file", }, mimeType: { type: "string", description: "MIME type of the file (if different from original)", }, }, required: ["fileId", "content"], }, };
  • Type guard function for validating arguments to google_drive_update_file tool.
    export function isUpdateFileArgs(args: any): args is { fileId: string; content: string; mimeType?: string; } { return ( args && typeof args.fileId === "string" && typeof args.content === "string" && (args.mimeType === undefined || typeof args.mimeType === "string") ); }
  • Core implementation of file update using Google Drive API v3. Handles metadata check, Google Docs limitation, and updates file content.
    async updateFile(fileId: string, content: string, mimeType?: string) { try { // First get the file metadata to verify its type const fileMetadata = await this.drive.files.get({ fileId: fileId, fields: "name,mimeType", }); const { mimeType: fileMimeType } = fileMetadata.data; // Check if this is a Google Doc/Sheet - these require different update approach if (fileMimeType.includes("application/vnd.google-apps")) { throw new Error( `Updating Google ${fileMimeType .split(".") .pop()} content is not supported via this tool. Please use the Google Drive web interface.` ); } // Update regular file content const response = await this.drive.files.update({ fileId: fileId, media: { mimeType: mimeType || fileMimeType, body: content, }, fields: "id,name", }); return `File '${response.data.name}' updated successfully.`; } catch (error) { throw new Error( `Failed to update file: ${ error instanceof Error ? error.message : String(error) }` ); } }
  • Server dispatch case that routes calls to the google_drive_update_file handler.
    case "google_drive_update_file": return await driveHandlers.handleDriveUpdateFile( args, googleDriveInstance );

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