MCP Shipyard
← Guides

Build a remote MCP server for email: tools, auth and review-ready metadata

Design a remote MCP server for email: send, search and validation tools, OAuth auth, a TypeScript example and the annotation rules that matter.

emailtoolsauthoauthsubmissionleaderboardtypescript

Build a remote MCP server for email

Short answer: an email server that sends or reads mail needs OAuth, a send tool marked destructive (a sent message cannot be recalled), read tools marked read-only, and no SMTP password or API key as a parameter. Address validation alone can run as a separate public, no-auth endpoint.

Basis: the MCP specification, the official TypeScript SDK docs (v2, package @modelcontextprotocol/server, read 2026-12-04) and our scanner rule pages. Tool sets are our recommendation, not a requirement. Anything marked (unverified) is not confirmed in those sources.

Keep recipient, subject and body as typed fields, and say what each tool sends and to whom.

send_email

  • Title: Send an email
  • Description: see the example below.
  • Input: to array of email addresses, 1 to 10, required; subject string; body string; cc optional
  • Annotations: readOnlyHint false, destructiveHint true, openWorldHint true

search_messages

  • Title: Search messages
  • Description: "Use this to search the signed-in user's mailbox by sender, subject text or date range. Returns up to 20 message ids with sender, subject and date."
  • Input: query string; from, after strings optional; limit integer 1 to 20
  • Annotations: readOnlyHint true, destructiveHint false, openWorldHint false

get_message

  • Title: Read a message
  • Description: "Use this to read one message by id returned from search_messages. Returns headers and the plain-text body."
  • Input: message_id string, required
  • Annotations: readOnlyHint true, destructiveHint false, openWorldHint false

validate_email_address

  • Title: Validate an email address
  • Description: "Use this to check whether an address is well formed and its domain accepts mail. It does not send anything."
  • Input: address string, required
  • Annotations: readOnlyHint true, destructiveHint false, openWorldHint true

Annotations are hints, not security (see annotations explained). Here openWorldHint is true only where a tool reaches arbitrary outside parties, and false for a fixed domain. send_email is readOnlyHint false and destructiveHint true because an irreversible send counts as destructive in ChatGPT's guidelines (see the submission checklist). A tool named send must never be read-only (annotations.write-marked-readonly).

Auth

Recommendation: OAuth 2.1 with PKCE. Reading or sending mail acts on a user's mailbox. Your server is the resource server: answer an unauthenticated call with 401 and a WWW-Authenticate header carrying resource_metadata (auth.challenge-401), publish RFC 9728 protected resource metadata (auth.prm-missing) whose resource equals the URL users enter (auth.resource-mismatch), and make your authorization server advertise PKCE S256 (auth.pkce-s256). For client registration advertise Client ID Metadata Documents (CIMD) and keep a registration_endpoint for Dynamic Client Registration (DCR) as the fallback (auth.client-registration-claude, auth.client-registration-chatgpt). Never put a token in the URL (auth.credential-in-url). The full flow is in MCP OAuth for Claude and ChatGPT. The SDK covers only the resource-server half: requireBearerAuth verifies tokens, and its docs say to use a dedicated identity provider for the authorization server. Split validate_email_address onto a public endpoint if you want it usable without sign-in (recommendation).

Transport

Serve Streamable HTTP on one HTTPS path such as https://mcp.example.com/mcp (auth.https). In the v2 SDK, createMcpHandler(factory) builds a fresh McpServer for every request, so the endpoint is stateless and needs no sticky sessions (sessions and serverless). The handler checks no Host, Origin or token itself, so put those checks in front of it. Still on SSE? See the migration guide. Keep the handshake fast (latency.handshake).

Minimal TypeScript example

This targets SDK v2; coming from v1, use the SDK's migration guide. In v2 inputSchema is a z.object(...). Replace lookup with your own code.

import { createMcpHandler, McpServer, requireBearerAuth } from '@modelcontextprotocol/server';
import * as z from 'zod/v4';

const handler = createMcpHandler(() => {
  const server = new McpServer({ name: 'acme-mail', version: '1.0.0' });
  server.registerTool(
    'send_email',
    {
      title: "Send an email",
      description:
        "Use this to send one email from the signed-in user's account to the listed recipients. It sends immediately and cannot be recalled. Does not save drafts.",
      inputSchema: z.object({
        to: z.array(z.email()).min(1).max(10),
        subject: z.string().max(200),
        body: z.string().max(50000)
      }),
      annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: true }
    },
    async (args) => {
      const sent = await sendFromUser(args); // your mail API
      if (!sent.ok) return { isError: true, content: [{ type: 'text', text: 'Send failed: check the recipient address.' }] };
      return { content: [{ type: 'text', text: 'Sent message ' + sent.id }] };
    }
  );
  return server;
});

const gate = requireBearerAuth({
  verifier: { verifyAccessToken }, // your function: token in, AuthInfo out, with expiresAt set
  requiredScopes: ['mcp'],
  expectedResource: new URL('https://mcp.example.com/mcp')
});

export default {
  async fetch(request: Request): Promise<Response> {
    const auth = await gate(request);
    if (auth instanceof Response) return auth; // 401 or 403 challenge
    return handler.fetch(request, { authInfo: auth });
  }
};

Return a message id on success. Validate recipients in the schema, not in prose.

Errors, size and speed

Return isError: true with text that says what was wrong and how to fix it; messages such as "Internal Server Error" fail review (errors.unhelpful-message). Reviewers run every tool with valid input and reject failures (errors.fixture-failed). Keep a call under 3 seconds where you can: the scanner warns above 3 and fails above 15 (latency.tool-call). For slower work see tool timeouts, cap result size (response size limits) and never echo keys or tokens in output (errors.secrets-in-output). Run the same calls in CI so a regression never reaches review.

Getting models to pick your tools

The leaderboard method shows the model every tool in the category as a function named <server>__<tool>, with your description and input schema, and records the first tool it calls. Your name, description and schema are the whole pitch. In the December 4 2026 run, 34.3% (36 of 105) of email trials ended with no tool called. The method's first email prompt draft was almost all "my inbox" requests, so some prompts were replaced with sending, validation and domain checks. Make each tool's first sentence the user's intent ("send", "find messages", "check an address"), and say when not to use it: validation does not send, search_messages does not return bodies. Do not describe sending limits or plans. Limits apply: the harness is offline, uses one model family, and measures selection, not correct answers. Rewrite method and prompt sets are in writing tool descriptions models pick; write about your own task and sibling tools, never about other servers (desc.injection-directive).

Pitfalls our rules catch

Submission checklist

Check your server against these rules at https://mcpshipyard.com/scan.

Check your server against these rules

Scan runs the checks from this guide against a live URL and lists each failing rule with its fix.

Scan a server