# MCP

An agent can use the API as tools. Each method is one tool, and the key decides what the agent may do.

## Connect a client

The MCP server is part of the API, at `/v1/mcp`. It speaks MCP over HTTP and takes the key in the `Authorization` header, like every other request. Most clients need only the address and that header. This is the entry for Claude Code, in `.mcp.json`.

```json
{
  "mcpServers": {
    "opensend": {
      "type": "http",
      "url": "https://api.opensend.sh/v1/mcp",
      "headers": {
        "Authorization": "Bearer os_..."
      }
    }
  }
}
```

> Give an agent a key of its own. A `sending` key lets it send and nothing else, and revoking the key cuts the agent off.

## Tools

A tool is named after its method: `emails.send` is `emails_send`, and `apiKeys.create` is `api_keys_create`. Its input is the input of the method, and its description says what it does. Each tool also says whether it only reads, whether it destroys something, and whether it reaches outside the workspace, as sending does.

`tools/list` gives the tools the key may use and no others: a `sending` key sees the tools that send, and a full key sees them all. A call the key may not make still gets an answer, an error with the code `forbidden`.

Each tool carries the name of its method under `_meta`, as `opensend/method`, so a program can tie a tool to the same method in this reference.

```bash
curl -X POST "$OPENSEND_API_URL/v1/mcp" \
  -H "Authorization: Bearer $OPENSEND_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"domains_list","arguments":{"status":"pending"}}}'
```

The answer holds the result twice: as `structuredContent`, and as text for clients that read only text. A refused call has `isError` set and says why as text. It also carries the error as `structuredContent.error`, with the `type`, `code` and `message` the REST API answers with, so a program can branch on the code.

## Check a call first

To learn whether a call would be taken without running it, send it with `opensend/check` set to `true` under `_meta`, next to `name` and `arguments`.

```bash
curl -X POST "$OPENSEND_API_URL/v1/mcp" \
  -H "Authorization: Bearer $OPENSEND_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"domains_create","arguments":{"name":"updates.example.com"},"_meta":{"opensend/check":true}}}'
```

The server checks that the key may use the tool and that the input is valid, runs nothing, and answers. An input that would be refused comes back as the same error a real call gives. It cannot tell you what only running can, such as a domain that is already added.

> This is an addition of OpenSend, not a part of MCP. The server names it under `capabilities.experimental` when it answers `initialize`, so a client can look before it relies on it.

## Protocol

- One `POST` to `/v1/mcp` carries a JSON-RPC 2.0 message, or a list of them, and the answer is plain JSON.
- The server speaks the protocol versions `2025-06-18`, `2025-03-26`, `2024-11-05`.
- It answers `initialize`, `ping`, `tools/list` and `tools/call`. It has tools only: no resources and no prompts.

## What is not a tool

Closing a workspace is not a tool, so a mistake of a model cannot wipe one. The assistant and its kept chats are not tools either: the assistant is not one of its own tools.

## The assistant

OpenSend has an assistant of its own, and it is a client of this same server. It starts a connection, reads `tools/list` and calls the tools like any other agent, so a tool that exists here is one the assistant can use, with nothing else to set up. It acts as the person who asks, with their permissions.

Ask it a question and it looks the answer up. It never changes anything by itself: it checks a change first, the change comes back as a proposal, and it runs only when you send it back.

cURL:

```bash
curl -X POST "$OPENSEND_API_URL/v1/ask" \
  -H "Authorization: Bearer $OPENSEND_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "messages": [
    {
      "role": "user",
      "text": "Which domains are not verified yet?"
    }
  ]
}'
```

TypeScript:

```ts
await opensend.ask.send({
  messages: [
    {
      role: 'user',
      text: 'Which domains are not verified yet?',
    },
  ],
})
```

CLI:

```bash
opensend ask send \
  --messages '[{"role":"user","text":"Which domains are not verified yet?"}]'
```

ask.send:

```json
{
  "object": "ask_answer",
  "text": "Two domains are not verified yet: news.example.com is pending and example.org failed its last check.",
  "steps": [
    {
      "call": "domains.list",
      "title": "List domains",
      "ok": true
    }
  ],
  "proposal": null,
  "result": null
}
```

## Every tool

| Tool | What it does |
| --- | --- |
| emails_send | Send email |
| emails_batch | Send emails in a batch |
| emails_update | Reschedule email |
| emails_cancel | Cancel email |
| emails_get | Retrieve email |
| emails_list | List emails |
| inbound_list | List received emails |
| inbound_get | Retrieve received email |
| domains_create | Add domain |
| domains_verify | Verify domain |
| domains_get | Retrieve domain |
| domains_list | List domains |
| domains_update | Update domain |
| domains_remove | Delete domain |
| templates_create | Create template |
| templates_get | Get template |
| templates_list | List templates |
| templates_update | Update template |
| templates_edit | Edit template design |
| templates_publish | Publish template |
| templates_test | Send test of template |
| templates_render | Render template design |
| templates_duplicate | Duplicate template |
| templates_versions | List template versions |
| templates_version | Get template version |
| templates_restore | Restore template version |
| templates_remove | Delete template |
| templates_starters | List template starters |
| templates_starter | Get template starter |
| images_add | Add image |
| images_upload | Upload image |
| images_list | List images |
| images_get | Retrieve image |
| images_remove | Delete image |
| broadcasts_create | Create broadcast |
| broadcasts_update | Update broadcast |
| broadcasts_send | Send broadcast |
| broadcasts_test | Send test of broadcast |
| broadcasts_duplicate | Duplicate broadcast |
| broadcasts_get | Retrieve broadcast |
| broadcasts_list | List broadcasts |
| broadcasts_remove | Delete broadcast |
| audiences_create | Create audience |
| audiences_list | List audiences |
| audiences_get | Retrieve audience |
| audiences_update | Rename audience |
| audiences_remove | Delete audience |
| audiences_join | Add contact to audience |
| audiences_leave | Remove contact from audience |
| contacts_create | Add contact |
| contacts_list | List contacts |
| contacts_get | Retrieve contact |
| contacts_update | Update contact |
| contacts_remove | Delete contact |
| contact_properties_create | Create contact property |
| contact_properties_list | List contact properties |
| contact_properties_get | Retrieve contact property |
| contact_properties_update | Update contact property |
| contact_properties_remove | Delete contact property |
| topics_create | Create topic |
| topics_list | List topics |
| topics_get | Retrieve topic |
| topics_update | Update topic |
| topics_remove | Delete topic |
| suppressions_create | Suppress an address |
| suppressions_list | List suppressed addresses |
| suppressions_remove | Remove a suppressed address |
| automations_create | Create automation |
| automations_update | Update automation |
| automations_publish | Publish automation |
| automations_pause | Pause automation |
| automations_resume | Resume automation |
| automations_test | Test automation |
| automations_enroll | Enrol in automation |
| automations_duplicate | Duplicate automation |
| automations_get | Retrieve automation |
| automations_list | List automations |
| automations_remove | Delete automation |
| runs_list | List runs |
| runs_get | Retrieve run |
| runs_cancel | Cancel run |
| runs_retry | Retry run |
| events_send | Send event |
| events_create | Define event |
| events_list | List events |
| events_get | Retrieve event |
| events_update | Update event |
| events_remove | Delete event |
| webhooks_create | Add webhook |
| webhooks_list | List webhooks |
| webhooks_update | Update webhook |
| webhooks_remove | Delete webhook |
| webhooks_test | Send test event |
| webhooks_deliveries | List webhook deliveries |
| metrics_get | Retrieve metrics |
| logs_list | List logs |
| logs_get | Retrieve log |
| api_keys_create | Create API key |
| api_keys_enroll | Enroll existing API key |
| api_keys_list | List API keys |
| api_keys_remove | Revoke API key |
| imports_inspect | Look into another account |
| imports_create | Start import |
| imports_get | Retrieve import |
| imports_list | List imports |
| imports_cancel | Cancel import |
| workspace_get | Retrieve workspace |
| workspace_update | Update workspace |
| members_invite | Invite member |
| members_list | List members |
| members_update | Update member |
| members_remove | Remove member |
| billing_plans | List plans |
| billing_checkout | Start checkout |
| billing_portal | Open billing portal |
| billing_invoices | List invoices |
| server_get | Retrieve server settings |
| account_get | Retrieve account |
| methods_list | List methods |
