UNPKG

msexchange-mcp

Version:

MCP server for Microsoft Exchange/Outlook email operations via Microsoft Graph API

103 lines (84 loc) • 3.35 kB
#!/usr/bin/env node // Test script to check rate limiting and large query behavior import { MailService } from './dist/mail/mailService.js'; import { loadConfig } from './dist/config/config.js'; console.log('šŸ” Testing large email queries and rate limiting...\n'); async function testLargeQueries() { try { const testEmail = 'olivier@surge.management'; const mailService = new MailService(testEmail); console.log('šŸ“§ Testing different query sizes:'); // Test various sizes const testSizes = [10, 50, 100, 200, 500, 1000, 1500]; for (const size of testSizes) { console.log(`\nšŸ”¢ Testing query with limit ${size}...`); const startTime = Date.now(); try { const emails = await mailService.queryEmails({ top: size, select: ['id', 'subject', 'from', 'receivedDateTime'] }); const duration = Date.now() - startTime; console.log(` āœ… Success: Retrieved ${emails.length} emails in ${duration}ms`); if (emails.length < size) { console.log(` āš ļø Note: Requested ${size} but only got ${emails.length} emails (may be max available)`); } } catch (error) { const duration = Date.now() - startTime; console.log(` āŒ Failed after ${duration}ms: ${error.message}`); if (error.message.includes('429') || error.message.includes('throttl')) { console.log(` 🚨 Rate limiting detected!`); } } // Add delay between requests to avoid throttling console.log(' ā° Waiting 2 seconds before next test...'); await new Promise(resolve => setTimeout(resolve, 2000)); } } catch (error) { console.error('āŒ Test failed:', error); } } // Test concurrent requests async function testConcurrentRequests() { console.log('\nšŸš€ Testing concurrent requests...'); const testEmail = 'olivier@surge.management'; const mailService = new MailService(testEmail); // Test with 5 concurrent requests (above the 4 limit) const promises = Array.from({ length: 5 }, (_, i) => mailService.queryEmails({ top: 50, skip: i * 50, select: ['id', 'subject', 'receivedDateTime'] }).then(emails => ({ requestIndex: i, success: true, count: emails.length })).catch(error => ({ requestIndex: i, success: false, error: error.message })) ); console.log('ā³ Making 5 concurrent requests...'); const results = await Promise.all(promises); results.forEach(result => { if (result.success) { console.log(` āœ… Request ${result.requestIndex}: ${result.count} emails`); } else { console.log(` āŒ Request ${result.requestIndex}: ${result.error}`); } }); } // Run tests testLargeQueries() .then(() => testConcurrentRequests()) .then(() => { console.log('\nšŸŽÆ Test Summary:'); console.log('- Microsoft Graph API limits $top parameter to 1000 for messages'); console.log('- Mailbox concurrency limit is 4 concurrent requests per app per mailbox'); console.log('- Large queries may timeout or hit memory limits'); console.log('- Proper pagination and rate limiting handling is essential'); }) .catch(error => { console.error('Test suite failed:', error); });