Skip to main content
Glama
ggiraudon
by ggiraudon

search

Find emails in a specified folder using criteria like sender, recipient, subject, date range, and message status to locate specific messages.

Instructions

Searches for messages in the specified folder matching the parameters set in searchOptions. Available search options are: from, to, subject, since, before, unseen, flagged, answered, custom. It returns a list of ids that can then be used to get individual messages based on their id.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
folderYes
fromNo
toNo
subjectNo
sinceNo
beforeNo

Implementation Reference

  • The async execute function that implements the core logic of the 'search' tool: validates input, parses search options, connects to IMAP, performs the search via controller, and returns message IDs as JSON.
    async execute(args, context) { if (!args || typeof args !== 'object' || !('folder' in args)) { throw new Error("Missing required arguments"); } const searchOptions = MailSearchOptionSchema.parse(args); const controller = ImapControllerFactory.getInstance(); await controller.connect(); const ids = await controller.search(args.folder, searchOptions); return JSON.stringify({ ids }); }
  • Zod schema defining the input parameters for the 'search' tool (used as parameters in Tool object). Note: some options are commented out here but handled via internal schema.
    export const SearchInput = z.object({ folder: z.string().min(2).max(100), from: z.string().optional(), to: z.string().optional(), subject: z.string().optional(), since: z.coerce.date().optional(), before: z.coerce.date().optional(), // unseen: z.boolean().optional(), // flagged: z.boolean().optional(), // answered: z.boolean().optional(), });
  • Internal Zod schema used in the handler to parse full search options, including additional flags like unseen, flagged, answered, and custom.
    export const MailSearchOptionSchema = z.object({ from: z.string().optional(), to: z.string().optional(), subject: z.string().optional(), since: z.coerce.date().optional(), before: z.coerce.date().optional(), unseen: z.boolean().optional(), flagged: z.boolean().optional(), answered: z.boolean().optional(), custom: z.any().optional(), });
  • src/index.ts:54-54 (registration)
    Registration of the SearchFolderTool (named 'search') with the FastMCP server.
    server.addTool(SearchFolderTool);
  • src/index.ts:14-14 (registration)
    Import of the SearchFolderTool in the main index file.
    import { SearchFolderTool } from "./tools/SearchFolderTool.js";

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/ggiraudon/emailMCPServer'

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