Skip to content

Commit d400840

Browse files
committed
Add email-logs tools
1 parent dd8d950 commit d400840

23 files changed

Lines changed: 2091 additions & 76 deletions

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## [Unreleased]
22

3-
* Add **get-sending-stats** tool: check delivery, bounce, open, click, and spam rates for a date range; optional breakdown by domain, category, email service provider, or date. Requires `MAILTRAP_ACCOUNT_ID`.
3+
* Add **list-email-logs** and **get-email-log-message** tools: query sent-mail delivery history with filters and pagination; inspect a single log by UUID (summary, event timeline, optional body via `include_content`).
4+
* Add **get-sending-stats** tool: check delivery, bounce, open, click, and spam rates for a date range; optional breakdown by domain, category, email service provider, or date.
45

56
## [0.1.0] - 2025-12-09
67

CLAUDE.md

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
55
## Development Commands
66

77
### Build and Development
8+
89
- `npm run build` - Compile TypeScript to JavaScript in the `dist/` directory
910
- `npm run dev` - Run the MCP server with the MCP Inspector for testing
1011
- `npm run prepublish` - Build the project and make the executable script executable
1112

1213
### Code Quality
14+
1315
- `npm run lint` - Run both ESLint and TypeScript checks
1416
- `npm run lint:eslint` - Run ESLint for code style checking
1517
- `npm run lint:tsc` - Run TypeScript compiler for type checking
1618

1719
### Testing
20+
1821
- `npm test` - Run all Jest tests
1922
- `npm run test:watch` - Run tests in watch mode during development
2023
- `npm run test:coverage` - Run tests with coverage reporting
@@ -24,59 +27,73 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
2427
This is an MCP (Model Context Protocol) server that integrates with Mailtrap's email service. The architecture follows a modular pattern:
2528

2629
### Core Components
30+
2731
- **src/index.ts**: Main MCP server entry point that registers all tools and handles the server lifecycle
2832
- **src/client.ts**: Mailtrap client configuration and initialization
2933
- **src/config/index.ts**: Server configuration constants
3034

3135
### Tool Architecture
36+
3237
All tools follow a consistent pattern in the `src/tools/` directory:
33-
- Each tool has its own subdirectory (e.g., `sendEmail/`, `templates/`)
34-
- Tools export both their implementation function and Zod schema for validation
38+
39+
- Each tool (or tool group) has its own subdirectory (e.g., `sendEmail/`, `templates/`, `emailLogs/`)
40+
- Tools export an **input schema** (JSON Schema–style object for MCP `inputSchema`) and a **handler** function
3541
- Template operations are grouped under `templates/` with individual files for each CRUD operation
42+
- **Runtime validation**: Handlers may validate input with Zod (see `stats/schema.ts` and `getSendingStats.ts`). Other tools use TypeScript types and ad-hoc checks; adding Zod validation in handlers is recommended for consistency
3643

3744
### Tool Structure Pattern
38-
```
39-
src/tools/{toolName}/
40-
├── index.ts # Main tool export
41-
├── schema.ts # Zod validation schema
42-
├── {toolName}.ts # Tool implementation
43-
└── __tests__/ # Jest test files
44-
```
45+
46+
- Single-tool dirs (e.g. `sendEmail/`, `stats/`): `index.ts`, `schema.ts` (or `schema.ts` + Zod in handler), implementation file(s), `__tests__/`
47+
- Multi-tool dirs (e.g. `templates/`, `sandbox/`, `emailLogs/`): `index.ts`, `schemas/*.ts` (one schema per tool), implementation file(s), `__tests__/`
48+
49+
Schema files define a JSON Schema–shaped object for MCP; optional Zod schemas in the same or separate file can be used for runtime validation in the handler.
4550

4651
### Environment Variables Required
52+
4753
- `MAILTRAP_API_TOKEN`: Required API token from Mailtrap
4854
- `DEFAULT_FROM_EMAIL`: Default sender email address
49-
- `MAILTRAP_ACCOUNT_ID`: Required for template management and sending stats (optional for send-email only)
55+
- `MAILTRAP_ACCOUNT_ID`: Required for almost all tools (templates, stats, email logs, sandbox list/show). Optional only for send-email and send-sandbox-email.
5056
- `MAILTRAP_TEST_INBOX_ID`: Required for sandbox tools - test inbox ID for sandbox mode operations
5157

5258
### Testing Setup
59+
5360
- Uses Jest with TypeScript support via ts-jest
5461
- Test files are located in `__tests__/` directories within each tool
5562
- Environment variables are set up via `jest/setEnvVars.js`
5663
- Coverage reports exclude test files and type definitions
5764

5865
### Build Configuration
66+
5967
- TypeScript compilation targets ES2022 with CommonJS modules
6068
- Separate build config (`tsconfig.build.json`) excludes test files from distribution
6169
- Output goes to `dist/` directory with proper executable permissions
6270

6371
### Available MCP Tools
6472

6573
#### Transactional Email
66-
1. **send-email**: Send transactional emails through Mailtrap
74+
75+
- **send-email**: Send transactional emails through Mailtrap.
76+
77+
#### Email Logs
78+
79+
- **list-email-logs**: List sent email logs (delivery history) with optional pagination and filters; use to debug delivery issues.
80+
- **get-email-log-message**: Get a single email log message by ID (UUID) to inspect delivery status and event history; optional `include_content` loads message body when available.
81+
82+
#### Statistics
83+
84+
- **get-sending-stats**: Get email sending statistics (delivery, bounce, open, click, spam rates) for a date range; optionally break down by domain, category, email service provider, or date.
6785

6886
#### Email Templates
69-
2. **create-template**: Create new email templates
70-
3. **list-templates**: List all email templates
71-
4. **update-template**: Update existing email templates
72-
5. **delete-template**: Delete email templates
87+
88+
- **create-template**: Create new email templates.
89+
- **list-templates**: List all email templates.
90+
- **update-template**: Update existing email templates.
91+
- **delete-template**: Delete email templates.
7392

7493
#### Sandbox Testing
75-
6. **send-sandbox-email**: Send email in sandbox mode to a test inbox
76-
7. **get-sandbox-messages**: Get list of messages from the sandbox test inbox
77-
8. **show-sandbox-email-message**: Show sandbox email message details and content from the sandbox test inbox
7894

79-
#### Statistics
80-
9. **get-sending-stats**: Get email sending statistics (delivery, bounce, open, click, spam rates) for a date range; optionally break down by domain, category, email service provider, or date. Requires `MAILTRAP_ACCOUNT_ID`.
95+
- **send-sandbox-email**: Send email in sandbox mode to a test inbox.
96+
- **get-sandbox-messages**: Get list of messages from the sandbox test inbox.
97+
- **show-sandbox-email-message**: Show sandbox email message details and content from the sandbox test inbox.
8198

82-
Each tool uses Zod schemas for input validation and follows the MCP protocol for response formatting.
99+
Tools use input schemas (JSON Schema format) for MCP; handlers may validate input with Zod. Response format follows the MCP protocol.

README.md

Lines changed: 90 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# MCP Mailtrap Server
66

7-
An MCP server that provides tools for sending transactional emails, managing email templates, checking sending statistics, and testing in sandbox via Mailtrap
7+
An MCP server that provides tools for sending and testing in sandbox via Mailtrap.
88

99
## Prerequisites
1010

@@ -16,10 +16,11 @@ Before using this MCP server, you need to:
1616
4. Get your Account ID from [Mailtrap account management](https://mailtrap.io/account-management)
1717

1818
**Required Environment Variables:**
19+
1920
- `MAILTRAP_API_TOKEN` - Required for all functionality
2021
- `DEFAULT_FROM_EMAIL` - Required for all email sending operations
21-
- `MAILTRAP_ACCOUNT_ID` - Required for template management and sending statistics
22-
- `MAILTRAP_TEST_INBOX_ID` - **Only** required for sandbox email functionality
22+
- `MAILTRAP_ACCOUNT_ID` - Required for almost all tools (templates, stats, email logs, sandbox list/show). Optional only for send-email and send-sandbox-email.
23+
- `MAILTRAP_TEST_INBOX_ID` - Required for sandbox tools (send, list messages, show message)
2324

2425
## Quick Install
2526

@@ -42,7 +43,9 @@ npx @smithery/cli install mailtrap
4243

4344

4445
## Setup
46+
4547
### Claude Desktop
48+
4649
Use MCPB to install the Mailtrap server. You can find those files in [Releases](https://github.com/mailtrap/mailtrap-mcp/releases). <br>Download .MCPB file and open it. If you have Claude Desktop - it will open it and suggest to configure.
4750

4851
### Claude Desktop or Cursor
@@ -153,12 +156,24 @@ This creates `mailtrap-mcp.mcpb` using the repository `manifest.json` and built
153156

154157
Once configured, you can ask agent to send emails and manage templates, for example:
155158

156-
**Email Operations:**
159+
**Email Sending Operations:**
157160

158161
- "Send an email to john.doe@example.com with the subject 'Meeting Tomorrow' and a friendly reminder about our upcoming meeting."
159162
- "Email sarah@example.com about the project update, and CC the team at team@example.com"
160163
- "Send a sandbox email to test@example.com with subject 'Test Template' to preview how our welcome email looks"
161164

165+
**Email Logs (debug delivery):**
166+
167+
- "List my recent sent email logs"
168+
- "Show email logs for emails sent to user@example.com"
169+
- "Get the email log message for ID abc-123-uuid to check delivery status"
170+
171+
**Sending Statistics:**
172+
173+
- "Get sending stats for January 2025"
174+
- "Show delivery rates broken down by domain for last month"
175+
- "What are my email stats by category from 2025-01-01 to 2025-01-31?"
176+
162177
**Sandbox Operations:**
163178

164179
- "Get all messages from my sandbox inbox"
@@ -173,12 +188,6 @@ Once configured, you can ask agent to send emails and manage templates, for exam
173188
- "Update the template with ID 12345 to change the subject to 'Updated Welcome Message'"
174189
- "Delete the template with ID 67890"
175190

176-
**Statistics:**
177-
178-
- "Get sending stats for January 2025"
179-
- "Show delivery rates broken down by domain for last month"
180-
- "What are my email stats by category from 2025-01-01 to 2025-01-31?"
181-
182191
## Available Tools
183192

184193
### send-email
@@ -196,47 +205,53 @@ Sends a transactional email through Mailtrap.
196205
- `bcc` (optional): Array of BCC recipient email addresses
197206
- `category` (required): Email category for tracking and analytics
198207

199-
### send-sandbox-email
208+
### list-email-logs
200209

201-
Sends an email to your Mailtrap test inbox for development and testing purposes. This is perfect for testing email templates without sending emails to real recipients.
210+
Lists sent email logs (delivery history) with optional pagination and filters. Use to debug delivery issues from the IDE.
202211

203212
**Parameters:**
204213

205-
- `to` (required): Email address(es) of the recipient(s) - can be a single email or array of emails (will be delivered to your test inbox)
206-
- `subject` (required): Email subject line
207-
- `from` (optional): Email address of the sender, if not provided "DEFAULT_FROM_EMAIL" will be used
208-
- `text` (optional): Email body text, required if "html" is empty
209-
- `html` (optional): HTML version of the email body, required if "text" is empty
210-
- `cc` (optional): Array of CC recipient email addresses
211-
- `bcc` (optional): Array of BCC recipient email addresses
212-
- `category` (optional): Email category for tracking
213-
214-
> [!NOTE]
215-
> The `MAILTRAP_TEST_INBOX_ID` environment variable must be configured for sandbox emails to work. This variable is **only** required for sandbox functionality and is not needed for regular transactional emails or template management.
216-
217-
### get-sandbox-messages
218-
219-
Retrieves a list of messages from your Mailtrap test inbox. Useful for checking what emails have been received in your sandbox during testing.
214+
- `search_after` (optional): Pagination cursor from the previous response's `next_page_cursor`
215+
- `sent_after` (optional): ISO 8601 date/time; only logs sent after this time
216+
- `sent_before` (optional): ISO 8601 date/time; only logs sent before this time
217+
- `from_email` (optional): Filter by sender email; use with `from_operator` (default: ci_equal)
218+
- `to_email` (optional): Filter by recipient email; use with `to_operator` (default: ci_equal)
219+
- `status` (optional): Filter by delivery status: delivered, not_delivered, enqueued, opted_out; use with `status_operator` (default: equal)
220+
- `subject` (optional): Filter by email subject; use with `subject_operator` (default: ci_contain). Use `subject_operator`: empty/not_empty to filter by presence of subject.
221+
- `sending_domain_id` (optional): Filter by sending domain ID (number); use with `sending_domain_id_operator` (default: equal)
222+
- `sending_stream` (optional): Filter by stream: transactional or bulk; use with `sending_stream_operator` (default: equal)
223+
- `events` (optional): Filter by event type(s): delivery, open, click, bounce, spam, unsubscribe, soft_bounce, reject, suspension; use with `events_operator` (include_event / not_include_event)
224+
- `clicks_count` / `opens_count` (optional): Filter by click/open count; use with `*_operator`: equal, greater_than, less_than
225+
- `client_ip` / `sending_ip` (optional): Filter by IP; use with `*_operator`: equal, not_equal, contain, not_contain
226+
- `email_service_provider_response` (optional): Filter by provider response text; use with `*_operator` (ci_contain, etc.)
227+
- `email_service_provider` (optional): Filter by provider (exact); use with `*_operator`: equal, not_equal
228+
- `recipient_mx` (optional): Filter by recipient MX; use with `recipient_mx_operator` (ci_contain, etc.)
229+
- `category` (optional): Filter by email category; use with `category_operator`: equal, not_equal
230+
231+
All parameters are optional.
232+
233+
### get-email-log-message
234+
235+
Gets a single email log message by ID (UUID): a readable summary (from, to, subject, sent time, status, category, stream, engagement, delivery context), then detailed event history. Optionally, with `include_content: true`, you can also load and show the message body (HTML and plain text) when Mailtrap exposes a raw message URL.
220236

221237
**Parameters:**
222238

223-
- `page` (optional): Page number for pagination (minimum: 1)
224-
- `last_id` (optional): Pagination using last message ID. Returns messages after the specified message ID (minimum: 1)
225-
- `search` (optional): Search query to filter messages
226-
227-
> [!NOTE]
228-
> All parameters are optional. If none are provided, the first page of messages from the inbox will be returned. Use page for traditional pagination, last_id for cursor-based pagination, or search to filter messages by content.
239+
- `message_id` (required): UUID of the email log message (from send response or list-email-logs). Use `list-email-logs` to find message IDs.
240+
- `include_content` (optional): When `true`, fetches the raw EML (if `raw_message_url` is available) and appends parsed HTML and plain-text body sections, similar to show-sandbox-email-message.
229241

230-
### show-sandbox-email-message
242+
### get-sending-stats
231243

232-
Shows detailed information and content of a specific email message from your Mailtrap test inbox, including HTML and text body content.
244+
Get email sending statistics (delivery, bounce, open, click, spam rates) for a date range. Optionally break down by domain, category, email service provider, or date. Check delivery rates without leaving the editor.
233245

234246
**Parameters:**
235247

236-
- `message_id` (required): ID of the sandbox email message to retrieve
237-
238-
> [!NOTE]
239-
> Use `get-sandbox-messages` first to get the list of messages and their IDs, then use this tool to view the full content of a specific message.
248+
- `start_date` (required): Start date for the stats range (YYYY-MM-DD)
249+
- `end_date` (required): End date for the stats range (YYYY-MM-DD)
250+
- `breakdown` (optional): How to break down the stats: `aggregated` (default), `by_domain`, `by_category`, `by_email_service_provider`, or `by_date`
251+
- `sending_domain_ids` (optional): Limit results to these sending domain IDs (array of integers)
252+
- `sending_streams` (optional): Limit to `transactional` and/or `bulk` (array of strings)
253+
- `categories` (optional): Limit to these email categories (array of strings)
254+
- `email_service_providers` (optional): Limit to these providers, e.g. Google, Yahoo, Outlook (array of strings)
240255

241256
### create-template
242257

@@ -282,22 +297,48 @@ Deletes an existing email template.
282297

283298
- `template_id` (required): ID of the template to delete
284299

285-
### get-sending-stats
300+
### send-sandbox-email
286301

287-
Get email sending statistics (delivery, bounce, open, click, spam rates) for a date range. Optionally break down by domain, category, email service provider, or date. Check delivery rates without leaving the editor.
302+
Sends an email to your Mailtrap test inbox for development and testing purposes. This is perfect for testing email templates without sending emails to real recipients.
288303

289304
**Parameters:**
290305

291-
- `start_date` (required): Start date for the stats range (YYYY-MM-DD)
292-
- `end_date` (required): End date for the stats range (YYYY-MM-DD)
293-
- `breakdown` (optional): How to break down the stats: `aggregated` (default), `by_domain`, `by_category`, `by_email_service_provider`, or `by_date`
294-
- `sending_domain_ids` (optional): Limit results to these sending domain IDs (array of integers)
295-
- `sending_streams` (optional): Limit to `transactional` and/or `bulk` (array of strings)
296-
- `categories` (optional): Limit to these email categories (array of strings)
297-
- `email_service_providers` (optional): Limit to these providers, e.g. Google, Yahoo, Outlook (array of strings)
306+
- `to` (required): Email address(es) of the recipient(s) - can be a single email or array of emails (will be delivered to your test inbox)
307+
- `subject` (required): Email subject line
308+
- `from` (optional): Email address of the sender, if not provided "DEFAULT_FROM_EMAIL" will be used
309+
- `text` (optional): Email body text, required if "html" is empty
310+
- `html` (optional): HTML version of the email body, required if "text" is empty
311+
- `cc` (optional): Array of CC recipient email addresses
312+
- `bcc` (optional): Array of BCC recipient email addresses
313+
- `category` (optional): Email category for tracking
298314

299315
> [!NOTE]
300-
> `MAILTRAP_ACCOUNT_ID` must be set for this tool to work.
316+
> The `MAILTRAP_TEST_INBOX_ID` environment variable must be configured for sandbox emails to work. This variable is **only** required for sandbox functionality and is not needed for regular transactional emails or template management.
317+
318+
### get-sandbox-messages
319+
320+
Retrieves a list of messages from your Mailtrap test inbox. Useful for checking what emails have been received in your sandbox during testing.
321+
322+
**Parameters:**
323+
324+
- `page` (optional): Page number for pagination (minimum: 1)
325+
- `last_id` (optional): Pagination using last message ID. Returns messages after the specified message ID (minimum: 1)
326+
- `search` (optional): Search query to filter messages
327+
328+
> [!NOTE]
329+
> All parameters are optional. If none are provided, the first page of messages from the inbox will be returned. Use page for traditional pagination, last_id for cursor-based pagination, or search to filter messages by content.
330+
331+
### show-sandbox-email-message
332+
333+
Shows detailed information and content of a specific email message from your Mailtrap test inbox, including HTML and text body content.
334+
335+
**Parameters:**
336+
337+
- `message_id` (required): ID of the sandbox email message to retrieve
338+
339+
> [!NOTE]
340+
> Use `get-sandbox-messages` first to get the list of messages and their IDs, then use this tool to view the full content of a specific message.
341+
301342

302343
## Development
303344

0 commit comments

Comments
 (0)