Skip to content

Add batch send sandbox email tool - #135

Merged
izikaj merged 4 commits into
mainfrom
add-bulk-send-sandbox-email-tool
Aug 7, 2026
Merged

Add batch send sandbox email tool#135
izikaj merged 4 commits into
mainfrom
add-bulk-send-sandbox-email-tool

Conversation

@izikaj

@izikaj izikaj commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Summary

The mailtrap SDK exposes batchSend against all three sending streams, but the MCP server only wired up two of them. The send surface is a 3×2 grid (transactional / bulk / sandbox × single send / batchSend), and the sandbox×batch cell was empty:

stream single send() batchSend()
transactional send-email batch-send-transactional-email
bulk batch-send-bulk-email
sandbox send-sandbox-email batch-send-sandbox-email (this PR)

Registers one new tool, batch-send-sandbox-email, so sandbox users can batch in a single API call instead of looping send-sandbox-email.

Changes

  • Tool (src/tools/sandbox/batchSendSandboxEmail.ts): resolves the sandbox, builds the payload, posts via a sandbox client. buildBatchPayload, getSandboxClient, and resolveSandboxId were already stream-agnostic, so no new client, payload, or resolver logic was needed — the SDK routes to TESTING_ENDPOINT/api/batch/{inboxId} on its own.
  • Schema (src/tools/sandbox/schemas/batchSendSandboxEmail.ts): the shared batch schema plus sandbox_id. Built by spreading into a fresh properties object — all three batch tools re-export one shared schema object, so an in-place edit would leak sandbox_id into the transactional and bulk tools.
  • Types (src/types/mailtrap.ts): BatchSendSandboxEmailToolRequest extends the existing batch request with sandbox_id.
  • Docs: tool description in server.ts, plus README.md and CLAUDE.md. Also corrected the MAILTRAP_ACCOUNT_ID / DEFAULT_FROM_EMAIL notes, which listed only the single-send tools but apply to the batch tools too, and flagged MAILTRAP_TEST_INBOX_ID as the legacy alias it is.
  • Tests: 7 cases — payload forwarding, sandbox_id not leaking into the SDK payload, MAILTRAP_SANDBOX_ID fallback, legacy MAILTRAP_TEST_INBOX_ID fallback and its precedence, missing-sandbox error, validation passthrough, API error prefix.

Notes

  • Named batch-send-sandbox-email, not "bulk sandbox": the SDK throws BULK_SANDBOX_INCOMPATIBLE when bulk and sandbox are both set, so that combination cannot exist. The axis these tools vary on is the stream.
  • Exposes sandbox_id, not test_inbox_id. MAILTRAP_TEST_INBOX_ID is a legacy alias for MAILTRAP_SANDBOX_ID, and a new tool shouldn't advertise it — the schema description is what the model reads when deciding how to call the tool, and the error message is what a user sees when nothing is configured. Existing configs still resolve via resolveSandboxId's MAILTRAP_SANDBOX_ID ?? MAILTRAP_TEST_INBOX_ID fallback, which is covered by a test. This also means the tool needs no changes to resolveSandboxId itself, so the PR doesn't touch a helper shared by 14 other tools.
  • Returns raw JSON like the sibling batch tools rather than send-sandbox-email's human-readable summary, which would discard batchSend's per-request errors[].
  • Accepts any of to/cc/bcc rather than requiring to, matching buildBatchPayload's actual behaviour over the SDK's stricter type.
  • attachments remains unsupported here, consistent with the four existing send tools. The SDK accepts it on batch base, each requests[] entry, and single Mail, but every MCP send schema omits it under additionalProperties: false — worth its own ticket rather than a one-off divergence.

Follow-up (not in this PR)

send-sandbox-email, get-sandbox-messages, show-sandbox-email-message, and get-sandbox-inbox predate resolveSandboxId and inline their own env lookup, reading only the legacy MAILTRAP_TEST_INBOX_ID with no MAILTRAP_SANDBOX_ID fallback. So a config with only MAILTRAP_SANDBOX_ID set works for this new tool but errors on those four. Routing them through resolveSandboxId is a clean separate change — their existing error strings already match the helper's output.

Summary by CodeRabbit

  • New Features

    • Added batch email sending to Mailtrap test inboxes through the batch-send-sandbox-email tool.
    • Supports shared and recipient-specific email fields, sandbox ID selection, and environment-based fallback.
    • Includes input validation and clear success or error responses.
  • Documentation

    • Updated setup and tool documentation with sandbox routing, configuration, parameters, supported fields, and validation details.

@izikaj izikaj self-assigned this Aug 6, 2026
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds the batch-send-sandbox-email MCP tool. It validates batch requests, resolves the sandbox from the request or environment configuration, sends transformed payloads through the sandbox client, and documents and tests the behavior.

Changes

Batch sandbox email

Layer / File(s) Summary
Request contracts and schema
src/types/mailtrap.ts, src/tools/sandbox/schemas/batchSendSandboxEmail.ts
Adds the batch sandbox request interface and schema with an optional numeric sandbox_id.
Batch handler and MCP registration
src/tools/sandbox/batchSendSandboxEmail.ts, src/tools/sandbox/index.ts, src/server.ts
Resolves the sandbox, transforms and sends the batch payload, returns standardized responses, and registers the MCP tool.
Validation coverage and tool documentation
src/tools/sandbox/__tests__/batchSendSandboxEmail.test.ts, README.md, CLAUDE.md
Covers sandbox selection, payload transformation, validation, and API errors. Documents batch structure and sandbox configuration.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant MCPClient
  participant batchSendSandboxEmail
  participant SandboxClient
  MCPClient->>batchSendSandboxEmail: Submit batch request
  batchSendSandboxEmail->>SandboxClient: Send transformed payload to resolved sandbox
  SandboxClient-->>batchSendSandboxEmail: Return API response
  batchSendSandboxEmail-->>MCPClient: Return success or error response
Loading

Possibly related PRs

Suggested reviewers: igordobryn, mklocek, vladimirtaytor

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely identifies the main change: adding the batch-send sandbox email tool.
Description check ✅ Passed The description clearly explains the motivation, implementation changes, testing coverage, and follow-up items, although it does not use every template heading.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@izikaj
izikaj marked this pull request as ready for review August 6, 2026 08:46

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/tools/sandbox/utils/resolveSandboxId.ts`:
- Around line 10-18: Update resolveSandboxId to resolve process.env[envName]
before the compatibility fallback to MAILTRAP_TEST_INBOX_ID, while preserving
the explicit sandboxId precedence. Add coverage with both environment variables
set to verify batch-send-sandbox-email uses MAILTRAP_TEST_INBOX_ID when it
passes that envName.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9d72b351-8e63-4a4c-87d1-2f3f5a51b8f1

📥 Commits

Reviewing files that changed from the base of the PR and between 574eb72 and f16a265.

📒 Files selected for processing (9)
  • CLAUDE.md
  • README.md
  • src/server.ts
  • src/tools/sandbox/__tests__/batchSendSandboxEmail.test.ts
  • src/tools/sandbox/batchSendSandboxEmail.ts
  • src/tools/sandbox/index.ts
  • src/tools/sandbox/schemas/batchSendSandboxEmail.ts
  • src/tools/sandbox/utils/resolveSandboxId.ts
  • src/types/mailtrap.ts

Comment thread src/tools/sandbox/utils/resolveSandboxId.ts Outdated
MAILTRAP_TEST_INBOX_ID is a legacy alias for MAILTRAP_SANDBOX_ID, so a new
tool should not advertise it — the schema description is what the model reads
when deciding how to call the tool, and the error message is what a user sees
when nothing is configured. Both now name the canonical variable.

Renaming the parameter also removes the need for the paramName/envName
arguments added to resolveSandboxId: the helper is back to its pre-PR form,
identical to main, so this branch no longer touches a file shared by 14 tools.
Legacy configs keep working via the helper's existing MAILTRAP_TEST_INBOX_ID
fallback, now covered by a test.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/types/mailtrap.ts`:
- Around line 85-87: Rename the batch sandbox identifier from sandbox_id to
test_inbox_id across BatchSendSandboxEmailToolRequest and its related schema,
downstream handler, and documentation, matching SendSandboxEmailRequest and the
public contract. Ensure the handler reads test_inbox_id so caller-provided inbox
selection is preserved, and remove remaining batch-flow references to
sandbox_id.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f5364cd6-6dd3-4de1-b1e4-31f978e717e2

📥 Commits

Reviewing files that changed from the base of the PR and between f16a265 and 10f3a9d.

📒 Files selected for processing (7)
  • CLAUDE.md
  • README.md
  • src/server.ts
  • src/tools/sandbox/__tests__/batchSendSandboxEmail.test.ts
  • src/tools/sandbox/batchSendSandboxEmail.ts
  • src/tools/sandbox/schemas/batchSendSandboxEmail.ts
  • src/types/mailtrap.ts
🚧 Files skipped from review as they are similar to previous changes (6)
  • CLAUDE.md
  • src/server.ts
  • README.md
  • src/tools/sandbox/batchSendSandboxEmail.ts
  • src/tools/sandbox/tests/batchSendSandboxEmail.test.ts
  • src/tools/sandbox/schemas/batchSendSandboxEmail.ts

Comment thread src/types/mailtrap.ts
Comment thread README.md Outdated
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@izikaj
izikaj merged commit 049b97c into main Aug 7, 2026
2 checks passed
@izikaj
izikaj deleted the add-bulk-send-sandbox-email-tool branch August 7, 2026 06:03
@github-actions github-actions Bot mentioned this pull request Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants