Skip to main content
Glama

gmail_search

Search your Gmail inbox using Gmail's query syntax to find emails by sender, subject, date, attachments, or read status.

Instructions

Search emails using Gmail query syntax. Returns a list of matching emails with subject, sender, date, and snippet. Use Gmail search operators like 'from:', 'to:', 'subject:', 'is:unread', 'has:attachment', 'after:', 'before:'.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesGmail search query string. Examples: 'from:john@example.com', 'subject:meeting is:unread', 'after:2024/01/01 has:attachment'.
max_resultsNoMaximum number of emails to return. Must be between 1 and 100. Default is 20.

Implementation Reference

  • Registration of the gmail_search tool including its schema definition within the list_tools() function.
    Tool(
        name="gmail_search",
        description="Search emails using Gmail query syntax or natural language. "
        "Examples: 'from:john@example.com', 'subject:meeting', 'is:unread'",
        inputSchema={
            "type": "object",
            "properties": {
                "query": {
                    "type": "string",
                    "description": "Gmail search query or natural language search",
                },
                "max_results": {
                    "type": "integer",
                    "description": "Maximum number of results (default: 20, max: 100)",
                    "default": 20,
                },
            },
            "required": ["query"],
        },
    ),
  • Handler implementation in call_tool() that parses arguments, calls GmailClient.search_emails(), formats results with _format_email_list, and returns TextContent.
    if name == "gmail_search":
        query = arguments.get("query", "")
        max_results = arguments.get("max_results", 20)
        results = await client.search_emails(query, max_results)
        return [
            TextContent(
                type="text",
                text=_format_email_list(results),
            )
        ]
  • GmailClient.search_emails method: converts tool parameters to SearchQuery object and delegates to list_emails() which performs the actual Gmail API search.
    async def search_emails(self, query: str, max_results: int = 20) -> list[EmailSummary]:
        """Simple search interface for natural language queries."""
        search = SearchQuery(query=query, max_results=max_results)
        return await self.list_emails(search)
  • Helper function to format the list of EmailSummary objects returned from search into a readable text response.
    def _format_email_list(emails: list) -> str:
        """Format email list for display."""
        if not emails:
            return "No emails found."
    
        lines = [f"Found {len(emails)} email(s):\n"]
        for email in emails:
            status = "📬" if not email.is_read else "📭"
            star = "⭐" if email.is_starred else ""
            attachment = "📎" if email.has_attachments else ""
            categories = f" [{', '.join(email.categories)}]" if email.categories else ""
    
            lines.append(
                f"{status}{star}{attachment} **{email.subject}**{categories}\n"
                f"   From: {email.sender}\n"
                f"   Date: {email.date.strftime('%Y-%m-%d %H:%M')}\n"
                f"   ID: `{email.id}`\n"
                f"   {email.snippet[:100]}...\n"
            )
        return "\n".join(lines)
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It discloses that the tool returns a list of emails with specific fields (subject, sender, date, snippet) and mentions Gmail search operators, which adds useful context. However, it lacks details on permissions needed, rate limits, pagination, or error handling for a search operation.

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

Conciseness5/5

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

The description is appropriately sized and front-loaded, with two sentences that efficiently convey purpose, return value, and usage examples without unnecessary details. Every sentence earns its place by providing essential information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (search with two parameters), no annotations, and no output schema, the description is mostly complete. It covers purpose, usage, and return fields, but could improve by addressing behavioral aspects like permissions or limitations. It compensates well for the lack of structured data.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already fully documents the two parameters (query and max_results). The description adds minimal value beyond the schema by mentioning Gmail search operators, which are implied in the schema's examples. Baseline score of 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verb ('Search') and resource ('emails'), and distinguishes it from siblings by focusing on search functionality rather than labeling, reading, sending, or other operations. It explicitly mentions what it returns (list of matching emails with specific fields).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use this tool (searching emails with Gmail query syntax) and includes examples of search operators. However, it does not explicitly state when not to use it or name specific alternatives among the sibling tools (e.g., gmail_list_unread for a simpler unread list).

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/murphy360/mcp_gmail'

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