# MCP Mailtrap Server The MCP Mailtrap Server is an official Model Context Protocol (MCP) server that integrates Mailtrap's email service capabilities into AI assistants and development tools. Built on the MCP SDK, this server enables AI agents to send transactional emails, manage email templates, and test email functionality through Mailtrap's sandbox environment. The server acts as a bridge between AI applications (like Claude Desktop, Cursor, or VS Code) and Mailtrap's API, allowing natural language commands to be translated into email operations. This implementation follows the MCP protocol specification and provides six core tools for email operations: sending transactional emails, sending sandbox test emails, creating templates, listing templates, updating templates, and deleting templates. The server uses TypeScript for type safety, Zod schemas for input validation, and the official Mailtrap Node.js SDK for API communication. It supports flexible configuration through environment variables and can be installed via NPX, Smithery CLI, or as an MCP Bundle (MCPB) file for easy distribution. ## Installation and Configuration ### Quick Installation via NPX ```json { "mcpServers": { "mailtrap": { "command": "npx", "args": ["-y", "mcp-mailtrap"], "env": { "MAILTRAP_API_TOKEN": "your_api_token_here", "DEFAULT_FROM_EMAIL": "sender@yourdomain.com", "MAILTRAP_ACCOUNT_ID": "123456", "MAILTRAP_TEST_INBOX_ID": "789012" } } } } ``` ### Local Development Setup ```bash # Clone and install dependencies git clone https://github.com/mailtrap/mailtrap-mcp.git cd mailtrap-mcp npm install # Build the TypeScript source npm run build # Run with MCP Inspector for testing npm run dev ``` ### Claude Desktop Configuration (Mac) ```bash # Edit config file nano ~/Library/Application\ Support/Claude/claude_desktop_config.json ``` ```json { "mcpServers": { "mailtrap": { "command": "node", "args": ["/absolute/path/to/mailtrap-mcp/dist/index.js"], "env": { "MAILTRAP_API_TOKEN": "your_api_token_here", "DEFAULT_FROM_EMAIL": "sender@yourdomain.com", "MAILTRAP_ACCOUNT_ID": "123456", "MAILTRAP_TEST_INBOX_ID": "789012" } } } } ``` ## Send Transactional Email Sends a production email through Mailtrap's transactional email service to real recipients. ```typescript // MCP tool call structure { "name": "send-email", "arguments": { "to": "recipient@example.com", "subject": "Welcome to Our Platform", "text": "Thank you for signing up!", "html": "
Thank you for signing up!
", "from": "noreply@yourdomain.com", "category": "onboarding", "cc": ["manager@example.com"], "bcc": ["archive@example.com"] } } // Successful response { "content": [{ "type": "text", "text": "Email sent successfully to recipient@example.com.\nMessage IDs: abc123xyz\nStatus: Success" }] } // Error response { "content": [{ "type": "text", "text": "Failed to send email: MAILTRAP_API_TOKEN environment variable is required" }], "isError": true } ``` ### Send to Multiple Recipients ```typescript { "name": "send-email", "arguments": { "to": ["user1@example.com", "user2@example.com", "user3@example.com"], "subject": "Team Meeting Tomorrow", "text": "Don't forget our team meeting at 10 AM tomorrow.", "category": "internal-communication" } } // Response { "content": [{ "type": "text", "text": "Email sent successfully to user1@example.com, user2@example.com, user3@example.com.\nMessage IDs: msg_1,msg_2,msg_3\nStatus: Success" }] } ``` ## Send Sandbox Email Sends a test email to Mailtrap's sandbox inbox for testing without delivering to real recipients. ```typescript // MCP tool call for sandbox testing { "name": "send-sandbox-email", "arguments": { "to": "test@example.com", "subject": "Test Email Template", "html": "This is a test email to preview styling.
", "text": "Testing Header\n\nThis is a test email to preview styling.", "from": "test@yourdomain.com", "category": "test" } } // Successful response { "content": [{ "type": "text", "text": "Sandbox email sent successfully to test@example.com.\nMessage IDs: sandbox_123\nStatus: Success" }] } // Error when MAILTRAP_TEST_INBOX_ID is not configured { "content": [{ "type": "text", "text": "Failed to send sandbox email: MAILTRAP_TEST_INBOX_ID environment variable is required for sandbox mode" }], "isError": true } ``` ### Multiple Sandbox Recipients ```typescript { "name": "send-sandbox-email", "arguments": { "to": "dev1@test.com, dev2@test.com, qa@test.com", "subject": "QA Testing - User Registration Email", "html": "Your account has been created.
We're excited to have you on board.
Your account ID: {{account_id}}
", "text": "Welcome {{user_name}}!\n\nWe're excited to have you on board.\n\nYour account ID: {{account_id}}", "category": "onboarding" } } // Successful response { "content": [{ "type": "text", "text": "Template \"Welcome Email\" created successfully!\nTemplate ID: 12345\nTemplate UUID: abc-123-def-456" }] } // Error when missing required content { "content": [{ "type": "text", "text": "Failed to create template: At least one of 'html' or 'text' content must be provided." }], "isError": true } ``` ### Password Reset Template ```typescript { "name": "create-template", "arguments": { "name": "Password Reset", "subject": "Reset Your Password", "html": "Click the link below to reset your password:
Reset PasswordThis link expires in 24 hours.
", "text": "Password Reset Request\n\nClick the link below to reset your password:\n{{reset_link}}\n\nThis link expires in 24 hours.", "category": "security" } } ``` ## List Email Templates Retrieves all email templates from your Mailtrap account. ```typescript // List all templates { "name": "list-templates", "arguments": {} } // Response with templates { "content": [{ "type": "text", "text": "Found 3 template(s):\n\n• Welcome Email (ID: 12345, UUID: abc-123-def-456)\n Subject: Welcome to {{company_name}}!\n Category: onboarding\n Created: 2024-01-15T10:30:00Z\n\n• Password Reset (ID: 12346, UUID: abc-124-def-457)\n Subject: Reset Your Password\n Category: security\n Created: 2024-01-16T14:20:00Z\n\n• Invoice Notification (ID: 12347, UUID: abc-125-def-458)\n Subject: Your Invoice is Ready\n Category: billing\n Created: 2024-01-17T09:15:00Z\n" }] } // Response when no templates exist { "content": [{ "type": "text", "text": "No templates found in your Mailtrap account." }] } // Error response { "content": [{ "type": "text", "text": "Failed to list templates: MAILTRAP_API_TOKEN environment variable is required" }], "isError": true } ``` ## Update Email Template Updates an existing email template by ID. ```typescript // Update template subject and HTML { "name": "update-template", "arguments": { "template_id": 12345, "subject": "Welcome to {{company_name}} - Get Started!", "html": "We're excited to have you on board.
Your account ID: {{account_id}}
Go to Dashboard" } } // Successful response { "content": [{ "type": "text", "text": "Template \"Welcome Email\" updated successfully!\nTemplate ID: 12345\nTemplate UUID: abc-123-def-456" }] } // Update only the category { "name": "update-template", "arguments": { "template_id": 12345, "category": "user-engagement" } } // Error when no fields provided { "content": [{ "type": "text", "text": "Error: At least one update field (name, subject, html, text, or category) must be provided" }], "isError": true } ``` ### Complete Template Overhaul ```typescript { "name": "update-template", "arguments": { "template_id": 12346, "name": "Password Reset v2", "subject": "Security Alert - Password Reset Requested", "html": "Hello {{user_name}},
We received a request to reset your password.
Reset PasswordThis link expires in 24 hours.
If you didn't request this, please ignore this email.