# MCP server for AI agents

MarleyFetch runs an [MCP](https://modelcontextprotocol.io) server at
`https://api.marleyfetch.com/mcp`. Connect an agent to it and it can check your plan and limits,
send email, manage templates and audiences, and run batches itself instead of writing API calls.
Email goes out through your own [SMTP connection](https://docs.marleyfetch.com/guides/connections.md), from your own address.

## Connect by signing in

**In Claude Code**, add the server, then run `/mcp` inside Claude Code and authenticate:

```bash
claude mcp add --transport http marleyfetch https://api.marleyfetch.com/mcp
```

**In Claude on the web or desktop**, and other MCP clients that support OAuth, add a custom
connector with the URL `https://api.marleyfetch.com/mcp`.

A browser window opens. Sign in with the Google account you use for the dashboard, pick the
connection the agent may send from, and choose **Allow**. You need at least one active
[SMTP connection](https://docs.marleyfetch.com/guides/connections.md) first.

Allowing creates an API key named `MCP: <app name>`, locked to that connection. It lasts 90 days,
after which the agent asks you to sign in again.

## Connect with an API key

For CI and other places without a browser, send an API key in a header instead:

```bash
claude mcp add --transport http marleyfetch https://api.marleyfetch.com/mcp \
  --header "Authorization: Bearer $MARLEYFETCH_API_KEY"
```

To share it with a project, commit a `.mcp.json`. The key stays in each person's environment:

```json
{
  "mcpServers": {
    "marleyfetch": {
      "type": "http",
      "url": "https://api.marleyfetch.com/mcp",
      "headers": { "Authorization": "Bearer ${MARLEYFETCH_API_KEY}" }
    }
  }
}
```

Give the agent its own key [locked to one connection](https://docs.marleyfetch.com/guides/api-keys.md#locking-a-key-to-one-connection),
so it can only send as that address.

## Tools

Each tool calls the matching REST endpoint with your key, so the same plan gates, quotas and error
codes apply. Pro-only tools return `FEATURE_NOT_AVAILABLE` on the Free plan.

| Tool | Does | Endpoint | Plan |
| --- | --- | --- | --- |
| `get_account` | Plan, limits, and the connections the agent can send from with their quotas | [`GET /v1/account`](https://docs.marleyfetch.com/reference/limits.md#checking-your-plan-and-usage) | All |
| `send_email` | Send one email to up to 10 recipients | [`POST /v1/send`](https://docs.marleyfetch.com/guides/sending.md) | All |
| `send_template_email` | Send a saved template by name, passing only its variables | [`POST /v1/send/template`](https://docs.marleyfetch.com/guides/templates.md#send-a-template-by-name) | All (`enqueue`: Pro) |
| `enqueue_email` | Queue an email; if the connection's quota is used up, it's sent when the quota resets | [`POST /v1/enqueue`](https://docs.marleyfetch.com/guides/sending.md#post-v1-enqueue) | Pro |
| `list_templates`, `get_template` | Read saved templates | [`GET /v1/templates`](https://docs.marleyfetch.com/guides/templates.md) | All |
| `create_template` | Save a template with `{{placeholders}}` | `POST /v1/templates` | All (Free: 3) |
| `list_audiences`, `create_audience` | Read and create recipient lists | [`/v1/audiences`](https://docs.marleyfetch.com/guides/audiences.md) | Pro |
| `add_audience_members` | Add members with per-member variables | `POST /v1/audiences/{id}/members` | Pro |
| `send_batch` | Send a template or content to an audience or up to 1,000 addresses | [`POST /v1/send/batch`](https://docs.marleyfetch.com/guides/batches.md) | Pro |
| `get_batch` | Follow a batch's progress | `GET /v1/batches/{id}` | Pro |

When the agent connects, the server tells it to call `get_account` first, so it knows your limits
before it plans a send. On Pro it's also told to queue non-urgent or many emails with
`enqueue_email`, and anything `send_email` couldn't send because of a quota or rate limit, and to
use `send_email` when it needs to confirm delivery.

## What the agent can and can't do

With its key, an agent can:

- send from the one connection the key is locked to, including batches to your audiences on Pro
- see your plan, usage, templates and audiences, and create templates and audiences.

It can't read your inbox, because MarleyFetch only sends. It can't send from your other
connections, and every email counts against your plan and the connection's quota. Everything it
sends appears in your delivery log.

Claude Code asks your permission before each tool call unless you allow the tool permanently. If
you allow a sending tool, the agent can send without asking, including from `/loop` and
scheduled runs.

## Disconnecting an agent

Delete its `MCP: <app name>` key on the [API keys](https://docs.marleyfetch.com/guides/api-keys.md) page. Its next call fails, and
the agent has to be connected again.

## Example prompts

- "What's my MarleyFetch plan and how much quota is left?"
- "Run the tests. If anything fails, email me the failing tests and the errors."
- "Summarize what we changed today and email it to the team."
- "Save a template called Welcome that greets `{{first_name}}`, then send it to the Beta testers
  audience."
- "Draft a follow-up to alice@example.com about the migration. Show me before sending."
