search_emails
Search emails by subject or content. Specify a query, limit results, and sort oldest first if needed.
Instructions
Search emails by subject or content
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search query string | |
| limit | No | Maximum number of results (default: 20) | |
| ascending | No | Sort oldest first instead of newest first (default: false) |
Implementation Reference
- src/index.ts:416-438 (registration)Tool registration for 'search_emails' — defines the name, description, and input schema (query, limit, ascending) in the ListTools handler.
{ name: 'search_emails', description: 'Search emails by subject or content', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search query string', }, limit: { type: ['number', 'string'], description: 'Maximum number of results (default: 20)', default: 20, }, ascending: { type: 'boolean', description: 'Sort oldest first instead of newest first (default: false)', }, }, required: ['query'], }, }, - src/index.ts:1240-1255 (handler)Handler for the 'search_emails' tool call — extracts query, limit, ascending args, validates query is present, and delegates to client.searchEmails().
case 'search_emails': { const { query, limit, ascending } = args as any; if (!query) { throw new McpError(ErrorCode.InvalidParams, 'query is required'); } const validLimit = Math.min(Math.max(Number(limit) || 20, 1), 100); const emails = await client.searchEmails(query, validLimit, !!ascending); return { content: [ { type: 'text', text: JSON.stringify(emails, null, 2), }, ], }; } - src/jmap-client.ts:1246-1268 (handler)Actual implementation of searchEmails() on JmapClient — builds a JMAP Email/query with a text filter, then fetches matching emails via Email/get.
async searchEmails(query: string, limit: number = 20, ascending: boolean = false): Promise<any[]> { const session = await this.getSession(); const request: JmapRequest = { using: ['urn:ietf:params:jmap:core', 'urn:ietf:params:jmap:mail'], methodCalls: [ ['Email/query', { accountId: session.accountId, filter: { text: query }, sort: [{ property: 'receivedAt', isAscending: ascending }], limit }, 'query'], ['Email/get', { accountId: session.accountId, '#ids': { resultOf: 'query', name: 'Email/query', path: '/ids' }, properties: ['id', 'subject', 'from', 'to', 'replyTo', 'receivedAt', 'preview', 'hasAttachment'] }, 'emails'] ] }; const response = await this.makeRequest(request); return this.getListResult(response, 1); } - src/index.ts:419-437 (schema)Input schema for search_emails — requires 'query' (string), optional 'limit' (number/string, default 20), optional 'ascending' (boolean).
inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search query string', }, limit: { type: ['number', 'string'], description: 'Maximum number of results (default: 20)', default: 20, }, ascending: { type: 'boolean', description: 'Sort oldest first instead of newest first (default: false)', }, }, required: ['query'], },