Skip to main content
Glama

gmail_list_unread

Retrieve unread emails from your Gmail inbox, with optional filtering by categories like financial, action_required, kids, or navy to organize messages.

Instructions

List unread emails from the inbox. Optionally filter by a pre-configured category such as navy, kids, financial, or action_required.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
categoryNoFilter by category name. Must be one of: navy, kids, financial, action_required. Leave empty for all unread emails.
max_resultsNoMaximum number of emails to return. Default is 20.

Implementation Reference

  • Primary handler logic for the 'gmail_list_unread' tool. Parses input arguments, constructs a SearchQuery object with is_unread=True and optional category filter, invokes GmailClient.list_emails, formats the results using _format_email_list, and returns as TextContent.
    elif name == "gmail_list_unread":
        category = arguments.get("category")
        max_results = arguments.get("max_results", 20)
        search = SearchQuery(
            is_unread=True,
            category=category,
            max_results=max_results,
        )
        results = await client.list_emails(search)
        return [TextContent(type="text", text=_format_email_list(results))]
  • JSON schema definition for the 'gmail_list_unread' tool inputs: optional 'category' (string enum) and 'max_results' (integer). Defines the tool interface for MCP clients.
    Tool(
        name="gmail_list_unread",
        description="List unread emails from the inbox. Optionally filter by a pre-configured category such as navy, kids, financial, or action_required.",
        inputSchema={
            "type": "object",
            "properties": {
                "category": {
                    "type": "string",
                    "description": "Filter by category name. Must be one of: navy, kids, financial, action_required. Leave empty for all unread emails."
                },
                "max_results": {
                    "type": "integer",
                    "description": "Maximum number of emails to return. Default is 20."
                }
            },
            "required": []
        },
    ),
  • Registers all tools including 'gmail_list_unread' by returning the predefined GMAIL_TOOLS list from the list_tools handler decorated with @server.list_tools().
    @server.list_tools()
    async def list_tools() -> list[Tool]:
        return GMAIL_TOOLS
  • Core helper method implementing the email listing logic. Builds Gmail API search query (adds 'is:unread' if specified), fetches messages, parses into EmailSummary, applies category filtering post-fetch, handles API errors.
    async def list_emails(self, search: SearchQuery) -> list[EmailSummary]:
        """List emails matching search criteria."""
        query = self._build_query(search)
        logger.info(f"Searching emails with query: {query}")
    
        try:
            results = (
                self.service.users()
                .messages()
                .list(userId="me", q=query, maxResults=search.max_results)
                .execute()
            )
    
            messages = results.get("messages", [])
            if not messages:
                return []
    
            # Fetch each message's metadata
            summaries = []
            for msg_ref in messages:
                msg = (
                    self.service.users()
                    .messages()
                    .get(userId="me", id=msg_ref["id"], format="metadata")
                    .execute()
                )
                email = self._parse_message(msg)
    
                # Filter by category if specified
                if search.category:
                    if search.category not in email.categories:
                        continue
    
                summaries.append(self._email_to_summary(email))
    
            return summaries
        except HttpError as e:
            logger.error(f"Failed to list emails: {e}")
            raise
  • Pydantic model defining the SearchQuery used by the tool, including fields like category, is_unread, and max_results for structured query building and validation.
    class SearchQuery(BaseModel):
        """Search query parameters."""
    
        query: Optional[str] = Field(default=None, description="Gmail search query")
        sender: Optional[str] = Field(default=None, description="Filter by sender")
        subject: Optional[str] = Field(default=None, description="Filter by subject")
        labels: list[str] = Field(default_factory=list, description="Filter by labels")
        category: Optional[str] = Field(default=None, description="Filter by our category")
        is_unread: Optional[bool] = Field(default=None, description="Filter by read status")
        has_attachment: Optional[bool] = Field(default=None)
        after_date: Optional[datetime] = Field(default=None)
        before_date: Optional[datetime] = Field(default=None)
        max_results: int = Field(default=20, ge=1, le=100)
Behavior2/5

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

With no annotations provided, the description carries full burden but only states what the tool does, not behavioral traits like whether it's read-only, requires authentication, has rate limits, or returns paginated results. It mentions 'pre-configured categories' but doesn't explain how these are set up or their impact.

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 two concise sentences with zero waste. The first sentence states the core purpose, and the second adds optional functionality. It's front-loaded and appropriately sized for a simple listing tool.

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

Completeness3/5

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

For a read operation with 2 parameters and 100% schema coverage but no output schema or annotations, the description is minimally adequate. It covers what the tool does but lacks context about return format, error handling, or behavioral constraints that would be helpful for an agent.

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 both parameters. The description adds marginal value by mentioning 'pre-configured category' and listing examples, but doesn't provide additional semantics beyond what's in the schema descriptions. Baseline 3 is appropriate when schema does the heavy lifting.

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 the verb ('List') and resource ('unread emails from the inbox'), making the purpose immediately understandable. It distinguishes from siblings like 'gmail_search' by focusing specifically on unread emails, though it doesn't explicitly contrast with 'gmail_get_priorities' or 'gmail_inbox_stats' which might also involve email retrieval.

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

Usage Guidelines3/5

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

The description implies usage for listing unread emails with optional category filtering, but provides no explicit guidance on when to use this tool versus alternatives like 'gmail_search' or 'gmail_get_priorities'. It mentions categories but doesn't explain when to filter by them versus using other tools.

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