Skip to main content
Glama
p-l-ta

mail-mcp

by p-l-ta

get_unsubscribe_link

Read-only

Extract the unsubscribe link from an email by checking the List-Unsubscribe header, then scanning the message body if the header is absent.

Instructions

Extract unsubscribe URLs from a message — checks the List-Unsubscribe header first (reliable), then scans the plain-text body as a fallback.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
message_idYesRFC message-id (with or without angle brackets)

Implementation Reference

  • The register function that implements the get_unsubscribe_link tool. It receives a message_id, finds the message via AppleScript, extracts the raw source + body content, and parses out List-Unsubscribe header URLs and body URLs that look like unsubscribe links.
    export function register(server: McpServer): void {
      server.tool(
        "get_unsubscribe_link",
        "Extract unsubscribe URLs from a message — checks the List-Unsubscribe header first (reliable), then scans the plain-text body as a fallback.",
        schema,
        { title: "Get Unsubscribe Link", readOnlyHint: true, destructiveHint: false },
        async ({ message_id }) => {
          const bareId = message_id.replace(/^<|>$/g, "");
          const raw = await runAppleScript({
            script: SCRIPT,
            args: { theMsgId: bareId },
            timeoutMs: 30_000,
          });
          if (raw === "NOTFOUND") {
            return {
              content: [{ type: "text", text: `No message found with id ${message_id}` }],
              isError: true,
            };
          }
          const urls = extractUnsubscribeUrls(raw);
          return {
            content: [{ type: "text", text: JSON.stringify(urls, null, 2) }],
          };
        },
      );
    }
  • Input schema for the tool: requires a 'message_id' string (RFC message-id, with or without angle brackets).
    const schema = {
      message_id: z.string().describe("RFC message-id (with or without angle brackets)"),
    };
  • src/server.ts:16-36 (registration)
    Import of the get_unsubscribe_link registration function.
    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);
    registerSend(server);
    registerReply(server);
    registerFlags(server);
    registerMove(server);
    registerTrash(server);
    registerCreateMailbox(server);
    registerBulkMarkRead(server);
    registerGetUnsubscribeLink(server);
  • src/server.ts:36-36 (registration)
    Registration call: registerGetUnsubscribeLink(server) wires the tool into the MCP server.
    registerGetUnsubscribeLink(server);
  • Helper function extractUnsubscribeUrls that parses the raw source to find List-Unsubscribe header URLs and scans the plain-text body for URLs containing unsubscribe/opt-out keywords.
    export function extractUnsubscribeUrls(raw: string): { header: string[]; body: string[] } {
      const splitIdx = raw.indexOf(SPLIT);
      const headers = splitIdx >= 0 ? raw.slice(0, splitIdx) : raw;
      const body = splitIdx >= 0 ? raw.slice(splitIdx + SPLIT.length) : "";
    
      const header: string[] = [];
      const bodyUrls: string[] = [];
    
      // List-Unsubscribe header may be folded (continuation lines start with whitespace)
      const match = headers.match(/^List-Unsubscribe:[ \t]*((?:[^\r\n]|\r?\n[ \t])*)/im);
      if (match) {
        const value = (match[1] ?? "").replace(/\r?\n[ \t]+/g, " ");
        for (const m of value.matchAll(/<([^>]+)>/g)) {
          if (m[1]) header.push(m[1]);
        }
      }
    
      // Scan plain-text body for URLs that look like unsubscribe links
      const urlRe = /https?:\/\/[^\s<>"')\]]+/g;
      for (const m of body.matchAll(urlRe)) {
        const url = m[0].replace(/[.,;]+$/, "");
        if (/unsubscribe|opt.?out|optout|remove/i.test(url) && !header.includes(url) && !bodyUrls.includes(url)) {
          bodyUrls.push(url);
        }
      }
    
      return { header, body: bodyUrls };
    }
Behavior4/5

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

Annotations already indicate read-only and non-destructive. The description adds value by detailing the two-step extraction process (header then body), which informs the agent of reliability and fallback behavior.

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?

One efficient sentence that front-loads the purpose and quickly adds methodological detail. No wasted words.

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

Completeness3/5

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

Lacks output format specification (e.g., returns a URL string or null), but the extraction process is well-described. Given no output schema, more detail on return value would improve completeness.

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 coverage is 100% for the single parameter, with a clear description. The tool description adds no extra detail about the parameter beyond what the schema provides.

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 extracts unsubscribe URLs from a message, specifying the method (header first, then body fallback). It distinguishes itself from sibling tools, which are all different email operations.

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?

No explicit guidance on when to use vs alternatives. The context implies usage when needing an unsubscribe link, but no comparisons to other tools are given.

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