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
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | New content of the file | |
| fileId | Yes | ID of the file to update | |
| mimeType | No | MIME 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
- handlers/drive.ts:66-82 (handler)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, };
- tools/drive/index.ts:75-96 (schema)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"], }, };
- utils/helper.ts:274-285 (schema)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") ); }
- utils/drive.ts:155-192 (helper)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-setup.ts:196-200 (registration)Server dispatch case that routes calls to the google_drive_update_file handler.case "google_drive_update_file": return await driveHandlers.handleDriveUpdateFile( args, googleDriveInstance );