drive_search_files
Locate specific files in Google Drive by entering a search query and defining the number of results to return, streamlining file management and retrieval.
Instructions
Search for files in Google Drive
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page_size | No | Number of results to return | |
| query | Yes | Search query |
Input Schema (JSON Schema)
{
"properties": {
"page_size": {
"default": 10,
"description": "Number of results to return",
"type": "integer"
},
"query": {
"description": "Search query",
"type": "string"
}
},
"required": [
"query"
],
"type": "object"
}
Implementation Reference
- src/mcp_google_suite/server.py:280-293 (handler)MCP tool handler for 'drive_search_files' that validates input and delegates to DriveService.search_filesasync def _handle_drive_search_files( self, context: GoogleWorkspaceContext, arguments: dict ) -> Dict[str, Any]: """Handle drive search files requests.""" query = arguments.get("query") page_size = arguments.get("page_size", 10) if not query: raise ValueError("Search query is required") logger.debug(f"Drive search request - Query: {query}, Page Size: {page_size}") result = await context.drive.search_files(query=query, page_size=page_size) logger.debug(f"Drive search completed - Found {len(result.get('files', []))} files") return result
- src/mcp_google_suite/server.py:57-72 (schema)Input schema definition for the 'drive_search_files' tool, including parameters and validation rulestypes.Tool( name="drive_search_files", description="Search for files in Google Drive", inputSchema={ "type": "object", "properties": { "query": {"type": "string", "description": "Search query"}, "page_size": { "type": "integer", "description": "Number of results to return", "default": 10, }, }, "required": ["query"], }, ),
- src/mcp_google_suite/server.py:177-182 (registration)Dynamic registration of tool handlers into the internal _tool_registry based on available _handle_ methodsfor tool in self._get_tools_list(): handler_name = f"_handle_{tool.name}" if hasattr(self, handler_name): handler = getattr(self, handler_name) self._tool_registry[tool.name] = handler logger.debug(f"Registered handler for {tool.name}")
- Core helper method implementing the Google Drive API search functionality for filesdef search_files(self, query: str, page_size: int = 10) -> Dict[str, Any]: """Search for files in Google Drive.""" try: results = ( self.service.files() .list(q=query, pageSize=page_size, fields="files(id, name, mimeType, webViewLink)") .execute() ) return {"success": True, "files": results.get("files", [])} except HttpError as error: return {"success": False, **self.handle_error(error)}