Skip to main content
Glama
taylorwilsdon

Google Workspace MCP Server - Control Gmail, Calendar, Docs, Sheets, Slides, Chat, Forms & Drive

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
NameRequiredDescriptionDefault
page_sizeNo
queryYes
serviceYes
user_google_emailYes

Implementation Reference

  • 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)

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/taylorwilsdon/google_workspace_mcp'

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