google_drive_list_files
Retrieve and organize files from Google Drive using search queries, sorting, and field selection. Specify parameters like query, page size, and order to customize results.
Instructions
List files from Google Drive
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fields | No | Fields to include in the response (use Google Drive API syntax) | |
| orderBy | No | Comma-separated field names to sort by (e.g., 'modifiedTime desc') | |
| pageSize | No | Maximum number of files to return (default: 10) | |
| query | No | Google Drive search query (e.g., 'name contains "report"') |
Implementation Reference
- handlers/drive.ts:11-29 (handler)The handler function that implements the core logic for the google_drive_list_files tool, including argument validation and calling the Google Drive API via the instance.export async function handleDriveListFiles( args: any, googleDriveInstance: GoogleDrive ) { if (!isListFilesArgs(args)) { throw new Error("Invalid arguments for google_drive_list_files"); } const { query, pageSize, orderBy, fields } = args; const result = await googleDriveInstance.listFiles( query, pageSize, orderBy, fields ); return { content: [{ type: "text", text: result }], isError: false, }; }
- tools/drive/index.ts:3-30 (schema)The TypeScript type definition and JSON schema for the tool's input parameters.export const LIST_FILES_TOOL: Tool = { name: "google_drive_list_files", description: "List files from Google Drive", inputSchema: { type: "object", properties: { query: { type: "string", description: "Google Drive search query (e.g., 'name contains \"report\"')", }, pageSize: { type: "number", description: "Maximum number of files to return (default: 10)", }, orderBy: { type: "string", description: "Comma-separated field names to sort by (e.g., 'modifiedTime desc')", }, fields: { type: "string", description: "Fields to include in the response (use Google Drive API syntax)", }, }, }, };
- server-setup.ts:181-185 (registration)The switch case in the MCP server's call tool request handler that registers and routes invocations of google_drive_list_files to its handler function.case "google_drive_list_files": return await driveHandlers.handleDriveListFiles( args, googleDriveInstance );
- utils/helper.ts:238-251 (helper)Helper type guard function for validating the input arguments to the google_drive_list_files tool.export function isListFilesArgs(args: any): args is { query?: string; pageSize?: number; orderBy?: string; fields?: string; } { return ( args && (args.query === undefined || typeof args.query === "string") && (args.pageSize === undefined || typeof args.pageSize === "number") && (args.orderBy === undefined || typeof args.orderBy === "string") && (args.fields === undefined || typeof args.fields === "string") ); }