Skip to main content
Glama
giantrotta24

google-mcp

by giantrotta24

gmail_search_work

Search Gmail messages from your configured work account. Specify a query and optionally limit the number of results.

Instructions

Search Gmail for the configured work account.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
max_resultsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • tools.py:39-45 (handler)
    The gmail_search_work MCP tool handler. It loads credentials for the 'work' account via _load_or_error, then delegates to the gmail_search function in api.py.
    @mcp.tool()
    def gmail_search_work(query: str, max_results: int = 20) -> dict[str, Any]:
        """Search Gmail for the configured work account."""
        result = _load_or_error("work")
        if isinstance(result, dict):
            return result
        return gmail_search(result, query, max_results)
  • tools.py:30-36 (registration)
    Tool registration via @mcp.tool() decorator (line 39). Also shows gmail_search_personal as a sibling for context.
    @mcp.tool()
    def gmail_search_personal(query: str, max_results: int = 20) -> dict[str, Any]:
        """Search Gmail for the configured personal account."""
        result = _load_or_error("personal")
        if isinstance(result, dict):
            return result
        return gmail_search(result, query, max_results)
  • The _load_or_error helper used by gmail_search_work to load credentials and handle errors.
    def _load_or_error(account: Account):
        """Return credentials or an error envelope if Keychain lookup fails."""
        try:
            return load_credentials(account)
        except RuntimeError as e:
            return {"ok": False, "error": str(e), "code": 401}
  • api.py:35-96 (helper)
    The gmail_search function that performs the actual Gmail API search. Called by gmail_search_work after credentials are loaded.
    def gmail_search(
        creds: Credentials,
        query: str,
        max_results: int = 20,
    ) -> dict[str, Any]:
        """Search Gmail and return message summaries."""
        from google.auth.exceptions import RefreshError
        from googleapiclient.discovery import build
    
        max_results = min(max_results, 50)
    
        try:
            service = build("gmail", "v1", credentials=creds)
    
            list_response = (
                service.users()
                .messages()
                .list(userId="me", q=query, maxResults=max_results)
                .execute(num_retries=3)
            )
    
            messages = list_response.get("messages", [])
            results: list[dict[str, Any]] = []
    
            for msg in messages:
                detail = (
                    service.users()
                    .messages()
                    .get(
                        userId="me",
                        id=msg["id"],
                        format="metadata",
                        metadataHeaders=["From", "Subject", "Date"],
                    )
                    .execute(num_retries=3)
                )
    
                headers = {
                    h["name"]: h["value"] for h in detail.get("payload", {}).get("headers", [])
                }
    
                results.append(
                    {
                        "id": detail["id"],
                        "thread_id": detail["threadId"],
                        "from": headers.get("From", ""),
                        "subject": headers.get("Subject", ""),
                        "date": headers.get("Date", ""),
                        "snippet": detail.get("snippet", ""),
                        "labels": detail.get("labelIds", []),
                    }
                )
    
            return {"ok": True, "data": results}
    
        except HttpError as e:
            return _parse_http_error(e)
        except RefreshError as e:
            return {"ok": False, "error": f"token refresh failed: {e}", "code": 401}
        except Exception as e:
            return {"ok": False, "error": f"upstream failure: {type(e).__name__}", "code": 503}
  • Configuration including Account type literal ('personal'|'work') and KEYCHAIN_SERVICES mapping used to resolve 'work' credentials.
    """Shared configuration for the google-mcp server."""
    from __future__ import annotations
    
    import os
    from pathlib import Path
    from typing import Literal
    
    _HERE = Path(__file__).parent
    CREDENTIALS_PATH = _HERE / "credentials.json"
    
    Account = Literal["personal", "work"]
    
    KEYCHAIN_SERVICES: dict[Account, str] = {
        "personal": "google-mcp-personal",
        "work": "google-mcp-work",
    }
    
    # Narrowest scopes covering the four tools: Gmail metadata/snippet search,
    # calendar listing (to filter by accessRole), and event reads.
    SCOPES = [
        "https://www.googleapis.com/auth/gmail.readonly",
        "https://www.googleapis.com/auth/calendar.calendarlist.readonly",
        "https://www.googleapis.com/auth/calendar.events.readonly",
    ]
    
    ACCOUNT_EMAIL_ENVS: dict[Account, str] = {
        "personal": "GOOGLE_MCP_PERSONAL_EMAIL",
        "work": "GOOGLE_MCP_WORK_EMAIL",
    }
    
    WORK_CALENDAR_FILTER_ENV = "GOOGLE_MCP_WORK_CALENDAR"
    
    
    def get_expected_email(account: Account) -> str | None:
        """Return expected email for account from environment, if configured."""
        env_name = ACCOUNT_EMAIL_ENVS[account]
        value = os.getenv(env_name, "").strip()
        return value or None
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided; description carries full burden. It only restates the tool's purpose without disclosing any behavioral traits like authentication needs, rate limits, or what happens with empty results.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Description is a single, concise sentence that fits the space. However, it lacks structure and could include additional details without sacrificing brevity.

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?

Given 2 parameters, 0% schema coverage, and output schema present, the description fails to provide sufficient context about output, search syntax, or limitations. Agent must rely on parameter names alone.

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?

Schema coverage is 0%, so description should compensate. It does not explain 'max_results' (e.g., default behavior, maximum allowed) beyond the schema's default value. The 'query' parameter is implicit but not elaborated.

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 verb 'Search' and resource 'Gmail' and distinguishes from sibling 'gmail_search_personal' by specifying 'work account'. However, it does not specify whether it searches only emails or all Gmail data, leaving slight ambiguity.

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?

No guidance on when to use this tool vs its sibling 'gmail_search_personal' or other tools. The description does not mention prerequisites, limitations, or contexts where this tool is appropriate.

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/giantrotta24/multi-account-google-mcp'

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