Skip to main content
Glama
p-l-ta

mail-mcp

by p-l-ta

list_senders

Read-only

Group senders by message count, unread count, and last arrival time to identify bulk senders and reduce mailbox noise.

Instructions

Return a grouped count of senders in a mailbox — who sends how many messages, how many are unread, and when the last arrived. Ideal for identifying bulk senders and noise.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
mailboxNoMailbox name or URL substring to restrict to (e.g. 'Amtrak', 'INBOX')
accountNoAccount host/name substring to restrict to
limitNoMax senders to return, ordered by message count desc

Implementation Reference

  • The register function that registers the 'list_senders' tool with the MCP server and contains the full handler logic (lines 44-66). It receives {mailbox, account, limit}, builds a SQL query via buildSql, executes it against the Envelope Index SQLite database, and returns a JSON string of senders with address, name, message count, unread count, and last received timestamp.
    export function register(server: McpServer): void {
      server.tool(
        "list_senders",
        "Return a grouped count of senders in a mailbox — who sends how many messages, how many are unread, and when the last arrived. Ideal for identifying bulk senders and noise.",
        schema,
        { title: "List Senders", readOnlyHint: true, destructiveHint: false },
        async ({ mailbox, account, limit }) => {
          const dbPath = await locateEnvelopeIndex();
          const sql = buildSql(mailbox, account, limit);
          const rows = await querySqlite<SenderRow>(dbPath, sql);
          const result = rows.map((r) => ({
            address: r.sender_address,
            name: r.sender_name || null,
            count: Number(r.message_count),
            unread: Number(r.unread_count),
            lastReceived: r.last_received ? new Date(r.last_received * 1000).toISOString() : null,
          }));
          return {
            content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
          };
        },
      );
    }
  • Zod schema for the tool's input parameters: mailbox (optional string), account (optional string), limit (optional number, default 50, min 1, max 500).
    const schema = {
      mailbox: z.string().optional().describe("Mailbox name or URL substring to restrict to (e.g. 'Amtrak', 'INBOX')"),
      account: z.string().optional().describe("Account host/name substring to restrict to"),
      limit: z.number().int().min(1).max(500).default(50).describe("Max senders to return, ordered by message count desc"),
    };
  • src/server.ts:17-37 (registration)
    Import and registration of the list_senders tool on the McpServer instance (line 17 imports, line 37 registers).
    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);
    registerSend(server);
    registerReply(server);
    registerFlags(server);
    registerMove(server);
    registerTrash(server);
    registerCreateMailbox(server);
    registerBulkMarkRead(server);
    registerGetUnsubscribeLink(server);
    registerListSenders(server);
  • The buildSql function that constructs the SQL query to aggregate senders by address/comment with message count, unread count, and last received date, filtered by mailbox/account substring and deleted flag.
    export function buildSql(mailbox?: string, account?: string, limit = 50): string {
      const where: string[] = ["m.deleted = 0"];
      if (mailbox) where.push(`mb.url LIKE '%${sqlEscape(mailbox)}%'`);
      if (account) where.push(`mb.url LIKE '%${sqlEscape(account)}%'`);
      return `
        SELECT
          a.address                                        AS sender_address,
          a.comment                                        AS sender_name,
          COUNT(*)                                         AS message_count,
          SUM(CASE WHEN m.read = 0 THEN 1 ELSE 0 END)     AS unread_count,
          MAX(m.date_received)                             AS last_received
        FROM messages m
        LEFT JOIN addresses a  ON a.ROWID = m.sender
        LEFT JOIN mailboxes mb ON mb.ROWID = m.mailbox
        WHERE ${where.join(" AND ")}
        GROUP BY a.address, a.comment
        ORDER BY message_count DESC
        LIMIT ${Math.max(1, Math.floor(limit))};
      `;
    }
  • The sqlEscape utility function used to safely escape single quotes in SQL string literals.
    function sqlEscape(v: string): string {
      return v.replace(/'/g, "''");
    }
Behavior5/5

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

Annotations declare readOnlyHint=true and destructiveHint=false, indicating a safe read operation. The description adds behavioral details: returns grouped counts with unread and last arrival info, and ordering by message count descending. No contradictions.

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?

Two sentences, front-loaded with the key purpose and outcome. Every word adds value, no redundancy.

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

Completeness4/5

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

The description adequately covers purpose, usage, and behavioral details for a tool with 3 optional parameters and no output schema. It could briefly mention the output format (e.g., a list of objects), but the grouped count nature is inferable.

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 baseline is 3. The description provides context for the output but does not add significant meaning beyond the schema descriptions for parameters. The ordering hint is already implied by the limit default.

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 it returns a grouped count of senders in a mailbox, including message counts, unread counts, and last arrival times. It distinguishes itself from sibling tools like list_recent or search_emails by focusing on sender aggregation.

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 says 'Ideal for identifying bulk senders and noise,' which implies when to use it, but does not explicitly mention when not to use it or compare to alternatives. The context is clear but lacks exclusions.

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