get_attachment
Download email attachments to a specified file path using the Microsoft MCP server. Input email ID, attachment ID, save path, and account ID to retrieve and store attachments efficiently.
Instructions
Download email attachment to a specified file path
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| account_id | Yes | ||
| attachment_id | Yes | ||
| email_id | Yes | ||
| save_path | Yes |
Implementation Reference
- src/microsoft_mcp/tools.py:812-837 (handler)The core handler function for the 'get_attachment' tool. It retrieves the attachment from Microsoft Graph API using the provided email_id and attachment_id, decodes the base64-encoded contentBytes, saves the file to the specified save_path, and returns metadata including name, content_type, size, and saved path.def get_attachment( email_id: str, attachment_id: str, save_path: str, account_id: str ) -> dict[str, Any]: """Download email attachment to a specified file path""" result = graph.request( "GET", f"/me/messages/{email_id}/attachments/{attachment_id}", account_id ) if not result: raise ValueError("Attachment not found") if "contentBytes" not in result: raise ValueError("Attachment content not available") # Save attachment to file path = pl.Path(save_path).expanduser().resolve() path.parent.mkdir(parents=True, exist_ok=True) content_bytes = base64.b64decode(result["contentBytes"]) path.write_bytes(content_bytes) return { "name": result.get("name", "unknown"), "content_type": result.get("contentType", "application/octet-stream"), "size": result.get("size", 0), "saved_to": str(path), }
- src/microsoft_mcp/server.py:3-14 (registration)The server entry point imports the FastMCP instance (mcp) from tools.py where all tools including get_attachment are decorated and registered, and calls mcp.run() to start the MCP server, making the tool available.from .tools import mcp def main() -> None: if not os.getenv("MICROSOFT_MCP_CLIENT_ID"): print( "Error: MICROSOFT_MCP_CLIENT_ID environment variable is required", file=sys.stderr, ) sys.exit(1) mcp.run()
- src/microsoft_mcp/tools.py:5-8 (registration)Creates the FastMCP server instance named 'microsoft-mcp' to which all tools, including get_attachment, are registered via @mcp.tool decorators.from fastmcp import FastMCP from . import graph, auth mcp = FastMCP("microsoft-mcp")