get-sandbox-messages
Retrieve test email messages from the Mailtrap sandbox inbox for debugging and verification purposes, with pagination and search filtering options.
Instructions
Get list of messages from the sandbox test inbox
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page | No | Page number for pagination | |
| last_id | No | Pagination using last message ID. Returns messages after the specified message ID. | |
| search | No | Search query to filter messages |
Implementation Reference
- The main handler function for the 'get-sandbox-messages' tool. It retrieves messages from the Mailtrap sandbox test inbox using the sandboxClient, handles pagination and search, formats the message list, and returns formatted content or error.async function getMessages({ page, last_id, search, }: GetMessagesRequest): Promise<{ content: { type: string; text: string }[]; 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); if (Number.isNaN(inboxId)) { throw new Error("MAILTRAP_TEST_INBOX_ID must be a valid number"); } // Get messages from the inbox // MessageListOptions supports: page, last_id, and search const options: { page?: number; last_id?: number; search?: string; } = {}; if (page !== undefined) { options.page = page; } if (last_id !== undefined) { options.last_id = last_id; } if (search !== undefined) { options.search = search; } const messages = await sandboxClient.testing.messages.get( inboxId, Object.keys(options).length > 0 ? options : undefined ); if (!messages || messages.length === 0) { return { content: [ { type: "text", text: "No messages found in the sandbox inbox.", }, ], }; } const messageList = messages .map( (message: (typeof messages)[0]) => `• Message ID: ${message.id}\n From: ${message.from_email}\n To: ${ message.to_email }\n Subject: ${message.subject}\n Sent: ${ message.sent_at }\n Read: ${message.is_read ? "Yes" : "No"}\n` ) .join("\n"); return { content: [ { type: "text", text: `Found ${messages.length} message(s) in sandbox inbox:\n\n${messageList}`, }, ], }; } catch (error) { console.error("Error getting messages:", error); const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `Failed to get messages: ${errorMessage}`, }, ], isError: true, }; } }
- JSON Schema defining the input parameters for the 'get-sandbox-messages' tool, including optional page, last_id for pagination, and search.const getMessagesSchema = { type: "object", properties: { page: { type: "number", description: "Page number for pagination", minimum: 1, }, last_id: { type: "number", description: "Pagination using last message ID. Returns messages after the specified message ID.", minimum: 1, }, search: { type: "string", description: "Search query to filter messages", }, }, required: [], additionalProperties: false, }; export default getMessagesSchema;
- src/server.ts:92-97 (registration)Tool registration in the main tools array of the MCP server, specifying name, description, inputSchema, and handler.{ name: "get-sandbox-messages", description: "Get list of messages from the sandbox test inbox", inputSchema: getMessagesSchema, handler: getMessages, },