Skip to Content
Pouch

MCP

A streamable HTTP MCP endpoint at /mcp, one tool per /v1 route.

A streamable HTTP MCP endpoint at POST /mcp, one tool per exposed /v1 route. It's a wrapper, not a second implementation: every tool call constructs the same Request an HTTP caller of that route would send and calls that route's own exported handler in-process: same validation, same key scoping, same errors. See docs/api/conventions.md for what each route does; this page only covers what's different about reaching it through MCP.

Connecting

POST https://<host>/mcp
Authorization: Bearer <key>
Content-Type: application/json
Accept: application/json, text/event-stream

The endpoint is stateless: every request gets a fresh MCP session, so there's no initialize handshake to hold open between calls. Authentication, rate limiting and X-Request-Id all go through the same withApiKey wrapper /v1 routes use. A tool call and an HTTP call to the same route are charged against the same per-key rate limit, as two separate hits: one for the MCP request itself, one for the /v1 call the tool makes underneath it.

GET and DELETE are accepted for MCP's own session-stream and session-termination semantics; neither does anything Pouch-specific, since there's no session state to stream or terminate.

Tools

lib/mcp/registry.ts pairs each tool with a RouteSpec from lib/api-docs/spec.ts (the same generator #4/#61 built for the API reference) and the same zod schema the route parses its request with. A tool's description, input shape and error list are generated from those, not retyped by hand. The registry throws at load if a tool names a route lib/api-docs/spec.ts doesn't document. The reverse is checked too: tests/unit/mcp-coverage.test.ts fails when a documented route has no tool, unless its NO_TOOL list names the route with a reason.

Every documented route has a tool apart from the three in "No tool" below. A route is never left out because it's destructive: the key that authenticates a tool call is the same key that would authenticate a direct HTTP call, so the MCP wrapper adds no privilege and removes none.

Destructiveness is expressed, not enforced, through MCP's own tool annotations: every tool carries readOnlyHint, destructiveHint and idempotentHint, set per route in lib/mcp/registry.ts. destructiveHint: true is set on every delete, on both unsubscribes (no API call resubscribes an address), on update_domain_inbound, since every call with webhook_url issues a new signing secret, on suspend_organization, since a manual suspension fails queued mail, and on convert_admin_provider, which is undone only by hand in SQL and AWS. A client that wants to prompt or confirm on that has what it needs to. If a delete route needs a guard beyond what /v1 already has (a confirmation step, a soft delete, a refusal when the domain has sent recently), that's a change to /v1 itself, so every caller gets it, not something bolted onto this wrapper for MCP callers alone.

ToolRouteAnnotations
create_domainPOST /v1/domainsnone
list_domainsGET /v1/domainsread-only
read_domainGET /v1/domains/:idread-only
move_domainPATCH /v1/domains/:ididempotent
verify_domainPOST /v1/domains/:id/verifyidempotent
delete_domainDELETE /v1/domains/:iddestructive, idempotent
read_reputationGET /v1/reputationread-only
read_statsGET /v1/statsread-only
send_emailPOST /v1/emailsnone
list_emailsGET /v1/emailsread-only
read_emailGET /v1/emails/:idread-only
resend_emailPOST /v1/emails/:id/resendnone
watch_emailGET /v1/emails/:id/eventsread-only
list_providersGET /v1/providersread-only
read_providerGET /v1/providers/:idread-only
import_suppressionsPOST /v1/suppressionsidempotent
list_suppressionsGET /v1/suppressionsread-only
read_suppressionGET /v1/suppressions/:addressread-only
remove_suppressionDELETE /v1/suppressions/:addressdestructive, idempotent
read_recipientGET /v1/recipients/:addressread-only
create_exportPOST /v1/exportsnone
list_exportsGET /v1/exportsread-only
read_exportGET /v1/exports/:idread-only
create_listPOST /v1/listsnone
list_listsGET /v1/listsread-only
read_listGET /v1/lists/:idread-only
delete_listDELETE /v1/lists/:iddestructive, idempotent
add_list_memberPOST /v1/lists/:id/members (one address)idempotent
import_list_membersPOST /v1/lists/:id/members (members array)idempotent
list_list_membersGET /v1/lists/:id/membersread-only
remove_list_memberDELETE /v1/lists/:id/members/:memberIddestructive, idempotent
export_list_membersGET /v1/lists/:id/exportread-only
unsubscribe_from_listPOST /v1/lists/:id/unsubscribedestructive, idempotent
unsubscribe_from_domainPOST /v1/domains/:id/unsubscribedestructive, idempotent
send_batchPOST /v1/batchesnone
read_batchGET /v1/batches/:idread-only
list_inboundGET /v1/inboundread-only
read_inboundGET /v1/inbound/:idread-only
read_domain_inboundGET /v1/domains/:id/inboundread-only
update_domain_inboundPATCH /v1/domains/:id/inbounddestructive
list_dmarc_reportsGET /v1/domains/:id/dmarc_reportsread-only
create_addressPOST /v1/addressesnone
list_addressesGET /v1/addressesread-only
read_addressGET /v1/addresses/:idread-only
update_addressPATCH /v1/addresses/:idnone
revoke_addressDELETE /v1/addresses/:iddestructive, idempotent
list_address_messagesGET /v1/addresses/:id/messagesread-only
wait_for_mailGET /v1/addresses/:id/messages (wait, 55s by default)read-only
reply_from_addressPOST /v1/addresses/:id/replynone
add_forward_targetPOST /v1/addresses/:id/forward_targetsnone
list_forward_targetsGET /v1/addresses/:id/forward_targetsread-only
read_forward_targetGET /v1/addresses/:id/forward_targets/:targetIdread-only
remove_forward_targetDELETE /v1/addresses/:id/forward_targets/:targetIddestructive, idempotent
resend_forward_confirmationPOST /v1/addresses/:id/forward_targets/:targetId/resend_confirmationnone
create_keyPOST /v1/keysnone
list_keysGET /v1/keysread-only
read_keyGET /v1/keys/:idread-only
update_keyPATCH /v1/keys/:ididempotent
revoke_keyDELETE /v1/keys/:iddestructive, idempotent
create_webhook_endpointPOST /v1/webhook_endpointsnone
list_webhook_endpointsGET /v1/webhook_endpointsread-only
read_webhook_endpointGET /v1/webhook_endpoints/:idread-only
update_webhook_endpointPATCH /v1/webhook_endpoints/:ididempotent
delete_webhook_endpointDELETE /v1/webhook_endpoints/:iddestructive, idempotent
rotate_webhook_secretPOST /v1/webhook_endpoints/:id/rotate_secretdestructive, idempotent
list_webhook_deliveriesGET /v1/webhook_endpoints/:id/deliveriesread-only
read_webhook_deliveryGET /v1/webhook_endpoints/:id/deliveries/:deliveryIdread-only
list_activityGET /v1/activityread-only
read_activityGET /v1/activity/:idread-only
read_organizationGET /v1/organizationread-only
update_organizationPATCH /v1/organizationidempotent

Providers are read-only for organization keys, so they have no create, update, test or delete tools.

The key, endpoint, activity and organization tools need a key with no domain scope, and create_key mints only in the calling key's own mode. Minting an admin key has no tool and no route; see docs/decisions.md.

POST /v1/lists/:id/members takes two JSON shapes, so it has two tools. Its CSV body has no tool; import_list_members takes the same rows as JSON.

export_list_members returns the CSV as the result's text, with no structuredContent. _meta.content_type carries the route's content-type.

send_email takes sensitive, as POST /v1/emails does. read_email and list_emails never return a sensitive message's body, whatever include names; list_emails takes sensitive: "true" to list only those messages.

Admin tools

An admin key (docs/api/admin.md) gets the tools below. It belongs to no organization, so an ordinary tool answers 403 organization_key_required. buildMcpServer registers a tool marked admin: true only when the key's scope is admin, so no other key sees them in tools/list or can call them by name. The route refuses any other key with admin_key_required regardless.

ToolRouteAnnotations
list_admin_providersGET /v1/admin/providersread-only
read_admin_providerGET /v1/admin/providers/:idread-only
create_admin_providerPOST /v1/admin/providersnone
update_admin_providerPATCH /v1/admin/providers/:ididempotent
test_admin_providerPOST /v1/admin/providers/:id/testread-only
setup_admin_providerPOST /v1/admin/providers/:id/setupidempotent
read_admin_conversionGET /v1/admin/providers/:id/convertread-only
convert_admin_providerPOST /v1/admin/providers/:id/convertdestructive, idempotent
delete_admin_providerDELETE /v1/admin/providers/:iddestructive, idempotent
adopt_admin_domainPOST /v1/admin/domainsnone
list_provider_organizationsGET /v1/admin/providers/:id/organizationsread-only
assign_organizationPOST /v1/admin/providers/:id/organizationsidempotent
unassign_organizationDELETE /v1/admin/providers/:id/organizations/:organizationIddestructive, idempotent
list_admin_organizationsGET /v1/admin/organizationsread-only
read_admin_organizationGET /v1/admin/organizations/:idread-only
update_admin_organizationPATCH /v1/admin/organizations/:ididempotent
suspend_organizationPOST /v1/admin/organizations/:id/suspenddestructive, idempotent
release_organizationPOST /v1/admin/organizations/:id/releaseidempotent
create_admin_organizationPOST /v1/admin/organizationsnone
list_organization_membersGET /v1/admin/organizations/:id/membersread-only
update_organization_memberPATCH /v1/admin/organizations/:id/members/:userIdidempotent
remove_organization_memberDELETE /v1/admin/organizations/:id/members/:userIddestructive, idempotent
list_admin_usersGET /v1/admin/usersread-only
read_admin_userGET /v1/admin/users/:idread-only
update_admin_userPATCH /v1/admin/users/:iddestructive, idempotent
delete_admin_userDELETE /v1/admin/users/:iddestructive, idempotent

update_admin_user is marked destructive because revoking the admin flag revokes the admin keys that account created, including the key making the call. remove_organization_member isn't: it removes one membership and leaves the account and its keys alone.

convert_admin_provider returns once the run has started. Call read_admin_conversion until conversion.state is done or failed.

tests/unit/mcp-coverage.test.ts fails when an /v1/admin route has no tool, or when a tool's admin flag doesn't match its path.

Watching a message

watch_email wraps GET /v1/emails/:id/events, the SSE route docs/api/conventions.md describes under "Watching a message: webhooks vs. the stream". A held-open stream has no completed Response for lib/mcp/invoke.ts's request/response pattern to return, so this tool doesn't follow it: lib/mcp/watch.ts's invokeWatchTool still calls the same route handler (same validation, same key scoping, same errors, same concurrent-stream slot from MAX_CONCURRENT_STREAMS_PER_KEY) but reads the SSE frames it writes instead of returning them to the caller as a stream, and folds them into one CallToolResult.

The call blocks, then returns. Up to MCP_WATCH_TIMEOUT_MS (55s by default, comfortably under the tool-call timeout most MCP clients enforce around 60s), it waits for the message to reach a terminal state: delivered, bounced, complained or failed. The result is always { finished, message, events }: message is the message in the same shape GET /v1/emails/:id returns, events lists the transitions seen during the call, and finished says whether that happened because the message settled or because time ran out. A timeout isn't an error: isError is false and finished is false, with a note saying to call it again. There's no Last-Event-ID for a tool call to send back, so a follow-up call replays the message's full event history from the start rather than resuming. That's cheap for one message's events, and the same replay an HTTP caller gets on a fresh connect with no Last-Event-ID of its own.

GET /v1/events has no tool. It streams every transition the key can see, held open until the client closes it. There's no terminal state to block until, so the "wait, then return one result" shape watch_email uses doesn't apply, and blocking a tool call until a caller-chosen cutoff would be list_emails with extra steps. A caller that wants to tail everything reaches it over HTTP directly.

Include and fields

Every tool over a resource read takes fields as an array, and include where the route has expansions, with the valid names in the tool's input schema. read_email with fields: ["status"] returns id and status and nothing else. The rules are the API's (docs/api/conventions.md, "Include and fields").

Waiting for mail

wait_for_mail is GET /v1/addresses/:id/messages with wait set, through the ordinary request/response path: the route itself long-polls, so there's no stream to fold. It returns the page as soon as mail reaches the address, or an empty data once wait seconds pass (55 by default, under the common 60-second tool-call timeout). Pass after with the last message seen to wait for the next one. It holds one of the key's MAX_CONCURRENT_STREAMS_PER_KEY slots while it waits. Read a message in full with read_inbound.

Key scoping

A key's domainIds constrains a tool call exactly the way it constrains the same HTTP route. GET /v1/domains already filters to the key's domains (lib/domains/index.ts's listDomains), and a scoped key already gets key_not_scoped back from POST /v1/domains and both /v1/providers routes (lib/domains/index.ts, lib/providers/index.ts). The MCP layer adds nothing to that; it can't, since every call is the same route call. What it adds is honesty in the tool list itself: each tool's description is regenerated per connection and states the authenticating key's actual scope ("scoped to N domains: dom_…" or "not domain-scoped") plus, for a route docs/api/conventions.md restricts to an unscoped key, whether this key qualifies. A client reading the tool list never has to guess whether a tool reaches more than this key can reach.

Errors

A non-2xx route response is already docs/api/conventions.md's error envelope, { error: { code, message, field, detail, request_id } }, and that JSON is carried through unchanged as the tool's error result (isError: true, the envelope as the result's text and structuredContent). A caller sees exactly what an HTTP caller of the same route would have seen: the same code to branch on, the same message, the same request_id to quote. The one divergence: a malformed call (wrong type, missing required field) can be rejected by MCP's own schema validation before the route ever runs, since the tool's input schema is the route's own zod schema. That rejection isn't wrapped in the API's error envelope; it's MCP's own validation error, over the same field names and the same shape rules.

No tool

tests/unit/mcp-coverage.test.ts lists these, each with its reason.

  • POST /v1/confirm and POST /v1/unsubscribe take a token rather than a key.
  • GET /v1/events has no terminal state to wait for. See "Watching a message".

On this page