Skip to main content
Glama

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; } }

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-drive'

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