drive_files_list
List Google Drive files with search queries, pagination, field selection, and sorting. Shared drives are included automatically.
Instructions
List files in Google Drive. Supports search queries via the 'q' parameter. Shared drive files are included automatically.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| q | No | Search query (e.g. "name contains 'report'" or "mimeType='application/vnd.google-apps.folder'") | |
| pageSize | No | Max results per page (1-1000, default 100) | |
| fields | No | Fields to include (e.g. "files(id,name,mimeType)") | |
| orderBy | No | Sort order (e.g. "modifiedTime desc") |
Implementation Reference
- src/services.ts:40-52 (registration)Tool definition registration for 'drive_files_list' as a ToolDef object — specifies name, description, gws command ['drive','files','list'], params schema (q, pageSize, fields, orderBy), and shared drive defaults.
const driveTools: ToolDef[] = [ { name: "drive_files_list", description: "List files in Google Drive. Supports search queries via the 'q' parameter. Shared drive files are included automatically.", command: ["drive", "files", "list"], params: [ { name: "q", description: "Search query (e.g. \"name contains 'report'\" or \"mimeType='application/vnd.google-apps.folder'\")", type: "string", required: false }, { name: "pageSize", description: "Max results per page (1-1000, default 100)", type: "number", required: false }, { name: "fields", description: "Fields to include (e.g. \"files(id,name,mimeType)\")", type: "string", required: false }, { name: "orderBy", description: "Sort order (e.g. \"modifiedTime desc\")", type: "string", required: false }, ], defaultParams: DRIVE_SHARED_DEFAULTS, }, - src/index.ts:157-178 (handler)Generic handler that registers all tools (including drive_files_list) via server.tool(). Uses a dynamic schema from buildZodSchema(tool) and delegates execution to executeGws(), which builds CLI args and spawns the gws process.
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:10-25 (schema)ToolDef interface definition — the TypeScript interface that defines the shape of tool definitions including name, description, command, params, bodyParams, etc.
export interface ToolDef { /** MCP tool name, e.g. "drive_files_list" */ name: string; /** Human-readable description */ description: string; /** gws CLI args, e.g. ["drive", "files", "list"] */ command: string[]; /** Parameters passed via --params (query/path params) */ params: ParamDef[]; /** Parameters passed via --json (request body) */ bodyParams?: ParamDef[]; /** Whether this tool accepts a file upload via --upload */ supportsUpload?: boolean; /** Default params injected into every call (can be overridden by caller) */ defaultParams?: Record<string, unknown>; } - src/index.ts:101-132 (helper)buildZodSchema() helper function — dynamically builds a Zod validation schema from ToolDef params, used to generate the schema for drive_files_list (and all other tools) at registration time.
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 (helper)executeGws() — the main handler delegate that builds CLI args from the tool definition and spawns the gws CLI process to actually run 'drive files list' (or any other tool).
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 }; } }