Skip to main content
Glama

search_emails

Search emails by keyword with optional inbox filtering. Returns matching messages from your default or specified inbox.

Instructions

Search emails by keyword. If inbox_id is omitted, uses the default inbox.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inbox_idNoInbox ID (optional, uses default inbox)
queryYesSearch query

Implementation Reference

  • mcp/index.js:240-257 (registration)
    MCP tool registration for 'search_emails' using server.tool(). Registers the tool with name 'search_emails', description 'Search emails by keyword. If inbox_id is omitted, uses the default inbox.', an optional inbox_id schema and a required query string schema. The handler calls the API endpoint GET /v1/inboxes/${inbox_id}/search?q=${query}.
    server.tool(
      'search_emails',
      'Search emails by keyword. If inbox_id is omitted, uses the default inbox.',
      {
        inbox_id: idSchema.optional().describe('Inbox ID (optional, uses default inbox)'),
        query: z.string().describe('Search query')
      },
      async ({ inbox_id, query }) => {
        if (!inbox_id) {
          const inbox = await getOrCreateDefaultInbox();
          if (inbox.error) return { content: [{ type: 'text', text: JSON.stringify(inbox, null, 2) }] };
          inbox_id = inboxId(inbox);
        }
        const params = new URLSearchParams({ q: query });
        const result = await api('GET', `/v1/inboxes/${inbox_id}/search?${params}`);
        return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
      }
    );
  • Input schema for the search_emails tool. Defines optional inbox_id (number or numeric string via idSchema) and required query (string) parameters.
    {
      inbox_id: idSchema.optional().describe('Inbox ID (optional, uses default inbox)'),
      query: z.string().describe('Search query')
    },
  • Core database function that executes the email search. Uses SQL with LIKE queries on subject, text_content, and from_addr columns, ordered by created_at descending with a limit (default 20).
    export function searchEmails({ inboxId, query, limit = 20 }) {
      const like = `%${query}%`;
      const stmt = db.prepare(`
        SELECT * FROM emails
        WHERE inbox_id = ? AND (subject LIKE ? OR text_content LIKE ? OR from_addr LIKE ?)
        ORDER BY created_at DESC LIMIT ?
      `);
      stmt.bind([inboxId, like, like, like, limit]);
      const rows = [];
      while (stmt.step()) rows.push(formatEmail(stmt.getAsObject()));
      stmt.free();
      return rows;
    }
  • REST API endpoint handler for GET /v1/inboxes/:inboxId/search. Parses query params q and limit, validates the inbox exists and belongs to the user, and delegates to the searchEmails function from db.js.
    // === ๆœ็ดข ===
    
    app.get('/v1/inboxes/:inboxId/search', (req, res) => {
      try {
        const inbox = getInboxById(req.params.inboxId, req.user.id);
        if (!inbox) return res.status(404).json({ error: 'Inbox not found' });
    
        const { q, limit = 20 } = req.query;
        if (!q) return res.status(400).json({ error: 'q (query) is required' });
    
        const results = searchEmails({ inboxId: inbox.id, query: q, limit: parseInt(limit) });
        res.json(results);
      } catch (err) {
        res.status(500).json({ error: err.message });
      }
    });
  • Import of searchEmails from db.js into the Express server (src/index.js), used by the REST API route.
    getEmails, getEmailById, markAsRead, insertEmail, searchEmails,
    getThreads, getThreadMessages,
Behavior2/5

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

With no annotations, the description carries full transparency burden. It only discloses that omitted inbox_id defaults to the default inbox, but fails to mention search scope (subject/body), case sensitivity, error handling, or return format.

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 sentence with no extraneous words, front-loading the core purpose.

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 the lack of annotations and output schema, the description is too brief. It omits expected return values, pagination, sorting, and potential limitations, leaving agents uninformed about behavior.

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 description adds no new information beyond what the schema already provides. The phrase 'by keyword' gives a slight hint about query semantics, but otherwise is redundant.

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 'Search emails by keyword' with a specific verb and resource. It also notes the default inbox behavior, distinguishing it from siblings like list_messages or read_email.

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 keyword searches and explains the default inbox behavior, but it does not provide explicit when-to-use or when-not-to-use guidance, nor does it reference sibling 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/joansongjr/clawaimail'

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