drive_files_update
Update a Google Drive file's name, MIME type, or upload new content by providing the file ID and optional new values.
Instructions
Update a file's metadata or content.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fileId | Yes | The file ID to update | |
| fields | No | Fields to return | |
| name | No | New file name | |
| mimeType | No | New MIME type | |
| uploadPath | No | Local file path to upload |
Implementation Reference
- src/index.ts:160-177 (handler)The generic tool handler registered via server.tool() for 'drive_files_update'. When the tool is invoked, it calls executeGws() which builds CLI args and spawns the gws process. This is the actual execution logic for drive_files_update.
server.tool( tool.name, tool.description, schema, async (args) => { const result = await executeGws(tool, args as Record<string, unknown>, gwsBinary); if (result.success) { return { content: [{ type: "text" as const, text: result.output || "(empty response)" }], }; } else { return { content: [{ type: "text" as const, text: `Error: ${result.error}` }], isError: true, }; } }, - src/index.ts:101-132 (schema)buildZodSchema() generates the Zod validation schema for all tools including drive_files_update. It constructs a schema from tool.params and tool.bodyParams definitions, and adds an optional 'uploadPath' field if supportsUpload is true.
export function buildZodSchema(tool: ToolDef): Record<string, z.ZodTypeAny> { const shape: Record<string, z.ZodTypeAny> = {}; const allParams = [...tool.params, ...(tool.bodyParams || [])]; for (const p of allParams) { let field: z.ZodTypeAny; switch (p.type) { case "number": field = z.number().describe(p.description); break; case "boolean": field = z.boolean().describe(p.description); break; default: field = z.string().describe(p.description); } if (!p.required) { field = field.optional(); } shape[p.name] = field; } // Add optional uploadPath for tools that support file upload if (tool.supportsUpload) { shape.uploadPath = z.string().describe("Local file path to upload").optional(); } return shape; } - src/index.ts:156-178 (registration)All tools from the SERVICE_TOOLS registry (including drive_files_update) are registered as MCP tools in a loop over the tools array. drive_files_update is registered here via server.tool() along with all other tools.
// Register each tool for (const tool of tools) { const schema = buildZodSchema(tool); server.tool( tool.name, tool.description, schema, async (args) => { const result = await executeGws(tool, args as Record<string, unknown>, gwsBinary); if (result.success) { return { content: [{ type: "text" as const, text: result.output || "(empty response)" }], }; } else { return { content: [{ type: "text" as const, text: `Error: ${result.error}` }], isError: true, }; } }, ); - src/services.ts:93-107 (schema)The ToolDef definition for 'drive_files_update' — defines the tool name, description, command (['drive','files','update']), params (fileId required, fields optional), bodyParams (name, mimeType optional), and supportsUpload: true. This is the schema/configuration for the tool.
{ name: "drive_files_update", description: "Update a file's metadata or content.", command: ["drive", "files", "update"], params: [ { name: "fileId", description: "The file ID to update", type: "string", required: true }, { name: "fields", description: "Fields to return", type: "string", required: false }, ], bodyParams: [ { name: "name", description: "New file name", type: "string", required: false }, { name: "mimeType", description: "New MIME type", type: "string", required: false }, ], supportsUpload: true, defaultParams: DRIVE_SHARED_DEFAULTS_NO_INCLUDE, }, - src/executor.ts:181-210 (helper)executeGws() is the generic helper that executes gws CLI commands. It's called when drive_files_update is invoked. buildArgs() (line 76-129) constructs the CLI arguments including --params, --json, and --upload flags based on the tool definition and user-provided args.
export async function executeGws( tool: ToolDef, args: Record<string, unknown>, gwsBinary: string, ): Promise<ExecResult> { const cliArgs = buildArgs(tool, args); console.error(`[gws-mcp] Executing: ${gwsBinary} ${cliArgs.join(" ")}`); try { const { stdout, stderr } = await spawnGwsRaw(gwsBinary, cliArgs); if (stderr) { console.error(`[gws-mcp] stderr: ${stderr}`); } return { success: true, output: stdout || "(empty response)" }; } catch (err: unknown) { const error = err as { message?: string }; let message = error.message || "Unknown error"; // Enhance Drive 404 errors with actionable hints if (message.includes("404") && message.includes("not found") && tool.command[0] === "drive") { message += "\n\nHint: If this file is in a shared drive, ensure supportsAllDrives is set (this should be automatic). Check that the file ID is correct and the authenticated account has access."; } console.error(`[gws-mcp] Error: ${message}`); return { success: false, output: "", error: message }; } }