Skip to main content
Glama

get_inbox_emails

Retrieve recent emails from your Outlook inbox to monitor messages, track communications, or process incoming information.

Instructions

Get inbox email list

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
countNoNumber of emails to retrieve

Implementation Reference

  • Input/output schema definition for the get_inbox_emails tool, specifying optional count parameter.
      name: "get_inbox_emails",
      description: "Get inbox email list",
      inputSchema: {
        type: "object",
        properties: {
          count: {
            type: "number",
            description: "Number of emails to retrieve",
            default: 10
          }
        }
      }
    },
  • MCP CallToolRequestSchema handler case that executes get_inbox_emails by calling outlookManager.getInboxEmails and formatting the markdown response.
    case 'get_inbox_emails': {
      const count = (args as any)?.count || 10;
      const emails = await outlookManager.getInboxEmails(count);
      return {
        content: [
          {
            type: 'text',
            text: `šŸ“Š **Email Overview**\nTotal: ${emails.length} emails\nUnread: ${emails.filter(e => !e.isRead).length} emails\n\nšŸ“‹ **Email List:**\n` + 
                 emails.map((email, index) => 
                   `${index + 1}. ${email.isRead ? 'āœ…' : 'šŸ“©'} **${email.subject}**\n   From: ${email.sender}\n   Time: ${email.receivedTime}\n   Preview: ${email.body?.substring(0, 100)}...\n`
                 ).join('\n')
          },
        ],
      };
    }
  • Specific handler method for fetching inbox emails by calling the generic getEmailsFromFolder with Inbox folder ID (6).
    async getInboxEmails(count: number = 10): Promise<EmailMessage[]> {
      return this.getEmailsFromFolder(6, count, "[ReceivedTime]"); // 6 = Inbox
    }
  • Core helper function that runs PowerShell script via child_process.spawn to interact with Outlook COM API, retrieve emails from specified folder, parse JSON output, and map to EmailMessage[] objects.
    private async getEmailsFromFolder(folderType: number, count: number = 10, sortBy: string = "[ReceivedTime]"): Promise<EmailMessage[]> {
      const script = `
        try {
          Add-Type -AssemblyName "Microsoft.Office.Interop.Outlook" -ErrorAction Stop
          $outlook = New-Object -ComObject Outlook.Application -ErrorAction Stop
          $namespace = $outlook.GetNamespace("MAPI")
          $folder = $namespace.GetDefaultFolder(${folderType})
          
          if ($folder.Items.Count -eq 0) {
            Write-Output "[]"
            exit 0
          }
          
          $items = $folder.Items
          $items.Sort("${sortBy}", $true)
          
          $emails = @()
          $counter = 0
          
          foreach ($item in $items) {
            if ($counter -ge ${count}) { break }
            
            try {
              $subject = if ($item.Subject) { $item.Subject.ToString() -replace '[\\x00-\\x1F\\x7F]', '' } else { "No Subject" }
              $sender = if ($item.SenderEmailAddress) { $item.SenderEmailAddress.ToString() -replace '[\\x00-\\x1F\\x7F]', '' } else { "Unknown" }
              $body = if ($item.Body) { 
                $bodyStr = $item.Body.ToString() -replace '[\\x00-\\x1F\\x7F]', ''
                if ($bodyStr.Length -gt 150) { $bodyStr.Substring(0, 150) + "..." } else { $bodyStr }
              } else { "" }
              
              $timeStamp = if ($item.SentOn -and ${folderType} -eq 5) { 
                $item.SentOn.ToString("yyyy-MM-dd HH:mm:ss") 
              } elseif ($item.ReceivedTime) { 
                $item.ReceivedTime.ToString("yyyy-MM-dd HH:mm:ss") 
              } else { 
                (Get-Date).ToString("yyyy-MM-dd HH:mm:ss") 
              }
              
              $emails += [PSCustomObject]@{
                Id = if ($item.EntryID) { $item.EntryID.ToString() } else { "no-id-$counter" }
                StoreID = if ($item.Session -and $item.Session.DefaultStore -and $item.Session.DefaultStore.StoreID) { 
                  $item.Session.DefaultStore.StoreID.ToString() 
                } elseif ($item.Parent -and $item.Parent.StoreID) { 
                  $item.Parent.StoreID.ToString() 
                } else { 
                  try { $namespace.DefaultStore.StoreID.ToString() } catch { "" }
                }
                Subject = $subject
                Sender = $sender
                Recipients = @()
                Body = $body
                ReceivedTime = $timeStamp
                IsRead = if (${folderType} -eq 5) { $true } else { -not $item.UnRead }
                HasAttachments = $item.Attachments.Count -gt 0
              }
              
              $counter++
            } catch { $counter++; continue }
          }
          
          if ($emails.Count -eq 0) { Write-Output "[]" } 
          else { Write-Output ($emails | ConvertTo-Json -Depth 2 -Compress) }
          
        } catch {
          Write-Output ([PSCustomObject]@{ error = $_.Exception.Message; type = "OutlookConnectionError" } | ConvertTo-Json -Compress)
        }
      `;
    
      try {
        const result = await this.executePowerShell(script);
        if (!result || result.trim() === '') return [];
        
        const cleanResult = result.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/g, '').trim();
        const parsed = JSON.parse(cleanResult);
        
        if (parsed.error) throw new Error(`Outlook Error: ${parsed.error}`);
        
        const emailArray = Array.isArray(parsed) ? parsed : [parsed];
        return emailArray.map((item: any) => ({
          id: this.cleanText(item.Id || ''),
          storeId: this.cleanText(item.StoreID || ''),
          subject: this.cleanText(item.Subject || 'No Subject'),
          sender: this.cleanText(item.Sender || 'Unknown'),
          recipients: [],
          body: this.cleanText(item.Body || ''),
          receivedTime: new Date(item.ReceivedTime),
          isRead: Boolean(item.IsRead),
          hasAttachments: Boolean(item.HasAttachments)
        }));
        
      } catch (error) {
        console.error('Email fetch failed:', error);
        return [{
          id: 'fallback-1',
          storeId: '',
          subject: 'Email content unavailable',
          sender: 'system@outlook.com',
          recipients: [],
          body: 'Unable to retrieve email content.',
          receivedTime: new Date(),
          isRead: true,
          hasAttachments: false
        }];
      }
    }
  • TypeScript interface defining the structure of EmailMessage objects returned by get_inbox_emails.
    export interface EmailMessage {
      id: string;
      storeId?: string;
      subject: string;
      sender: string;
      recipients: string[];
      body: string;
      receivedTime: Date;
      isRead: boolean;
      hasAttachments: boolean;
    }
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 only states the action without disclosing behavioral traits like permissions needed, rate limits, sorting order (e.g., by date), pagination, or what 'inbox' means (e.g., unread vs. all). For a read operation with no annotations, this is insufficient.

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

Conciseness4/5

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

The description is a single, efficient sentence with no wasted words. It's front-loaded and appropriately sized for a simple tool, though it could be more informative without sacrificing brevity.

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 the tool's complexity (a read operation with one parameter) and lack of annotations or output schema, the description is incomplete. It doesn't explain return values, error conditions, or how it differs from similar tools, making it inadequate for full contextual understanding.

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

Parameters3/5

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

Schema description coverage is 100%, with the single parameter 'count' documented as 'Number of emails to retrieve' with a default of 10. The description adds no additional meaning beyond the schema, so it meets the baseline of 3 for high coverage.

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

Purpose3/5

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

The description 'Get inbox email list' states a basic purpose (verb 'get' + resource 'inbox email list'), but it's vague about scope and doesn't distinguish from sibling tools like 'get_draft_emails', 'get_sent_emails', or 'search_inbox_emails'. It lacks specificity about what constitutes 'inbox' or what 'list' includes.

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 is provided on when to use this tool versus alternatives. With siblings like 'search_inbox_emails' and 'get_email_by_id', the description doesn't indicate if this is for bulk retrieval, recent emails, or default behavior, leaving usage ambiguous.

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

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/cqyefeng119/windows-outlook-mcp'

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