Skip to main content
Glama

list_emails

Retrieve emails from a specified Outlook folder using a Microsoft MCP server. Configure account ID, folder, limit, and body inclusion for precise email listing.

Instructions

List emails from specified folder

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
account_idYes
folderNoinbox
include_bodyNo
limitNo

Implementation Reference

  • The handler function for the 'list_emails' tool. It lists emails from a specified Microsoft mail folder using the Microsoft Graph API, with options for folder, limit, and whether to include body content.
    @mcp.tool
    def list_emails(
        account_id: str,
        folder: str = "inbox",
        limit: int = 10,
        include_body: bool = True,
    ) -> list[dict[str, Any]]:
        """List emails from specified folder"""
        folder_path = FOLDERS.get(folder.casefold(), folder)
    
        if include_body:
            select_fields = "id,subject,from,toRecipients,ccRecipients,receivedDateTime,hasAttachments,body,conversationId,isRead"
        else:
            select_fields = "id,subject,from,toRecipients,receivedDateTime,hasAttachments,conversationId,isRead"
    
        params = {
            "$top": min(limit, 100),
            "$select": select_fields,
            "$orderby": "receivedDateTime desc",
        }
    
        emails = list(
            graph.request_paginated(
                f"/me/mailFolders/{folder_path}/messages",
                account_id,
                params=params,
                limit=limit,
            )
        )
    
        return emails
  • Helper dictionary mapping user-friendly folder names to Microsoft Graph API folder paths, used by the list_emails handler.
    FOLDERS = {
        k.casefold(): v
        for k, v in {
            "inbox": "inbox",
            "sent": "sentitems",
            "drafts": "drafts",
            "deleted": "deleteditems",
            "junk": "junkemail",
            "archive": "archive",
        }.items()
    }
  • Creation of the FastMCP instance where tools like list_emails are registered via decorators.
    mcp = FastMCP("microsoft-mcp")
  • Import of the MCP instance from tools.py, which triggers registration of all decorated tools including list_emails, and runs the server.
    from .tools import mcp

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