Skip to main content
Glama
andresfrei

Google Drive MCP Server

by andresfrei

search_files

Search for files by name in Google Drive to quickly locate specific documents, spreadsheets, and text files across multiple accounts.

Instructions

Search files by name in a Google Drive

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
driveIdYes
queryYes

Implementation Reference

  • The main handler function that destructures input parameters, calls the googleDriveService.searchFiles helper, formats the output with total count and file list, and returns both text and structured content as required by MCP tool format.
    handler: async (params: { driveId: string; query: string }) => {
      const { driveId, query } = params;
      const files = await googleDriveService.searchFiles(driveId, query);
      const output = { totalFiles: files.length, files };
    
      return {
        content: [
          { type: "text" as const, text: JSON.stringify(output, null, 2) },
        ],
        structuredContent: output,
      };
    },
  • Zod-based input and output schemas defining the expected parameters (driveId, query) and response structure (totalFiles, files array with id, name, etc.) for the search_files tool.
    config: {
      title: "Search Google Drive Files",
      description: "Search files by name in a Google Drive",
      inputSchema: {
        driveId: z.string().describe("Drive ID to search in"),
        query: z.string().describe("Search query (file name)"),
      },
      outputSchema: {
        totalFiles: z.number(),
        files: z.array(
          z.object({
            id: z.string(),
            name: z.string(),
            mimeType: z.string(),
            modifiedTime: z.string(),
            webViewLink: z.string().optional(),
          })
        ),
      },
    },
  • Re-export of the searchFilesTool from its implementation file as part of the central MCP tools registry index.
    export { searchFilesTool } from "@/mcp/tools/search-files.js";
  • Supporting helper method in the GoogleDriveService class that performs the actual file search using Google Drive API v3 files.list with a name contains query, excluding trashed files, mapping results to DriveFile type.
    async searchFiles(driveId: string, query: string): Promise<DriveFile[]> {
      const drive = await this.getDriveClient(driveId);
    
      try {
        // Buscar por nombre (case-insensitive)
        const response = await drive.files.list({
          q: `name contains '${query}' and trashed = false`, // Búsqueda parcial
          fields: "files(id, name, mimeType, modifiedTime, size, webViewLink)", // Campos básicos
          pageSize: 50, // Límite de resultados
          orderBy: "modifiedTime desc", // Más recientes primero
        });
    
        const files = response.data.files || [];
        logger.info(`Search found ${files.length} files for query: "${query}"`);
    
        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,
        }));
      } catch (error) {
        logger.error("Error searching files", { driveId, query, 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 full burden for behavioral disclosure. While 'search' implies a read-only operation, it doesn't specify whether this requires authentication, what happens with no results, whether there are rate limits, or how results are returned. The description mentions the scope ('in a Google Drive') but lacks other critical behavioral context for a tool with no annotation coverage.

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 communicates the core functionality without unnecessary words. It's appropriately sized for a basic search tool and gets straight to the point with no wasted language.

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?

For a search tool with 2 required parameters, 0% schema coverage, no annotations, and no output schema, the description is insufficient. It doesn't explain what the tool returns, how results are structured, whether there are limitations on search scope, or how to interpret the parameters. The description provides only basic purpose information without the necessary context for effective tool usage.

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

Parameters2/5

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

With 0% schema description coverage for both parameters, the description provides no information about what 'driveId' and 'query' represent, their formats, or constraints. The description mentions 'search files by name' which hints that 'query' might be a filename search, but doesn't clarify if it supports partial matches, wildcards, or other search operators. This doesn't adequately compensate for the complete lack of schema documentation.

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 action ('search files by name') and resource ('in a Google Drive'), making the purpose immediately understandable. It doesn't explicitly distinguish from sibling tools like 'list_files', but the 'search by name' specification provides some differentiation from a generic listing operation.

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 'list_files' or 'get_file_content'. It doesn't mention prerequisites, limitations, or specific scenarios where this search function is appropriate versus other file-related operations.

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