drive_files_create
Creates a Google Drive file with specified name, MIME type, and parent folder. Optionally uploads a local file. Returns requested fields like ID or webViewLink.
Instructions
Create a new file in Google Drive. Use with bodyParams for metadata and optionally upload a local file.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fields | No | Fields to return (e.g. "id,webViewLink") | |
| name | Yes | File name | |
| mimeType | No | MIME type (e.g. "application/vnd.google-apps.document") | |
| parents | No | Parent folder IDs (JSON array as string, e.g. '["folderId"]') | |
| uploadPath | No | Local file path to upload |
Implementation Reference
- src/services.ts:63-77 (schema)Tool definition (schema) for drive_files_create. Defines the tool name, description, command (drive files create), params (fields), bodyParams (name, mimeType, parents), supportsUpload flag, and defaultParams (supportsAllDrives).
{ name: "drive_files_create", description: "Create a new file in Google Drive. Use with bodyParams for metadata and optionally upload a local file.", command: ["drive", "files", "create"], params: [ { name: "fields", description: "Fields to return (e.g. \"id,webViewLink\")", type: "string", required: false }, ], bodyParams: [ { name: "name", description: "File name", type: "string", required: true }, { name: "mimeType", description: "MIME type (e.g. \"application/vnd.google-apps.document\")", type: "string", required: false }, { name: "parents", description: "Parent folder IDs (JSON array as string, e.g. '[\"folderId\"]')", type: "string", required: false }, ], supportsUpload: true, defaultParams: DRIVE_SHARED_DEFAULTS_NO_INCLUDE, }, - src/index.ts:156-178 (registration)Generic registration loop that registers all tools (including drive_files_create) from tools array onto the MCP server using server.tool(), with buildZodSchema for schema and executeGws for handler logic.
// 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/index.ts:101-132 (helper)buildZodSchema helper that constructs the Zod validation schema for each tool. For drive_files_create, this includes 'fields' (from params), 'name', 'mimeType', 'parents' (from bodyParams), plus optional 'uploadPath' since 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/executor.ts:181-210 (handler)executeGws handles the actual execution for drive_files_create (and all generic tools). It calls buildArgs to construct CLI arguments, spawns the gws process, and returns the output. This is the generic handler invoked by the registered tool callback.
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 }; } }