search_docs
Find Google Docs by name using the Drive API. Input a query, Google email, and service to retrieve a formatted list of matching documents, streamlining document searches in Google Workspace.
Instructions
Searches for Google Docs by name using Drive API (mimeType filter).
Returns:
str: A formatted list of Google Docs matching the search query.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page_size | No | ||
| query | Yes | ||
| service | Yes | ||
| user_google_email | Yes |
Implementation Reference
- gdocs/docs_tools.py:51-88 (handler)Handler and registration for the 'search_docs' tool. Searches Google Docs by name using Drive API, returns formatted list with IDs and links.@server.tool() @handle_http_errors("search_docs", is_read_only=True, service_type="docs") @require_google_service("drive", "drive_read") async def search_docs( service: Any, user_google_email: str, query: str, page_size: int = 10, ) -> str: """ Searches for Google Docs by name using Drive API (mimeType filter). Returns: str: A formatted list of Google Docs matching the search query. """ logger.info(f"[search_docs] Email={user_google_email}, Query='{query}'") escaped_query = query.replace("'", "\\'") response = await asyncio.to_thread( service.files().list( q=f"name contains '{escaped_query}' and mimeType='application/vnd.google-apps.document' and trashed=false", pageSize=page_size, fields="files(id, name, createdTime, modifiedTime, webViewLink)", supportsAllDrives=True, includeItemsFromAllDrives=True ).execute ) files = response.get('files', []) if not files: return f"No Google Docs found matching '{query}'." output = [f"Found {len(files)} Google Docs matching '{query}':"] for f in files: output.append( f"- {f['name']} (ID: {f['id']}) Modified: {f.get('modifiedTime')} Link: {f.get('webViewLink')}" ) return "\n".join(output)