You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,7 @@
1
1
## [Unreleased]
2
2
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.
Copy file name to clipboardExpand all lines: CLAUDE.md
+38-21Lines changed: 38 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,16 +5,19 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
5
5
## Development Commands
6
6
7
7
### Build and Development
8
+
8
9
-`npm run build` - Compile TypeScript to JavaScript in the `dist/` directory
9
10
-`npm run dev` - Run the MCP server with the MCP Inspector for testing
10
11
-`npm run prepublish` - Build the project and make the executable script executable
11
12
12
13
### Code Quality
14
+
13
15
-`npm run lint` - Run both ESLint and TypeScript checks
14
16
-`npm run lint:eslint` - Run ESLint for code style checking
15
17
-`npm run lint:tsc` - Run TypeScript compiler for type checking
16
18
17
19
### Testing
20
+
18
21
-`npm test` - Run all Jest tests
19
22
-`npm run test:watch` - Run tests in watch mode during development
20
23
-`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
24
27
This is an MCP (Model Context Protocol) server that integrates with Mailtrap's email service. The architecture follows a modular pattern:
25
28
26
29
### Core Components
30
+
27
31
-**src/index.ts**: Main MCP server entry point that registers all tools and handles the server lifecycle
28
32
-**src/client.ts**: Mailtrap client configuration and initialization
29
33
-**src/config/index.ts**: Server configuration constants
30
34
31
35
### Tool Architecture
36
+
32
37
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
35
41
- 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
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.
45
50
46
51
### Environment Variables Required
52
+
47
53
-`MAILTRAP_API_TOKEN`: Required API token from Mailtrap
-`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.
50
56
-`MAILTRAP_TEST_INBOX_ID`: Required for sandbox tools - test inbox ID for sandbox mode operations
51
57
52
58
### Testing Setup
59
+
53
60
- Uses Jest with TypeScript support via ts-jest
54
61
- Test files are located in `__tests__/` directories within each tool
55
62
- Environment variables are set up via `jest/setEnvVars.js`
56
63
- Coverage reports exclude test files and type definitions
57
64
58
65
### Build Configuration
66
+
59
67
- TypeScript compilation targets ES2022 with CommonJS modules
60
68
- Separate build config (`tsconfig.build.json`) excludes test files from distribution
61
69
- Output goes to `dist/` directory with proper executable permissions
62
70
63
71
### Available MCP Tools
64
72
65
73
#### 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.
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
78
94
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.
81
98
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.
Copy file name to clipboardExpand all lines: README.md
+90-49Lines changed: 90 additions & 49 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
5
5
# MCP Mailtrap Server
6
6
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.
8
8
9
9
## Prerequisites
10
10
@@ -16,10 +16,11 @@ Before using this MCP server, you need to:
16
16
4. Get your Account ID from [Mailtrap account management](https://mailtrap.io/account-management)
17
17
18
18
**Required Environment Variables:**
19
+
19
20
-`MAILTRAP_API_TOKEN` - Required for all functionality
20
21
-`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)
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.
47
50
48
51
### Claude Desktop or Cursor
@@ -153,12 +156,24 @@ This creates `mailtrap-mcp.mcpb` using the repository `manifest.json` and built
153
156
154
157
Once configured, you can ask agent to send emails and manage templates, for example:
155
158
156
-
**Email Operations:**
159
+
**Email Sending Operations:**
157
160
158
161
- "Send an email to john.doe@example.com with the subject 'Meeting Tomorrow' and a friendly reminder about our upcoming meeting."
159
162
- "Email sarah@example.com about the project update, and CC the team at team@example.com"
160
163
- "Send a sandbox email to test@example.com with subject 'Test Template' to preview how our welcome email looks"
161
164
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
+
162
177
**Sandbox Operations:**
163
178
164
179
- "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
173
188
- "Update the template with ID 12345 to change the subject to 'Updated Welcome Message'"
174
189
- "Delete the template with ID 67890"
175
190
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
-
182
191
## Available Tools
183
192
184
193
### send-email
@@ -196,47 +205,53 @@ Sends a transactional email through Mailtrap.
196
205
-`bcc` (optional): Array of BCC recipient email addresses
197
206
-`category` (required): Email category for tracking and analytics
198
207
199
-
### send-sandbox-email
208
+
### list-email-logs
200
209
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.
202
211
203
212
**Parameters:**
204
213
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.
220
236
221
237
**Parameters:**
222
238
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.
229
241
230
-
### show-sandbox-email-message
242
+
### get-sending-stats
231
243
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.
233
245
234
246
**Parameters:**
235
247
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)
240
255
241
256
### create-template
242
257
@@ -282,22 +297,48 @@ Deletes an existing email template.
282
297
283
298
-`template_id` (required): ID of the template to delete
284
299
285
-
### get-sending-stats
300
+
### send-sandbox-email
286
301
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.
288
303
289
304
**Parameters:**
290
305
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
298
314
299
315
> [!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.
0 commit comments