Skip to content
send.io
All posts

How to connect the send.io MCP server to Claude Code with scoped API keys

Add MCP server to Claude Code with claude mcp add, secure it with scoped API keys, and debug handshake failures in production. Get runnable commands, annotated .mcp.json configs, env var expansion for secrets, per inbox scoped keys, and fixes for 401, 403, malformed JSON, and missing env errors.

On this page
TL;DR: Register the send.io hosted MCP server with claude mcp add --transport http sendio https://api.send.io/mcp and authenticate with a send.io API key passed as the bearer token. For team repos, store config in .mcp.json and inject the key via environment variable, never hardcode it. Verify with /mcp inside Claude Code, then test a tool call. Scope keys per inbox or pod so an agent cannot read or send from unrelated mailboxes. Most handshake failures trace to malformed JSON, missing env vars, or a key whose scope does not include the tool.

Most MCP setup guides stop at "it connected." That is not enough when wiring an AI agent to email infrastructure. A working connection means the server responded to a handshake. A safe connection means the agent can only touch the inbox it was provisioned for, the key is not sitting in a config file, and you know exactly what breaks when it breaks.

This guide covers how to register the send.io MCP server with Claude Code using the claude mcp add CLI command, a project-scope .mcp.json file, or the user-level config file. It also covers how to verify the handshake and how to scope API keys so an agent cannot reach mailboxes it should not. Every documented command is runnable as written, and placeholder endpoints are marked.

Preparing your environment for MCP integration

Before registering the server, confirm that Claude Code, your send.io credentials, and the hosted endpoint are all ready. The next sections cover prerequisites, API key creation, and a direct handshake test.

System prerequisites for Claude MCP tools

You need Claude Code installed and authenticated, with the claude CLI on your PATH. Run claude --version to confirm. You do not need an SDK. The send.io hosted MCP server runs over HTTP, so the only requirement is a valid API key and network access to api.send.io.

For send.io, setup depends on the path you are evaluating. The send.io API reference describes the sending flow as create an API key, add your domain, then call POST /emails. The agent mailbox flow can be tried without an account, an API key, or a card.

Setting up send.io for Claude Code

Create an API key in the send.io dashboard at app.send.io. Keys differ by access level: an admin key gives broad, account-level access and should be reserved for provisioning work, while a scoped key is limited to specific permissions and resources, such as a single inbox or a pod of inboxes. Confirm the key types available to your account in the dashboard before you create one.

Start with an admin key to provision your first agent inbox, then switch to a scoped key for the actual Claude Code connection. The send.io MCP documentation covers the available tools and authentication model.

Testing send.io protocol integration

Before opening Claude Code, confirm the hosted MCP endpoint responds. Send a minimal JSON-RPC 2.0 initialize call:

curl -X POST https://api.send.io/mcp \
-H "Authorization: Bearer $SENDIO_API_KEY" \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"test","version":"0.1"}}}'

A healthy response returns a JSON-RPC result with the server's capabilities and protocol version. A 401 means your key is invalid or revoked. A connection refused usually points to a wrong URL or port in the request, so check the endpoint against the send.io MCP documentation before assuming a network fault. The examples in this guide use https://api.send.io/mcp, but confirm the current endpoint path in the documentation before running them.

Registration methods for the send.io MCP server in Claude Code

Claude Code supports three registration paths for the send.io MCP server, and each one stores configuration and secrets differently. The sections below walk through each method, then compare them so you can pick the right one for your project.

Method 1: Quick add via Claude Code CLI

A quick way to add an MCP server is the claude mcp add command. It registers the server at local scope by default, and the --scope flag can target project or user scope instead:

claude mcp add --transport http sendio https://api.send.io/mcp \
--header "Authorization: Bearer $SENDIO_API_KEY"

The --transport http flag tells Claude Code to use Streamable HTTP, which is what the send.io hosted MCP server speaks. The --header flag passes the bearer token inline. Claude Code confirms:

Added HTTP MCP server "sendio" with URL: https://api.send.io/mcp

This stores the key in plain text in a local-scope entry in ~/.claude.json, filed under the project's path. For personal projects on a single machine, that may be acceptable. For anything that touches a shared repo or CI, use the project-scope method instead.

Method 2: Project-scope JSON config

Create a .mcp.json file in your repo root. Claude Code reads this file when you start a session in that directory:

{
"mcpServers": {
"sendio": {
"type": "http",
"url": "https://api.send.io/mcp",
"headers": {
"Authorization": "Bearer ${SENDIO_API_KEY}"
}
}
}
}

The ${SENDIO_API_KEY} syntax expands the environment variable at runtime, keeping the key out of the repo. Commit .mcp.json and add SENDIO_API_KEY to your team's environment setup docs or secrets manager.

When the same MCP server is defined in more than one scope, Claude Code connects once and uses the definition from the highest-precedence source: local scope first, then project scope, then user scope. Local-scope and user-scope entries are both stored in ~/.claude.json, but local-scope entries are filed under the project's path while user-scope entries apply to every project. A local-scope server can therefore outrank the .mcp.json definition for the same project. .mcp.json is still the right default for team repos, CI pipelines, and any setup where multiple engineers need the same configuration, because the file travels with the repo.

Method 3: Persistent user-level setup

If you want the send.io MCP server available across all your projects without adding a .mcp.json to each one, edit the user-level config file directly: ~/.claude.json on macOS and Linux, %USERPROFILE%\.claude.json on Windows. Add the same server block:

{
"mcpServers": {
"sendio": {
"type": "http",
"url": "https://api.send.io/mcp",
"headers": {
"Authorization": "Bearer ${SENDIO_API_KEY}"
}
}
}
}

User-level config is useful for personal projects and single-machine setups. The trade-off is that it is invisible to the team and does not travel with the repo.

Matching methods to project needs

Method

Scope

Portability

Secret handling

Best for

claude mcp add

Local by default (use --scope for project or user)

Low (per machine)

Plain text in config

Quick personal testing

.mcp.json

Project scope (stored in .mcp.json at the repo root)

High (can be committed to the repo)

Env var expansion

Team repos, CI, production

User scope (~/.claude.json)

User scope (applies to every project)

Low (per machine)

Plain text unless you reference an environment variable. Expansion is documented for .mcp.json only

Personal projects, single machine

For anything that touches production inboxes or shared infrastructure, use .mcp.json with environment variable expansion. The file lives in version control, the key does not, and every engineer gets the same server configuration without manual setup.

Quick-start guide to Claude MCP server additions

This section collects the full claude mcp add syntax and the environment variable patterns that keep your key out of the config file. It ends with how to confirm the registration worked.

Command syntax for secure MCP injection

The full claude mcp add command for an HTTP MCP server with environment variable support:

claude mcp add --transport http sendio https://api.send.io/mcp \
--header 'Authorization: Bearer ${SENDIO_API_KEY}' \
--env SENDIO_API_KEY=${SENDIO_API_KEY}

Breaking down each flag:

  • --transport http: Uses Streamable HTTP transport. Required for the send.io hosted MCP server.
  • sendio: The server name, used in /mcp and claude mcp remove.
  • https://api.send.io/mcp: The canonical hosted MCP server endpoint.
  • --header: Sets the Authorization header, passing your send.io API key as the bearer token.
  • --env: Passes an environment variable to the server process. Not strictly needed for HTTP transport, but useful if you later add local stdio servers that need the key.

Passing environment variables inline

You can pass environment variables directly in the command:

claude mcp add --transport http sendio https://api.send.io/mcp \
--env SENDIO_API_KEY=mx_...

This writes the key value into the config file, a security risk if the file is ever committed, shared, or backed up to a cloud sync service. The safer pattern references a shell variable that expands at runtime:

export SENDIO_API_KEY=mx_...
claude mcp add --transport http sendio https://api.send.io/mcp \
--header 'Authorization: Bearer ${SENDIO_API_KEY}'

The single quotes matter. Bash and zsh expand ${VAR} inside double quotes before the CLI runs, so a double-quoted header would write the expanded key into the config in plain text. With single quotes, the shell passes ${SENDIO_API_KEY} through unchanged, and the config file stores ${SENDIO_API_KEY}that variable reference, not the key itself. Claude Code expands the reference from your shell environment at startup and warns if the variable is unset, so set it before you launch Claude Code.

Validating your MCP server connection

Inside a Claude Code session, run /mcp to list all registered MCP servers and their connection status. A healthy send.io registration looks like this:

sendio: ✔ Connected

If the server is listed but not connected, the status label tells you where to look. Claude Code documents these labels in /mcp:

  • ! Needs authentication: The server responded but did not accept the credentials. Confirm the environment variable is set and the key is valid and not revoked.
  • sendio: registered,✘ Failed to connect: The server was found in the config but did not complete the handshake. Check the config file for JSON syntax errors and verify the URL is https://api.send.io/mcp.
  • ⏸ Pending approval: A server defined in a project-scoped .mcp.json stays pending until someone approves it in that workspace. Approve it when Claude Code prompts you, or from the /mcp menu. Each engineer who clones the repo approves it once.
  • ✘ Rejected (disabledMcpjsonServers): The server was rejected in this workspace and is listed in the disabledMcpjsonServers setting. Remove it from that setting to re-enable it.
  • ⊘ Disabled for this project: The server is turned off for the current project. Re-enable it from /mcp.

If the server does not appear in the list at all, registration failed. Check the config file for JSON syntax errors, confirm the environment variable is set, and verify the URL is https://api.send.io/mcp.

Constraining agent access with .mcp.json

A .mcp.json file defines which servers Claude Code loads for a repo and how each one authenticates. The sections below show the file structure, explain each field send.io needs, and cover how to keep the key out of version control.

Defining the .mcp.json file structure

A complete .mcp.json file for the send.io MCP server:

{
"mcpServers": {
"sendio": {
"type": "http",
"url": "https://api.send.io/mcp",
"headers": {
"Authorization": "Bearer ${SENDIO_API_KEY}"
}
}
}
}

Field by field:

  • mcpServers: Top-level object that holds all server definitions.
  • sendio: The server name, used in /mcp output and claude mcp remove.
  • type: "http": Transport type. Claude Code expects "http" for remote MCP servers like the hosted send.io endpoint.
  • url: The endpoint URL. Must be https://api.send.io/mcp.
  • headers: HTTP headers sent with every request. The Authorization header carries your bearer token.
  • env: Environment variables passed to the server context at process start. Not shown above because the hosted send.io server authenticates through headers and does not need it. You would only add this block for a local stdio server.

Defining your .mcp.json server config

The send.io-specific block carries the bearer token in headers.Authorization, which is the correct place for HTTP transport. The env block serves a different purpose: it passes environment variables to local stdio servers at process start, so you can leave it out for the hosted send.io server.

Securing sensitive keys in .mcp.json

Never commit a real API key to version control. Use environment variable expansion so the config file contains a variable reference, not the key value. If you are using a secrets manager (1Password CLI, Doppler, AWS Secrets Manager), inject the key into the environment before starting Claude Code.

Add .mcp.json to your repo, but add SENDIO_API_KEY to your .env.example or onboarding docs with a placeholder value. Each engineer sets their own key locally.

Securing your MCP server credentials

Rotate keys on a schedule. When you rotate, issue the replacement key first and deploy it before revoking the old one, so active sessions do not lose access mid-rotation. If a key is compromised, revoke it, issue a new one, update the environment variable, and restart Claude Code to pick up the new key.

Setting up scoped API keys per inbox

A connected agent is only as safe as the key it holds. This section explains why an admin key is too broad for Claude Code and how to provision keys limited to a single inbox or pod.

Preventing credential leakage per inbox

A single admin-level API key grants access to every mailbox, domain, and setting on your account. If that key leaks, the attacker has full control. If you use it in a Claude Code config, the agent can theoretically call any tool the MCP server exposes, including tools that read or send from other inboxes.

The fix is a scoped API key. A scoped key is tied to a single inbox or a single pod of inboxes. It cannot access resources outside its scope, and it cannot grant permissions it does not hold. This is the control that prevents an agent from reading or replying from mailboxes it should not touch.

Provisioning inbox-specific API keys

Create an agent inbox with a scoped key by calling POST /v0/inboxes on the send.io API:

curl -X POST https://api.send.io/v0/inboxes \
-H "Authorization: Bearer $SENDIO_ADMIN_KEY" \
-H "Content-Type: application/json" \
-d '{
"username": "support-agent",
"domain": "agents.yourcompany.com"
}'

The documented create-inbox response returns a credentials field: an IMAP/SMTP login whose password is an API key scoped to this inbox, shown only once. The JSON below is an illustrative shape rather than a verified schema. Confirm the exact field names inside credentials against the send.io API reference before parsing the response in code:

{
"id": "inbox_abc123",
"address": "support-agent@agents.yourcompany.com",
"credentials": {
"username": "support-agent@agents.yourcompany.com",
"password": "mx_..."
}
}

Whatever the exact field names, store any returned credentials immediately, since provisioning responses typically show secrets only once. An inbox-scoped key can read, send from, and manage only its own inbox. It cannot reach other inboxes, domains, or account settings. The agent mailbox documentation covers the full provisioning flow and the self-signup pattern for agents that provision their own inboxes.

Protecting inbox data with scoped keys

Scoped keys carry permission lists. According to the send.io documentation, a key scoped to a single inbox can call tools that read messages, send replies, and manage that inbox's settings. It cannot call tools that create new inboxes, modify other inboxes, or access account-level settings like domain management or API key administration.

Only admin-level keys can create, change, or delete other keys. An agent running with an inbox-scoped key cannot escalate its own privileges by provisioning a new key with broader permissions.

Preventing unauthorized mailbox traversal

If you run multiple agent inboxes for different customers or projects, group them into inbox pods. A pod acts as an isolation boundary: a pod-level API key is designed to see and manage only the inboxes within that pod, not inboxes in other pods or account-level settings.

Create a pod with POST /pods, as documented in the send.io API reference:

curl -X POST https://api.send.io/pods \
-H "Authorization: Bearer $SENDIO_ADMIN_KEY" \
-H "Content-Type: application/json" \
-d '{"name": "customer-acme"}'

Then create inboxes within that pod with POST /pods/{pod}/inboxes, and issue the pod's API key with POST /pods/{pod}/api-keys. To list your existing pods, call GET /v0/pods. The pod's API key sees only the inboxes in the customer-acme pod, so if you run 20 customer pods, a compromised key for one pod does not expose the other 19.

Debugging your Claude Code MCP handshake

When the handshake fails, the cause is usually in the config file or the key itself. This section shows how to list registrations, run a test tool call, and diagnose the most common failures.

Listing active MCP server registrations

The /mcp command inside Claude Code shows all registered servers with name, connection status, and tool count. The documented statuses are pending, connected, failed, needs-auth, and disabled. A server showing "failed" was found in the config but did not complete the initial handshake. A server showing "connected" responded successfully and its tools are available.

If a server does not appear at all, the config file has a syntax error or the server definition is missing required fields. Check .mcp.json or the user-level config for JSON validity.

Testing the MCP server connection

From inside Claude Code, make a minimal tool call to verify the connection:

List the inboxes the sendio MCP server can access.

A successful call returns a JSON array of inboxes visible to the scoped key. A 403 means the key is valid but lacks permission for that tool. A 401 means the key is invalid or revoked. A timeout means the server did not respond before the client's deadline, which points to a slow or lost response rather than a bad URL. Some clients report this as MCP error -32001, the RequestTimedOut code in the MCP TypeScript SDK, but the number you see depends on the client. A wrong URL or unreachable endpoint more often surfaces as a 404, 405, or connection refused error.

Diagnosing MCP server handshake failures

The three most common causes:

  1. Malformed JSON in .mcp.json: Trailing commas, unescaped quotes, or missing closing braces. Run the file through a JSON validator.
  2. Missing environment variable: The ${SENDIO_API_KEY} reference cannot expand because the variable is not set. Run echo $SENDIO_API_KEY to confirm.
  3. Wrong transport type: The config specifies "type": "stdio" but the send.io hosted server requires "type": "http".

Each failure produces a different symptom. Malformed JSON shows a parse error with a line number. A missing environment variable does not produce a parse-time error: Claude Code warns that the variable is unset, naming it in claude mcp list output and in /mcp, and still loads the server with the literal ${SENDIO_API_KEY} text. The server then receives Bearer ${SENDIO_API_KEY} in the Authorization header and rejects it with a 401. Wrong transport shows a connection error because stdio expects a local process, not a URL.

Debugging failed MCP connections and service sync

Some failures appear only after registration succeeds, such as permission denials on specific tools or configuration errors in .mcp.json. The sections below map each symptom to its cause and fix.

Validating API key scopes and usage

Check what a key can do in the send.io dashboard, and confirm its scope (admin, inbox-scoped, or pod-scoped) and permissions against the send.io API reference. A 403 on a tool call means the key lacks the permission that tool requires. For example, an inbox-scoped key is limited to its own inbox, so a tool that creates new inboxes is likely to return a 403. Confirm the exact tool names and the permission each one requires in the send.io MCP documentation.

For an email OTP flow, the scoped key model works well because the agent only needs access to the inbox that receives verification codes, not the entire account.

Fixing malformed .mcp.json files

Common JSON errors in .mcp.json:

Before (broken):

{
"mcpServers": {
"sendio": {
"type": "http",
"url": "https://api.send.io/mcp",
"headers": {
"Authorization": "Bearer ${SENDIO_API_KEY}",
}
}
}
}

After (fixed):

{
"mcpServers": {
"sendio": {
"type": "http",
"url": "https://api.send.io/mcp",
"headers": {
"Authorization": "Bearer ${SENDIO_API_KEY}"
}
}
}
}

The trailing comma after the Authorization value is the error. JSON does not allow trailing commas. Most editors with JSON support will flag this automatically.

Fixing variable expansion failures in .mcp.json

If Claude Code reports it cannot expand ${SENDIO_API_KEY}, the variable is not set in your shell:

# bash/zsh
export SENDIO_API_KEY=mx_...

# Add to ~/.bashrc or ~/.zshrc for persistence
echo 'export SENDIO_API_KEY=mx_...' >> ~/.zshrc

For team environments, use a .env file with direnv or a secrets manager CLI. The transactional email best practices guide covers environment variable management for API keys across deployment environments.

Fixing broken send.io connection strings

The canonical MCP endpoint is https://api.send.io/mcp. If you see connection refused or DNS errors, check the URL. Common mistakes:

  • Using http instead of https
  • Omitting the /mcp path
  • Using the REST API base URL without the /mcp suffix

For production use, always use https://api.send.io/mcp.

Debugging MCP server permission denials

A 403 on a specific tool call means the key is valid but lacks the permission. Reissue the key with the correct scope or use an admin key for admin-only tools. If your agent needs to create new inboxes on demand, it needs an admin key. If it only needs to read and reply from one inbox, an inbox-scoped key is sufficient.

Symptom

Likely cause

Fix

403 invalid_permission error on a tool call

The key or your role may not do this, for example a key restricted to another domain, or an action only an admin can take

Reissue the key with the permission that tool requires, or use an admin key for admin-only actions

JSON parse error

Malformed .mcp.json

Validate JSON, remove trailing commas

Missing-variable warning in claude mcp list or /mcp, then a 401 from the server

${SENDIO_API_KEY} not set, so the server receives the literal Bearer ${SENDIO_API_KEY}

Export the variable in your shell profile and restart Claude Code

Connection refused

Wrong URL or network issue

Verify URL is https://api.send.io/mcp

Managing and revoking MCP server connections

Keys rotate, projects end, and credentials sometimes leak. This section covers how to update a token, remove a server registration, and cut off access for a compromised key.

Update auth tokens without server reset

To rotate an API key, remove the old registration and add it again:

claude mcp remove sendio
claude mcp add --transport http sendio https://api.send.io/mcp \
--header "Authorization: Bearer ${SENDIO_API_KEY_NEW}"

With .mcp.json, update the environment variable value and restart Claude Code. The config file does not need to change because it references the variable, not the key value.

Purging stale MCP server integrations

Remove a server you no longer need:

claude mcp remove sendio

This removes the server definition from your configuration. Without a scope flag, claude mcp remove targets local scope, and the CLI reports "Removed MCP server … from local config." To remove a server from another scope, pass --scope with user or project, for example claude mcp remove sendio --scope holdsuseruser. Local scope is tied to the project directory, so run the command inside that project. If the server is defined in .mcp.json, deleting the server block from the file also works.

Force logout of MCP server sessions

Revoking an API key is designed to invalidate it immediately, so any Claude Code session using that key should start receiving 401 responses on the next tool call. The session may cache the old key until you restart Claude Code, so restart after revoking to clear the cache. This is the fastest way to cut off access if a key is compromised.

Provision an agent inbox with a scoped API key and connect it to Claude Code using the quickstart guide. Test the connection with /mcp and a first tool call before wiring it into a production agent loop.

FAQs

Can the same API key be used across multiple projects?

Yes, but you should not. A shared key means a leak in one project exposes every project. Provision a separate scoped key per project or per inbox. The send.io API reference covers key management.

What happens if a scoped key is revoked mid-session?

Tool calls return 401 once the key is revoked or otherwise invalid. Issue a replacement scoped key, update the environment variable, and restart Claude Code. The session does not auto-refresh credentials, and it may keep using the old key until you restart.

How do you test the server without exposing production inboxes?

Point Claude Code at a dedicated test inbox protected by its own scoped key, so a mistake in testing never touches production mail. Because the scoped key can only reach the inbox it was provisioned for, you can run full tool calls against the live MCP server without exposing customer or production inboxes.

Does .mcp.json override user-level configuration?

Yes, project scope takes precedence over user-level config. When the same server is defined in more than one scope, Claude Code uses the highest-precedence definition: local scope first, then project scope (.mcp.json), then user scope. A local-scope definition for the same server therefore beats both the .mcp.json entry and the user-level config.

Can Claude Code auto-discover MCP servers from package.json?

No. Claude Code reads .mcp.json or user-level config. It does not scan package.json for MCP server definitions.

Key terms glossary

MCP (Model Context Protocol): An open protocol that standardizes how AI assistants discover and call external tools. send.io exposes email tools through an MCP server.

Scoped API key: A credential limited to specific permissions and resources, such as a single inbox or pod. It cannot grant permissions it does not hold.

Inbox pod: A grouping of agent inboxes that shares an isolation boundary. A pod-level key can only see inboxes within that pod.

Streamable HTTP: A transport for MCP that uses HTTP POST with JSON-RPC 2.0 payloads. The send.io hosted MCP server uses this transport.

Bearer token: An authentication header value sent as Authorization: Bearer <key>. Use a send.io API key, preferably a scoped one, as the token for the send.io MCP server.

.mcp.json: A project-scope configuration file that declares MCP servers for Claude Code. It lives in the repo root and takes precedence over user-level config, but a local-scope definition of the same server takes precedence over it.