Skip to main content
Glama
andresfrei

Google Drive MCP Server

by andresfrei

list_files

Retrieve files from Google Drive using filters like folder location, modification date, file type, or specific drive to organize and access your documents efficiently.

Instructions

List files from Google Drive with optional filters (driveId, folderId, modifiedAfter/Before, mimeType)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
driveIdNo
folderIdNo
mimeTypeNo
modifiedAfterNo
modifiedBeforeNo
pageSizeNo

Implementation Reference

  • The handler function that implements the core logic of the 'list_files' tool. It calls the Google Drive service to list files based on parameters and formats the response with total count and file list.
    handler: async (params: {
      driveId?: string;
      folderId?: string;
      modifiedAfter?: string;
      modifiedBefore?: string;
      mimeType?: string;
      pageSize?: number;
    }) => {
      const files = await googleDriveService.listFiles(params);
      const output = { totalFiles: files.length, files };
    
      return {
        content: [
          { type: "text" as const, text: JSON.stringify(output, null, 2) },
        ],
        structuredContent: output,
      };
    },
  • Zod schemas defining the input parameters and output structure for the 'list_files' tool, including optional filters like driveId, folderId, date ranges, mimeType, and pageSize.
    config: {
      title: "List Google Drive Files",
      description:
        "List files from Google Drive with optional filters (driveId, folderId, modifiedAfter/Before, mimeType)",
      inputSchema: {
        driveId: z.string().optional().describe("Drive ID to list files from"),
        folderId: z.string().optional().describe("Folder ID to list files from"),
        modifiedAfter: z
          .string()
          .optional()
          .describe("Filter files modified after this date (ISO 8601)"),
        modifiedBefore: z
          .string()
          .optional()
          .describe("Filter files modified before this date (ISO 8601)"),
        mimeType: z.string().optional().describe("Filter by MIME type"),
        pageSize: z
          .number()
          .optional()
          .default(100)
          .describe("Number of files to return (max 1000)"),
      },
      outputSchema: {
        totalFiles: z.number(),
        files: z.array(
          z.object({
            id: z.string(),
            name: z.string(),
            mimeType: z.string(),
            modifiedTime: z.string(),
            size: z.string().optional(),
            webViewLink: z.string().optional(),
            parents: z.array(z.string()).optional(),
          })
        ),
      },
  • Automatic registration loop that registers the 'list_files' tool (imported via tools/index.ts) using McpServer.registerTool with its name, config, and handler.
    const toolList = Object.values(tools);
    toolList.forEach((tool) => {
      server.registerTool(tool.name, tool.config as any, tool.handler as any);
    });
  • Barrel export that makes the listFilesTool available for import in the server registration.
    export { listFilesTool } from "@/mcp/tools/list-files.js";
  • The GoogleDriveService.listFiles method called by the tool handler, which constructs a Google Drive API query with filters and retrieves the list of files.
    async listFiles(params: ListFilesParams): Promise<DriveFile[]> {
      // Usar primer Drive si no se especifica uno
      const driveId =
        params.driveId || Object.keys(drivesConfigLoader.getConfig().drives)[0];
      const drive = await this.getDriveClient(driveId);
    
      // Construir query de filtrado de Google Drive
      const queryParts: string[] = ["trashed = false"]; // Excluir archivos en papelera
    
      if (params.folderId) {
        queryParts.push(`'${params.folderId}' in parents`);
      }
    
      if (params.modifiedAfter) {
        queryParts.push(`modifiedTime >= '${params.modifiedAfter}'`);
      }
    
      if (params.modifiedBefore) {
        queryParts.push(`modifiedTime <= '${params.modifiedBefore}'`);
      }
    
      if (params.mimeType) {
        queryParts.push(`mimeType = '${params.mimeType}'`);
      }
    
      const query = queryParts.join(" and ");
    
      try {
        // Ejecutar consulta a Google Drive API
        const response = await drive.files.list({
          q: query, // Query construido dinámicamente
          fields:
            "files(id, name, mimeType, modifiedTime, size, webViewLink, parents)", // Campos específicos
          pageSize: params.pageSize || 100, // Límite por defecto: 100 archivos
          orderBy: "modifiedTime desc", // Ordenar por más recientes primero
        });
    
        const files = response.data.files || [];
    
        logger.info(`Listed ${files.length} files from drive: ${driveId}`);
    
        // Mapear a tipo DriveFile tipado
        return files.map((file: Record<string, any>) => ({
          id: file.id!,
          name: file.name!,
          mimeType: file.mimeType!,
          modifiedTime: file.modifiedTime!,
          size: file.size,
          webViewLink: file.webViewLink,
          parents: file.parents,
        }));
      } catch (error) {
        logger.error("Error listing files", { driveId, error });
        throw error;
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions optional filters but doesn't describe key behaviors: whether this is a read-only operation, how pagination works (though 'pageSize' is in schema), what the return format looks like, or any rate limits/permissions needed. For a tool with 6 parameters and no annotations, this leaves significant gaps in understanding its behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose ('List files from Google Drive') and then enumerates optional filters. There is zero wasted language, and every word contributes directly to understanding the tool's functionality.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has 6 parameters with 0% schema description coverage, no annotations, and no output schema, the description is incomplete. It doesn't explain return values, pagination behavior, error conditions, or how filters interact. For a listing tool with multiple filters, more context is needed to use it effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description lists 5 of the 6 parameters (driveId, folderId, mimeType, modifiedAfter/Before) as optional filters, adding meaning beyond the schema which has 0% description coverage. However, it omits 'pageSize' entirely, and doesn't explain parameter formats (e.g., date format for modifiedAfter) or relationships between parameters. With low schema coverage, it partially compensates but not fully.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'List' and resource 'files from Google Drive', making the purpose unambiguous. It distinguishes from siblings like 'search_files' by specifying it's a listing operation rather than a search, though it doesn't explicitly contrast them. The description avoids tautology by not just repeating the name.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'search_files' or 'list_drives'. It mentions optional filters but doesn't explain scenarios where filtering is appropriate or when other tools might be better suited. There are no explicit when/when-not instructions or named alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/andresfrei/mcp-google-drive-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server