Skip to main content
Glama

search_emails

Find specific emails in your Gmail inbox using standard query syntax like 'is:unread' or 'from:example@email.com'. Control the maximum number of results returned.

Instructions

Search emails using Gmail query syntax

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesGmail search query (e.g., 'is:unread', 'from:newsletter@example.com')
maxResultsNoMaximum number of results (default: 10)

Implementation Reference

  • Zod schema defining the input for search_emails: 'query' (string) and 'maxResults' (number, optional, default 10).
    search_emails: z.object({
        query: z.string().describe("Gmail search query (e.g., 'is:unread', 'from:newsletter@example.com')"),
        maxResults: z.number().optional().default(10).describe("Maximum number of results (default: 10)")
    }),
  • src/tools.ts:50-55 (registration)
    getToolDefinitions() maps all schemas including search_emails into MCP tool definitions with name, description, and inputSchema.
    export const getToolDefinitions = () => 
        Object.entries(schemas).map(([name, schema]) => ({
            name,
            description: toolDescriptions[name],
            inputSchema: zodToJsonSchema(schema)
        }));
  • The case 'search_emails' in handleToolCall: validates args, calls gmailService.searchEmails(query, maxResults), and returns formatted text results with email ID, subject, from, date, snippet, and Gmail URL.
    case "search_emails": {
        const v = validated as z.infer<typeof schemas.search_emails>;
        const results = await gmailService.searchEmails(v.query, v.maxResults);
        return { content: [{ type: "text", text: results.length ? 
            results.map(e => `ID: ${e.id}\nSubject: ${e.subject}\nFrom: ${e.from}\nDate: ${e.date}\nSnippet: ${e.snippet}\nGmail URL: ${gmailService.getEmailUrl(e.id)}\n`).join('---\n') : 
            "No emails found." }] };
    }
  • GmailService.searchEmails(): Calls Gmail API users.messages.list with query/maxResults, then fetches metadata for each message (Subject, From, To, Date headers) and returns EmailInfo[].
    async searchEmails(query: string, maxResults = 10): Promise<EmailInfo[]> {
        const { data } = await this.gmail.users.messages.list({ userId: 'me', q: query, maxResults });
        if (!data.messages?.length) return [];
        
        return Promise.all(data.messages.map(async (msg) => {
            const { data: detail } = await this.gmail.users.messages.get({
                userId: 'me',
                id: msg.id!,
                format: 'metadata',
                metadataHeaders: ['Subject', 'From', 'To', 'Date']
            });
            const h = detail.payload?.headers || [];
            const findHeader = (name: string) => h.find(x => x.name === name)?.value || '';
            return {
                id: msg.id!,
                threadId: detail.threadId,
                subject: findHeader('Subject'),
                from: findHeader('From'),
                to: findHeader('To'),
                date: findHeader('Date'),
                snippet: detail.snippet || ''
            };
        }));
    }
Behavior2/5

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

No annotations are provided, so the description must disclose behavioral traits. It only states it searches, without mentioning that it is read-only or what it returns. This is a significant gap for a search tool.

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 a single, direct sentence with no fluff. It efficiently conveys the tool's action and method.

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?

The tool lacks an output schema, yet the description does not explain what the search returns (e.g., email metadata, full content). This leaves the agent uncertain about the return value, a critical gap for a search tool.

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

Parameters4/5

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

The input schema already describes both parameters (query and maxResults) with 100% coverage. The description adds value by specifying 'Gmail query syntax', clarifying the expected format for the query parameter.

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 searches emails using a specific syntax (Gmail query). This distinguishes it from sibling tools like read_email (single email) and delete_email (deletion).

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 implies usage for searching with Gmail syntax, but does not explicitly compare to alternatives like list_labels or read_email. It provides clear context but lacks explicit when-not-to-use guidance.

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/muammar-yacoob/GMail-Manager-MCP'

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