get_email
Retrieve detailed email information, including body content and attachment metadata, using email ID and account ID. Manage content size with customizable limits for streamlined email data extraction on Microsoft MCP.
Instructions
Get email details with size limits
Args:
email_id: The email ID
account_id: The account ID
include_body: Whether to include the email body (default: True)
body_max_length: Maximum characters for body content (default: 50000)
include_attachments: Whether to include attachment metadata (default: True)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| account_id | Yes | ||
| body_max_length | No | ||
| email_id | Yes | ||
| include_attachments | No | ||
| include_body | No |
Implementation Reference
- src/microsoft_mcp/tools.py:165-209 (handler)The handler function for the 'get_email' tool. It retrieves email details from Microsoft Graph API, supports optional body inclusion with truncation, and processes attachments by removing content bytes to limit size.@mcp.tool def get_email( email_id: str, account_id: str, include_body: bool = True, body_max_length: int = 50000, include_attachments: bool = True, ) -> dict[str, Any]: """Get email details with size limits Args: email_id: The email ID account_id: The account ID include_body: Whether to include the email body (default: True) body_max_length: Maximum characters for body content (default: 50000) include_attachments: Whether to include attachment metadata (default: True) """ params = {} if include_attachments: params["$expand"] = "attachments($select=id,name,size,contentType)" result = graph.request("GET", f"/me/messages/{email_id}", account_id, params=params) if not result: raise ValueError(f"Email with ID {email_id} not found") # Truncate body if needed if include_body and "body" in result and "content" in result["body"]: content = result["body"]["content"] if len(content) > body_max_length: result["body"]["content"] = ( content[:body_max_length] + f"\n\n[Content truncated - {len(content)} total characters]" ) result["body"]["truncated"] = True result["body"]["total_length"] = len(content) elif not include_body and "body" in result: del result["body"] # Remove attachment content bytes to reduce size if "attachments" in result and result["attachments"]: for attachment in result["attachments"]: if "contentBytes" in attachment: del attachment["contentBytes"] return result