search_emails
Query and retrieve emails from specific accounts using Microsoft Graph API. Input search terms, account ID, and optional filters to streamline results.
Instructions
Search emails using the modern search API.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| account_id | Yes | ||
| folder | No | ||
| limit | No | ||
| query | Yes |
Implementation Reference
- src/microsoft_mcp/tools.py:862-887 (handler)The main handler function for the 'search_emails' tool. It performs email searches using either folder-specific traditional search or unified modern search via Microsoft Graph API, depending on whether a folder is specified.@mcp.tool def search_emails( query: str, account_id: str, limit: int = 50, folder: str | None = None, ) -> list[dict[str, Any]]: """Search emails using the modern search API.""" if folder: # For folder-specific search, use the traditional endpoint folder_path = FOLDERS.get(folder.casefold(), folder) endpoint = f"/me/mailFolders/{folder_path}/messages" params = { "$search": f'"{query}"', "$top": min(limit, 100), "$select": "id,subject,from,toRecipients,receivedDateTime,hasAttachments,body,conversationId,isRead", } return list( graph.request_paginated(endpoint, account_id, params=params, limit=limit) ) return list(graph.search_query(query, ["message"], account_id, limit))