Skip to main content
Glama

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
NameRequiredDescriptionDefault
account_idYes
attachment_idYes
email_idYes
save_pathYes

Implementation Reference

  • 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),
        }
  • 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()
  • 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")
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions downloading to a file path, implying a write operation, but doesn't disclose behavioral traits like permissions needed, file overwriting, network usage, error handling, or format of downloaded content. For a tool with no annotations, this leaves significant gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core action. Every word earns its place with no redundancy or unnecessary details, making it highly concise and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 4 parameters with 0% schema coverage, no annotations, and no output schema, the description is incomplete. It lacks details on parameter meanings, behavioral context (e.g., file system interactions), and expected outcomes, making it inadequate for a tool of this complexity.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It only mentions 'specified file path' (mapping to save_path), but doesn't explain account_id, attachment_id, or email_id parameters. With 4 parameters and low coverage, the description adds minimal semantic value beyond the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Download') and resource ('email attachment') with the destination ('to a specified file path'). It distinguishes from siblings like get_email or get_file by specifying attachment retrieval. However, it doesn't explicitly differentiate from potential similar tools (though none exist in the sibling list).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus alternatives is provided. The description doesn't mention prerequisites (e.g., authentication), constraints, or sibling tools like get_email for email content. It's a standalone statement without context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/elyxlz/microsoft-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server