test_bulk_operations
Find recent emails and perform safe bulk mark-as-read or unread operations. Use dry run to preview changes before applying.
Instructions
Test bulk operations by finding recent emails and performing safe operations (mark read/unread)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dryRun | No | If true, only shows what would be done without making changes (default: true) | |
| limit | No | Number of emails to test with (default: 3, max: 10) |
Implementation Reference
- src/index.ts:969-987 (registration)Tool registration in ListToolsRequestSchema handler for 'test_bulk_operations' with inputSchema defining dryRun (boolean, default true) and limit (number, default 3, max 10)
{ name: 'test_bulk_operations', description: 'Test bulk operations by finding recent emails and performing safe operations (mark read/unread)', inputSchema: { type: 'object', properties: { dryRun: { type: 'boolean', description: 'If true, only shows what would be done without making changes (default: true)', default: true, }, limit: { type: 'number', description: 'Number of emails to test with (default: 3, max: 10)', default: 3, }, }, }, }, - src/index.ts:1814-1906 (handler)Handler case 'test_bulk_operations' in CallToolRequestSchema. Fetches recent emails, tests bulk_mark_read (mark as read then undo/unread). Supports dryRun mode (default true). Executes real bulk operations when dryRun=false, with error handling per operation.
case 'test_bulk_operations': { const { dryRun = true, limit = 3 } = args as any; const client = initializeClient(); // Get some recent emails to test with const testLimit = Math.min(Math.max(limit, 1), 10); const emails = await client.getRecentEmails(testLimit, 'inbox'); if (emails.length === 0) { return { content: [ { type: 'text', text: 'No emails found for bulk operation testing. Try sending yourself a test email first.', }, ], }; } const emailIds = emails.slice(0, testLimit).map(email => email.id); const operations = [ { name: 'bulk_mark_read', description: `Mark ${emailIds.length} emails as read`, parameters: { emailIds, read: true } }, { name: 'bulk_mark_read (undo)', description: `Mark ${emailIds.length} emails as unread (undo previous)`, parameters: { emailIds, read: false } } ]; const results = { testEmails: emails.map(email => ({ id: email.id, subject: email.subject, from: email.from?.[0]?.email || 'unknown', receivedAt: email.receivedAt })), operations: [] as any[] }; if (dryRun) { results.operations = operations.map(op => ({ ...op, status: 'DRY RUN - Would execute but not actually performed', executed: false })); return { content: [ { type: 'text', text: `BULK OPERATIONS TEST (DRY RUN)\n\n${JSON.stringify(results, null, 2)}\n\nTo actually execute the test, set dryRun: false`, }, ], }; } else { // Execute the test operations for (const operation of operations) { try { await client.bulkMarkRead(operation.parameters.emailIds, operation.parameters.read); results.operations.push({ ...operation, status: 'SUCCESS', executed: true, timestamp: new Date().toISOString() }); // Small delay between operations await new Promise(resolve => setTimeout(resolve, 500)); } catch (error) { results.operations.push({ ...operation, status: 'FAILED', executed: false, error: error instanceof Error ? error.message : String(error), timestamp: new Date().toISOString() }); } } return { content: [ { type: 'text', text: `BULK OPERATIONS TEST (EXECUTED)\n\n${JSON.stringify(results, null, 2)}`, }, ], }; } } - src/index.ts:1834-1845 (helper)Operations array defined within the handler containing two test operations: bulk_mark_read (mark as read) and bulk_mark_read undo (mark as unread).
const operations = [ { name: 'bulk_mark_read', description: `Mark ${emailIds.length} emails as read`, parameters: { emailIds, read: true } }, { name: 'bulk_mark_read (undo)', description: `Mark ${emailIds.length} emails as unread (undo previous)`, parameters: { emailIds, read: false } } ];