Skip to main content
Glama
p-l-ta

mail-mcp

by p-l-ta

list_recent

Read-only

Retrieve recent emails from a specified mailbox in your Mail.app account. Filter by number of messages or show only unread ones.

Instructions

List recent messages in a mailbox of a specific account.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
accountYesAccount name as shown in Mail.app
mailboxNoINBOX
limitNo
unread_onlyNo

Implementation Reference

  • The register function that registers the 'list_recent' tool with the MCP server. The handler executes an AppleScript to list recent messages in a specified mailbox, parses the output, and returns it as JSON.
    export function register(server: McpServer): void {
      server.tool(
        "list_recent",
        "List recent messages in a mailbox of a specific account.",
        schema,
        { title: "List Recent Emails", readOnlyHint: true, destructiveHint: false },
        async ({ account, mailbox, limit, unread_only }) => {
          const raw = await runAppleScript({
            script: SCRIPT,
            args: {
              acctName: account,
              mbName: mailbox,
              limStr: String(limit),
              unreadOnlyStr: unread_only ? "true" : "false",
            },
          });
          return {
            content: [{ type: "text", text: JSON.stringify(parse(raw), null, 2) }],
          };
        },
      );
  • Zod schema for the tool's input parameters: account (string), mailbox (string, default INBOX), limit (1-50, default 10), unread_only (boolean, default false).
    const schema = {
      account: z.string().describe("Account name as shown in Mail.app"),
      mailbox: z.string().default("INBOX"),
      limit: z.number().int().min(1).max(50).default(10),
      unread_only: z.boolean().default(false),
    };
  • src/server.ts:8-28 (registration)
    Import and registration of the list_recent tool in the main server file. Line 8 imports register, line 28 calls registerListRecent(server).
    import { register as registerListRecent } from "./tools/list_recent.js";
    import { register as registerSend } from "./tools/send.js";
    import { register as registerReply } from "./tools/reply.js";
    import { register as registerFlags } from "./tools/flags.js";
    import { register as registerMove } from "./tools/move.js";
    import { register as registerTrash } from "./tools/trash.js";
    import { register as registerCreateMailbox } from "./tools/create_mailbox.js";
    import { register as registerBulkMarkRead } from "./tools/bulk_mark_read.js";
    import { register as registerGetUnsubscribeLink } from "./tools/get_unsubscribe_link.js";
    import { register as registerListSenders } from "./tools/list_senders.js";
    import { register as registerEmptyMailbox } from "./tools/empty_mailbox.js";
    
    const server = new McpServer({
      name: "mail-app-mcp",
      version: "1.0.0",
    });
    
    registerSearch(server);
    registerRead(server);
    registerAccounts(server);
    registerListRecent(server);
  • The runAppleScript helper used by the handler to execute the AppleScript via osascript with safe argument passing.
    export async function runAppleScript(opts: RunAppleScriptOptions): Promise<string> {
      const { script, args = {}, timeoutMs = 30_000 } = opts;
    
      const argNames = Object.keys(args);
      const argValues = argNames.map((n) => args[n]!);
    
      const bindings = argNames
        .map((name, i) => `  set ${name} to item ${i + 1} of argv`)
        .join("\n");
    
      const wrapped = `on run argv\n${bindings}\n${script}\nend run\n`;
    
      const dir = await mkdtemp(path.join(tmpdir(), "mail-mcp-"));
      const scriptPath = path.join(dir, "script.applescript");
      try {
        await writeFile(scriptPath, wrapped, "utf8");
        const { stdout } = await execFileP("osascript", [scriptPath, ...argValues], {
          timeout: timeoutMs,
          maxBuffer: 10 * 1024 * 1024,
        });
        return stdout.trimEnd();
      } finally {
        await rm(dir, { recursive: true, force: true }).catch(() => {});
      }
    }
  • The parse function that transforms the raw AppleScript output (field-separated lines) into an array of RecentMsg objects with subject, from, date, unread, and messageId.
    function parse(raw: string): RecentMsg[] {
      const out: RecentMsg[] = [];
      for (const line of raw.split("\n")) {
        if (!line) continue;
        const parts = line.split(FIELD_SEP);
        if (parts.length < 5) continue;
        out.push({
          subject: parts[0] ?? "",
          from: parts[1] ?? "",
          date: parts[2] ?? "",
          unread: parts[3] === "true",
          messageId: parts[4] ?? "",
        });
      }
      return out;
    }
Behavior3/5

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

Annotations already indicate readOnlyHint=true and destructiveHint=false. Description adds no further behavioral traits like sorting order or time window.

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?

Single clear sentence with no superfluous words. Efficiently conveys 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?

No output schema, so return format unspecified. Lacks details on message ordering, time range for 'recent', or default mailbox behavior.

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

Parameters2/5

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

Schema description coverage is only 25% (only 'account' described). Description does not add meaning to any parameter beyond schema.

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?

Description clearly states verb 'List' and resource 'recent messages in a mailbox of a specific account'. It distinguishes from siblings like 'search_emails' and '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 Guidelines2/5

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

No explicit guidance on when to use this tool vs alternatives like 'search_emails' for filtering. Only implies usage for recent messages.

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/p-l-ta/mail-mcp'

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