Skip to main content
Glama
mailtrap

MCP Mailtrap Server

Official
by mailtrap

show-sandbox-email-message

Retrieve and view detailed content of test emails from the Mailtrap sandbox inbox for debugging and verification purposes.

Instructions

Show sandbox email message details and content from the sandbox test inbox

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
message_idYesID of the sandbox email message to retrieve

Implementation Reference

  • The main handler function that fetches the sandbox email message details, HTML, and text content using Mailtrap API, formats them, and returns as MCP content blocks.
    async function showEmailMessage({
      message_id,
    }: ShowEmailMessageRequest): Promise<{ content: any[]; isError?: boolean }> {
      try {
        const { MAILTRAP_TEST_INBOX_ID } = process.env;
    
        if (!MAILTRAP_TEST_INBOX_ID) {
          throw new Error(
            "MAILTRAP_TEST_INBOX_ID environment variable is required for sandbox mode"
          );
        }
    
        // Check if sandbox client is available
        if (!sandboxClient) {
          throw new Error(
            "Sandbox client is not available. Please set MAILTRAP_TEST_INBOX_ID environment variable."
          );
        }
    
        const inboxId = Number(MAILTRAP_TEST_INBOX_ID);
    
        // Get message details
        // The showEmailMessage method takes inboxId and messageId
        const message = await sandboxClient.testing.messages.showEmailMessage(
          inboxId,
          message_id
        );
    
        if (!message) {
          return {
            content: [
              {
                type: "text",
                text: `Message with ID ${message_id} not found.`,
              },
            ],
            isError: true,
          };
        }
    
        // Get HTML and text content
        let htmlContent = "";
        let textContent = "";
    
        try {
          htmlContent = await sandboxClient.testing.messages.getHtmlMessage(
            inboxId,
            message_id
          );
        } catch (error) {
          // HTML might not be available
          console.warn("Could not retrieve HTML content:", error);
        }
    
        try {
          textContent = await sandboxClient.testing.messages.getTextMessage(
            inboxId,
            message_id
          );
        } catch (error) {
          // Text might not be available
          console.warn("Could not retrieve text content:", error);
        }
    
        const messageDetails = [
          `Message ID: ${message.id}`,
          `From: ${message.from_email}`,
          `To: ${message.to_email}`,
          `Subject: ${message.subject}`,
          `Sent: ${message.sent_at}`,
          `Read: ${message.is_read ? "Yes" : "No"}`,
          message.html_body_size
            ? `HTML Size: ${message.html_body_size} bytes`
            : "",
          message.text_body_size
            ? `Text Size: ${message.text_body_size} bytes`
            : "",
          message.email_size ? `Total Size: ${message.email_size} bytes` : "",
        ]
          .filter(Boolean)
          .join("\n");
    
        let contentText = `Sandbox Email Message Details:\n\n${messageDetails}`;
    
        if (htmlContent) {
          contentText += `\n\n--- HTML Content ---\n${htmlContent}`;
        }
    
        if (textContent) {
          contentText += `\n\n--- Text Content ---\n${textContent}`;
        }
    
        if (!htmlContent && !textContent) {
          contentText += "\n\nNote: Message body content could not be retrieved.";
        }
    
        return {
          content: [
            {
              type: "text",
              text: contentText,
            },
          ],
        };
      } catch (error) {
        console.error("Error showing sandbox email message:", error);
    
        const errorMessage = error instanceof Error ? error.message : String(error);
    
        return {
          content: [
            {
              type: "text",
              text: `Failed to show sandbox email message: ${errorMessage}`,
            },
          ],
          isError: true,
        };
      }
    }
    
    export default showEmailMessage;
  • JSON Schema defining the input parameters for the tool, requiring a numeric message_id.
    const showEmailMessageSchema = {
      type: "object",
      properties: {
        message_id: {
          type: "number",
          description: "ID of the sandbox email message to retrieve",
        },
      },
      required: ["message_id"],
      additionalProperties: false,
    };
    
    export default showEmailMessageSchema;
  • src/server.ts:98-104 (registration)
    Registration of the tool in the server's tools array, specifying name, description, input schema, and handler function.
    {
      name: "show-sandbox-email-message",
      description:
        "Show sandbox email message details and content from the sandbox test inbox",
      inputSchema: showEmailMessageSchema,
      handler: showEmailMessage,
    },
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It implies a read-only operation ('show') but doesn't disclose permissions needed, rate limits, error conditions, or what 'details and content' includes (e.g., headers, body, attachments). This leaves significant gaps for a tool that retrieves data.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero wasted words. It front-loads the core action ('show sandbox email message details and content') and specifies the source ('from the sandbox test inbox'), making it easy to scan and understand quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is incomplete for a data retrieval tool. It doesn't explain what 'details and content' encompasses (e.g., metadata, body format), potential errors, or how to obtain message IDs (e.g., from 'get-sandbox-messages'). For a tool with one parameter but unknown output complexity, this lacks sufficient context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with the single parameter 'message_id' documented as 'ID of the sandbox email message to retrieve'. The description adds no additional parameter semantics beyond this, such as format examples or ID sourcing. Baseline 3 is appropriate given the schema fully covers the parameter.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'show' and the resource 'sandbox email message details and content', specifying it's from the 'sandbox test inbox'. This distinguishes it from non-sandbox email tools like 'send-email', but doesn't explicitly differentiate from sibling 'get-sandbox-messages' (which likely lists messages rather than showing details of one).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'get-sandbox-messages' (which might list messages) or 'send-sandbox-email' (which sends messages). It mentions the 'sandbox test inbox' context but doesn't specify prerequisites, exclusions, or comparative use cases with siblings.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mailtrap/mailtrap-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server