# resend/mcp-send-email architecture

> Architecture diagram of the GitHub repository resend/mcp-send-email, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/resend/mcp-send-email
- Repository: https://github.com/resend/mcp-send-email

## Overview

##### Project type and purpose
- This is a lightweight, command-line “MCP” (Model-Connected-Plugin) microservice built in TypeScript/Node.js.
- Its sole responsibility is to receive email send requests from chat clients (Cursor or Claude Desktop), format them, and invoke the Resend API to dispatch emails (plain text, HTML, scheduled, CC/BCC, reply-to, custom sender).

##### File structure
- Top-level files:
- index.ts – single entry point defining the CLI/MCP server logic
- email.md – example email template used in demos/testing
- package.json, tsconfig.json, biome.json – Node.js and build configuration
- README.md, CHANGELOG.md – documentation
- Build artifacts (not in tree but referenced): build/index.js (compiled output)
- No separate “frontend” or “database” directories: this is purely a backend microservice/CLI tool.

##### Key insights from README
- Integrates with two external “clients”: Cursor and Claude Desktop, each invoking the CLI via command or command+args+env.
- Relies on Resend’s HTTP API (via Resend Node.js SDK under the hood).
- Exposes flags and environment variables: API key, sender, reply-to, schedule options.
- No persistent state or database; scheduling is ephemeral or delegated to the Node process.

##### Main components and their interactions
a. Components
1. Chat Clients (Cursor, Claude Desktop)
2. Local MCP CLI Server (build/index.js)
– CLI interface (parses args/env)
– Email Builder (formats plain text or HTML, handles CC/BCC, reply-to, scheduling)
– Resend Client Library (Node SDK or direct HTTP calls)
3. External Resend API
4. (Optional) Local Scheduler Module – handles future‐delivery logic in process memory
b. Relationships & Data Flow
– Users trigger “send email” in their chat client →
– Chat Client invokes `node build/index.js` with flags/env →
– CLI parses input and email.md (or stdin) →
– Email Builder constructs payload →
– Resend Client Library issues HTTPS request →
– Resend API responds with send confirmation →
– CLI returns success/failure JSON or console output back to client.
c. Architectural patterns & principles
– Single-responsibility: one module handles CLI parsing, one for payload building, one for HTTP client.
– Externalized configuration: API key and sender via flags or env vars.
– Pluggable integration: designed to be invoked by any tool supporting command plugins (MCP spec).
d. Key technologies
– Node.js + TypeScript, compiled by tsc
– Resend Node.js SDK (or HTTP client)
– MCP specification (Anthropic/Cursor)
– CLI argument parser (e.g., yargs or native process.argv)

##### Putting it all together
- Inside the MCP Server, vertically stack the sub-components in logical flow:
CLI Parser → Email Builder → Scheduler (optional) → Resend Client.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    subgraph "External Clients"
        direction TB
        Cursor["Cursor"]:::external
        Claude["Claude Desktop"]:::external
    end

    %% MCP Server Modules
    subgraph "MCP Server (Node CLI)"
        direction TB
        CLIParser["CLI Parser"]:::internal
        EmailBuilder["Email Builder"]:::internal
        Scheduler["Scheduler Module"]:::internal
        ResendClient["Resend Client"]:::internal
    end

    %% External Service
    ResendAPI["Resend API"]:::service

    %% Templates
    EmailTemplate["email.md"]:::internal

    %% Configuration & Build
    subgraph "Configuration & Build"
        direction TB
        Package["package.json"]:::config
        TSConfig["tsconfig.json"]:::config
        Biome["biome.json"]:::config
    end

    %% Documentation
    subgraph "Documentation"
        direction TB
        Readme["README.md"]:::doc
        Changelog["CHANGELOG.md"]:::doc
    end

    %% Data Flow
    Cursor -->|"invoke CLI"| CLIParser
    Claude -->|"invoke CLI"| CLIParser
    CLIParser -->|"parses flags/env"| EmailBuilder
    EmailTemplate -->|"template input"| EmailBuilder
    EmailBuilder -->|"constructs payload"| Scheduler
    Scheduler -->|"schedules or passes through"| ResendClient
    ResendClient -->|"HTTP POST /send"| ResendAPI
    ResendAPI -->|"response/status"| ResendClient
    ResendClient -->|"returns result"| CLIParser
    CLIParser -->|"output JSON/console"| Cursor
    CLIParser -->|"output JSON/console"| Claude

    %% Click Events
    click CLIParser "https://github.com/resend/mcp-send-email/blob/main/index.ts"
    click EmailBuilder "https://github.com/resend/mcp-send-email/blob/main/index.ts"
    click Scheduler "https://github.com/resend/mcp-send-email/blob/main/index.ts"
    click ResendClient "https://github.com/resend/mcp-send-email/blob/main/index.ts"
    click EmailTemplate "https://github.com/resend/mcp-send-email/blob/main/email.md"
    click Package "https://github.com/resend/mcp-send-email/blob/main/package.json"
    click TSConfig "https://github.com/resend/mcp-send-email/blob/main/tsconfig.json"
    click Biome "https://github.com/resend/mcp-send-email/blob/main/biome.json"
    click Readme "https://github.com/resend/mcp-send-email/blob/main/README.md"
    click Changelog "https://github.com/resend/mcp-send-email/blob/main/CHANGELOG.md"

    %% Styles
    classDef external fill:#C6F6D5,stroke:#2F855A
    classDef internal fill:#BEE3F8,stroke:#2B6CB0
    classDef service fill:#FBD38D,stroke:#DD6B20
    classDef config fill:#E2E8F0,stroke:#4A5568
    classDef doc fill:#FDE68A,stroke:#D69E2E
```
