MCP Server

The mails-agent MCP (Model Context Protocol) server gives AI assistants like Claude Desktop, Cursor, and Windsurf the ability to send, receive, and manage email. It exposes 10 tools that the AI can call directly.

Installation

Run the MCP server directly with npx (no global install needed):

npx mails-agent-mcp

Or install globally:

npm install -g mails-agent-mcp
mails-agent-mcp

Configuration

Claude Desktop

Add the following to your claude_desktop_config.json:

{
  "mcpServers": {
    "mails-agent": {
      "command": "npx",
      "args": ["mails-agent-mcp"],
      "env": {
        "MAILS_API_KEY": "mk_your_api_key"
      }
    }
  }
}

Config file locations:

Cursor

Add the MCP server in Cursor settings under Features → MCP Servers:

{
  "mcpServers": {
    "mails-agent": {
      "command": "npx",
      "args": ["mails-agent-mcp"],
      "env": {
        "MAILS_API_KEY": "mk_your_api_key"
      }
    }
  }
}

Windsurf

Add to your Windsurf MCP configuration (~/.windsurf/mcp_config.json):

{
  "mcpServers": {
    "mails-agent": {
      "command": "npx",
      "args": ["mails-agent-mcp"],
      "env": {
        "MAILS_API_KEY": "mk_your_api_key"
      }
    }
  }
}

Self-hosted API

If you self-host mails-agent, add the API URL to the environment:

{
  "mcpServers": {
    "mails-agent": {
      "command": "npx",
      "args": ["mails-agent-mcp"],
      "env": {
        "MAILS_API_KEY": "mk_your_api_key",
        "MAILS_API_URL": "https://your-worker.your-domain.workers.dev"
      }
    }
  }
}

Tools

The MCP server exposes 10 tools. After configuration, the AI assistant can call any of these directly.

send_email

Send an email from your mailbox.

ParameterTypeRequiredDescription
tostring[]YesRecipient email addresses
subjectstringYesEmail subject
textstringNo*Plain text body
htmlstringNo*HTML body
ccstring[]NoCC recipients
bccstring[]NoBCC recipients
in_reply_tostringNoMessage ID for threading

* At least one of text or html is required.

get_inbox

List recent emails.

ParameterTypeRequiredDescription
limitnumberNoMax results (default 20)
offsetnumberNoPagination offset

search_emails

Semantic search across emails.

ParameterTypeRequiredDescription
querystringYesNatural language search query
limitnumberNoMax results (default 10)

get_email

Get a single email by ID.

ParameterTypeRequiredDescription
idstringYesEmail message ID

delete_email

Delete a single email.

ParameterTypeRequiredDescription
idstringYesEmail message ID

wait_for_code

Wait for a verification code to arrive. Polls the inbox until a code is extracted or the timeout is reached.

ParameterTypeRequiredDescription
timeoutnumberNoMax seconds to wait (default 60)
senderstringNoOnly match codes from this sender

get_threads

List email threads.

ParameterTypeRequiredDescription
limitnumberNoMax results (default 20)
offsetnumberNoPagination offset

get_thread

Get all messages in a thread.

ParameterTypeRequiredDescription
thread_idstringYesThread ID

get_me

Get information about the authenticated key and mailbox. No parameters.

extract_data

Extract structured data from an email using AI.

ParameterTypeRequiredDescription
message_idstringYesEmail message ID
typestringYesExtraction type: order, shipping, calendar, receipt, or code

Usage Examples

Once configured, you can ask your AI assistant to perform email tasks in natural language:

How It Works

The MCP server runs as a local process and communicates with the AI client via the Model Context Protocol (stdio transport). It translates tool calls from the AI into mails-agent API requests.

AI Assistant  --MCP-->  mails-agent-mcp  --HTTP-->  mails-agent API
   (Claude)            (local process)            (Cloudflare Worker)

The MCP server itself is stateless. All state lives in the mails-agent API. The server needs only the API key to function.

Troubleshooting

Tools not appearing

Authentication errors

Timeout on wait_for_code