search_draft_emails
Locate and retrieve draft emails in Microsoft Outlook using specific keywords, streamlining email management and reducing manual search time.
Instructions
Search draft emails
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| count | No | Number of results to return | |
| query | Yes | Search keywords |
Implementation Reference
- src/index.ts:198-216 (registration)Registration of the 'search_draft_emails' tool in the MCP ListToolsRequestSchema handler, defining name, description, and input schema.{ name: "search_draft_emails", description: "Search draft emails", inputSchema: { type: "object", properties: { query: { type: "string", description: "Search keywords" }, count: { type: "number", description: "Number of results to return", default: 10 } }, required: ["query"] } },
- src/index.ts:639-657 (handler)Top-level MCP tool call handler for 'search_draft_emails' that parses arguments, invokes the manager method, and formats the response.case 'search_draft_emails': { const query = (args as any)?.query; const count = (args as any)?.count || 10; if (!query) { throw new Error('Search query is required'); } const drafts = await outlookManager.searchDraftEmails(query, count); return { content: [ { type: 'text', text: `🔍 **Draft Search Results: "${query}"**\nTotal: ${drafts.length} items\n\n📋 **Draft Search Results List:**\n` + drafts.map((draft, index) => `${index + 1}. **${draft.subject}**\n From: ${draft.sender}\n Time: ${draft.receivedTime}\n EntryID: ${draft.id}\n StoreID: ${draft.storeId || 'N/A'}\n Search Context: ${draft.body?.includes(query) ? 'Match in content' : 'Match in subject'}: ${draft.subject}\n Preview: ${draft.body?.substring(0, 100)}...\n` ).join('\n') }, ], }; }
- src/outlook-manager.ts:381-386 (handler)Implementation of searchDraftEmails in OutlookManager that fetches draft emails and filters them using EmailSummarizer.searchEmails.async searchDraftEmails(query: string, count: number = 10): Promise<EmailMessage[]> { const emails = await this.getDraftEmails(Math.min(count * 2, 50)); const { EmailSummarizer } = await import('./email-summarizer.js'); const searchResults = EmailSummarizer.searchEmails(emails, query); return searchResults.slice(0, count); }
- src/email-summarizer.ts:42-62 (helper)Static helper method EmailSummarizer.searchEmails that implements the core search logic by filtering emails matching the query in subject, sender, or body.static searchEmails(emails: EmailMessage[], searchTerm: string): EmailMessage[] { if (!searchTerm.trim()) { return emails; } const normalizedSearchTerm = searchTerm.toLowerCase(); return emails.filter(email => { // Search in subject const subjectMatch = email.subject.toLowerCase().includes(normalizedSearchTerm); // Search in sender const senderMatch = email.sender.toLowerCase().includes(normalizedSearchTerm); // Search in body content (remove HTML tags before searching) const cleanBody = email.body.replace(/<[^>]*>/g, '').toLowerCase(); const bodyMatch = cleanBody.includes(normalizedSearchTerm); return subjectMatch || senderMatch || bodyMatch; }); }