Skip to main content
Glama

test_connection

Verify IMAP and SMTP server connectivity to ensure email services are properly configured and accessible.

Instructions

Test the email server connection (IMAP and SMTP)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Handler for the test_connection tool in the MCP server request handler. Validates mailClient existence and delegates to mailClient.testConnection(), returning the result as JSON text.
    case 'test_connection': { if (!mailClient) { throw new McpError( ErrorCode.InvalidRequest, 'iCloud Mail not configured. Please set ICLOUD_EMAIL and ICLOUD_APP_PASSWORD environment variables.' ); } const result = await mailClient.testConnection(); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }
  • Core implementation of testConnection method in ICloudMailClient class. Tests IMAP (connect/disconnect) and SMTP (verify with timeout), provides detailed success/error responses with troubleshooting tips.
    async testConnection(): Promise<{ status: string; message: string }> { try { console.error('Testing IMAP connection...'); await this.connect(); console.error('IMAP connection successful, disconnecting...'); await this.disconnect(); console.error('Testing SMTP connection...'); // Test SMTP connection with timeout await Promise.race([ this.transporter.verify(), new Promise((_, reject) => setTimeout( () => reject(new Error('SMTP verification timeout after 30 seconds')), 30000 ) ), ]); console.error('SMTP connection successful'); return { status: 'success', message: 'Email connection test successful - both IMAP and SMTP are working', }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); console.error('Connection test failed:', errorMessage); // Provide helpful error messages based on common issues let helpfulMessage = errorMessage; if ( errorMessage.includes('authenticate') || errorMessage.includes('Invalid credentials') ) { helpfulMessage += "\n\nTroubleshooting:\n1. Ensure you're using an app-specific password, not your regular Apple ID password\n2. Verify that two-factor authentication is enabled on your Apple ID\n3. Generate a new app-specific password if the current one isn't working\n4. Check that your Apple ID hasn't been locked"; } else if ( errorMessage.includes('timeout') || errorMessage.includes('ENOTFOUND') || errorMessage.includes('ECONNREFUSED') ) { helpfulMessage += '\n\nTroubleshooting:\n1. Check your internet connection\n2. Verify firewall settings allow connections to iCloud mail servers\n3. Try connecting from a different network'; } return { status: 'error', message: helpfulMessage, }; } }
  • src/index.ts:139-145 (registration)
    Registration of the test_connection tool in the MCP tools list, with description and empty input schema (no parameters required).
    name: 'test_connection', description: 'Test the email server connection (IMAP and SMTP)', inputSchema: { type: 'object', properties: {}, }, },

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/Racimy/iMail-mcp'

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