Skip to main content
Glama

access-shared-mailbox

Read-only

Read emails from a shared Outlook mailbox you have access to. Specify folder, count, and detail level to retrieve messages.

Instructions

Read emails from a shared mailbox you have access to

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sharedMailboxYesEmail address of the shared mailbox (required)
folderNoFolder to read from (default: inbox)
countNoNumber of emails to retrieve (default: 25, max: 50)
outputVerbosityNoOutput detail level (default: standard)

Implementation Reference

  • Main handler function for the 'access-shared-mailbox' tool. Validates input, authenticates, calls Microsoft Graph API to fetch emails from a shared mailbox, and formats the response. Handles errors for authentication, access denied (403), and not found (404) scenarios.
    async function handleAccessSharedMailbox(args) {
      const { sharedMailbox, folder, count, outputVerbosity } = args;
    
      if (!sharedMailbox) {
        return {
          content: [
            {
              type: 'text',
              text: "Shared mailbox email address is required (e.g., 'shared@company.com').",
            },
          ],
        };
      }
    
      const mailFolder = folder || 'inbox';
      const pageSize = Math.min(count || 25, 50);
      const verbosity = outputVerbosity || 'standard';
    
      try {
        const accessToken = await ensureAuthenticated();
    
        // Build endpoint for shared mailbox
        const endpoint = `users/${sharedMailbox}/mailFolders/${mailFolder}/messages`;
        const fieldSet = verbosity === 'full' ? 'read' : 'list';
        const queryParams = {
          $top: pageSize.toString(),
          $orderby: 'receivedDateTime desc',
          $select: FIELD_PRESETS[fieldSet].join(','),
        };
    
        const response = await callGraphAPI(
          accessToken,
          'GET',
          endpoint,
          null,
          queryParams
        );
    
        const messages = response.value || [];
    
        if (messages.length === 0) {
          return {
            content: [
              {
                type: 'text',
                text: `No emails found in ${sharedMailbox}/${mailFolder}.\n\nNote: Make sure you have access to this shared mailbox and the Mail.Read.Shared permission is granted.`,
              },
            ],
          };
        }
    
        let output = [];
        output.push(`# Shared Mailbox: ${sharedMailbox}`);
        output.push(`**Folder**: ${mailFolder} | **Count**: ${messages.length}\n`);
    
        if (verbosity === 'minimal') {
          messages.forEach((msg, i) => {
            output.push(`${i + 1}. ${msg.subject}`);
            output.push(`   From: ${msg.from?.emailAddress?.address || 'Unknown'}`);
          });
        } else {
          output.push('| # | Subject | From | Date | Read |');
          output.push('|---|---------|------|------|------|');
          messages.forEach((msg, i) => {
            const date = new Date(msg.receivedDateTime).toLocaleDateString();
            const from =
              msg.from?.emailAddress?.name ||
              msg.from?.emailAddress?.address ||
              'Unknown';
            const read = msg.isRead ? 'Y' : 'N';
            output.push(
              `| ${i + 1} | ${msg.subject?.substring(0, 40)}${msg.subject?.length > 40 ? '...' : ''} | ${from.substring(0, 20)} | ${date} | ${read} |`
            );
          });
        }
    
        if (verbosity === 'full') {
          output.push('\n## Message IDs');
          messages.forEach((msg, i) => {
            output.push(`${i + 1}. \`${msg.id}\``);
          });
        }
    
        return {
          content: [
            {
              type: 'text',
              text: output.join('\n'),
            },
          ],
          _meta: {
            sharedMailbox,
            folder: mailFolder,
            count: messages.length,
            messages: messages.map((m) => formatEmail(m, verbosity)),
          },
        };
      } catch (error) {
        if (error.message === 'Authentication required') {
          return {
            content: [
              {
                type: 'text',
                text: "Authentication required. Please use the 'auth' tool with action=authenticate first.",
              },
            ],
          };
        }
    
        if (
          error.message.includes('Access is denied') ||
          error.message.includes('403')
        ) {
          return {
            content: [
              {
                type: 'text',
                text: `Access denied to shared mailbox "${sharedMailbox}".\n\n**Possible causes:**\n- You don't have access to this shared mailbox\n- The Mail.Read.Shared permission is not granted\n- The shared mailbox address is incorrect`,
              },
            ],
          };
        }
    
        if (error.message.includes('not found') || error.message.includes('404')) {
          return {
            content: [
              {
                type: 'text',
                text: `Shared mailbox "${sharedMailbox}" not found. Please verify the email address.`,
              },
            ],
          };
        }
    
        return {
          content: [
            {
              type: 'text',
              text: `Error accessing shared mailbox: ${error.message}`,
            },
          ],
        };
      }
    }
  • Tool registration defining the 'access-shared-mailbox' tool with name, description, annotations (readOnlyHint, openWorldHint), inputSchema with parameters (sharedMailbox, folder, count, outputVerbosity), and handler reference.
    const advancedTools = [
      {
        name: 'access-shared-mailbox',
        description: 'Read emails from a shared mailbox you have access to',
        annotations: {
          title: 'Shared Mailbox',
          readOnlyHint: true,
          openWorldHint: false,
        },
        inputSchema: {
          type: 'object',
          properties: {
            sharedMailbox: {
              type: 'string',
              description: 'Email address of the shared mailbox (required)',
            },
            folder: {
              type: 'string',
              description: 'Folder to read from (default: inbox)',
            },
            count: {
              type: 'number',
              description: 'Number of emails to retrieve (default: 25, max: 50)',
            },
            outputVerbosity: {
              type: 'string',
              enum: ['minimal', 'standard', 'full'],
              description: 'Output detail level (default: standard)',
            },
          },
          required: ['sharedMailbox'],
        },
        handler: handleAccessSharedMailbox,
      },
  • Helper function 'formatEmail' that formats email objects for output based on verbosity level (minimal or standard). Used within the handler to structure email data in the response.
    function formatEmail(email, verbosity = 'standard') {
      if (verbosity === 'minimal') {
        return {
          id: email.id,
          subject: email.subject,
          from: email.from?.emailAddress?.address,
        };
      }
    
      return {
        id: email.id,
        subject: email.subject,
        from: email.from?.emailAddress
          ? {
              name: email.from.emailAddress.name,
              address: email.from.emailAddress.address,
            }
          : null,
        receivedDateTime: email.receivedDateTime,
        isRead: email.isRead,
        hasAttachments: email.hasAttachments,
        flag: email.flag,
      };
    }
Behavior3/5

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

Annotations already declare readOnlyHint=true and openWorldHint=false, so the agent knows this is a safe read operation with limited scope. The description adds the specific context of reading from a shared mailbox (not a personal one) and the access requirement, which provides useful behavioral context beyond the annotations.

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 communicates the core purpose without any wasted words. It's appropriately sized and front-loaded with the essential information.

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

Completeness3/5

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

For a read operation with good annotations (readOnlyHint, openWorldHint) and comprehensive parameter documentation, the description provides adequate context about the shared mailbox focus. However, without an output schema, it doesn't describe what format or structure the returned emails will have, leaving a gap in completeness.

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?

With 100% schema description coverage, the input schema already documents all 4 parameters thoroughly with descriptions, defaults, and constraints. The description doesn't add any meaningful parameter semantics beyond what's already in the structured schema, so it meets the baseline expectation.

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 verb ('Read emails') and resource ('from a shared mailbox you have access to'), making the purpose immediately understandable. However, it doesn't explicitly distinguish this tool from sibling tools like 'read-email' or 'search-emails', which appear to be related email reading operations.

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?

The description provides no guidance on when to use this tool versus alternatives like 'read-email' or 'search-emails'. It mentions the requirement of having access to the shared mailbox, but offers no explicit when/when-not criteria or comparison with sibling tools.

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

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