get_recent_emails
Fetch the most recent emails from a specified mailbox, with configurable count and sorting direction.
Instructions
Get the most recent emails from inbox (like top-ten)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Number of recent emails to retrieve (default: 10, max: 50) | |
| mailboxName | No | Mailbox to search (default: inbox) | inbox |
| ascending | No | Sort oldest first instead of newest first (default: false) |
Implementation Reference
- src/jmap-client.ts:715-748 (handler)The getRecentEmails method on JmapClient queries a mailbox (defaults to inbox) and returns the most recent emails. It resolves the mailbox by role or name, then performs an Email/query + Email/get JMAP call.
async getRecentEmails(limit: number = 10, mailboxName: string = 'inbox', ascending: boolean = false): Promise<any[]> { const session = await this.getSession(); // Find the specified mailbox (default to inbox) const mailboxes = await this.getMailboxes(); const targetMailbox = mailboxes.find(mb => mb.role === mailboxName.toLowerCase() || mb.name.toLowerCase().includes(mailboxName.toLowerCase()) ); if (!targetMailbox) { throw new Error(`Could not find mailbox: ${mailboxName}`); } const request: JmapRequest = { using: ['urn:ietf:params:jmap:core', 'urn:ietf:params:jmap:mail'], methodCalls: [ ['Email/query', { accountId: session.accountId, filter: { inMailbox: targetMailbox.id }, sort: [{ property: 'receivedAt', isAscending: ascending }], limit: Math.min(limit, 50) }, 'query'], ['Email/get', { accountId: session.accountId, '#ids': { resultOf: 'query', name: 'Email/query', path: '/ids' }, properties: ['id', 'subject', 'from', 'to', 'replyTo', 'receivedAt', 'preview', 'hasAttachment', 'keywords', 'header:List-Unsubscribe:asURLs'] }, 'emails'] ] }; const response = await this.makeRequest(request); return this.getListResult(response, 1); } - src/index.ts:588-609 (registration)Tool registration schema for 'get_recent_emails' defining the input parameters (limit, mailboxName, ascending) with descriptions and defaults.
name: 'get_recent_emails', description: 'Get the most recent emails from inbox (like top-ten)', inputSchema: { type: 'object', properties: { limit: { type: ['number', 'string'], description: 'Number of recent emails to retrieve (default: 10, max: 50)', default: 10, }, mailboxName: { type: 'string', description: 'Mailbox to search (default: inbox)', default: 'inbox', }, ascending: { type: 'boolean', description: 'Sort oldest first instead of newest first (default: false)', }, }, }, }, - src/index.ts:1393-1405 (handler)Call handler in index.ts that extracts arguments (limit, mailboxName, ascending) and delegates to client.getRecentEmails(), returning JSON results.
case 'get_recent_emails': { const { limit = 10, mailboxName = 'inbox', ascending } = args as any; const client = initializeClient(); const emails = await client.getRecentEmails(limit, mailboxName, !!ascending); return { content: [ { type: 'text', text: JSON.stringify(emails, null, 2), }, ], }; }