Skip to main content
Glama

attachments

Read-onlyIdempotent

Manage email attachments by listing all files for an email or downloading specific attachments as base64-encoded content.

Instructions

Email attachments: list, download. List shows all attachments for an email. Download returns base64-encoded content.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesAction to perform
accountYesAccount email (required)
uidYesEmail UID (required)
folderNoMailbox folder (default: INBOX)
filenameNoAttachment filename (required for download)

Implementation Reference

  • Main handler function for the 'attachments' tool. Validates input, dispatches to handleList or handleDownload based on action, and wraps execution with error handling.
    export async function attachments(accounts: AccountConfig[], input: AttachmentsInput): Promise<any> {
      return withErrorHandling(async () => {
        if (!input.account) {
          throw new EmailMCPError(
            'account is required for attachment operations',
            'VALIDATION_ERROR',
            'Provide the account email address'
          )
        }
    
        if (!input.uid) {
          throw new EmailMCPError(
            'uid is required for attachment operations',
            'VALIDATION_ERROR',
            'Provide the email UID from search/read'
          )
        }
    
        switch (input.action) {
          case 'list':
            return await handleList(accounts, input)
    
          case 'download':
            return await handleDownload(accounts, input)
    
          default:
            throw createUnknownActionError(input.action, 'list, download')
        }
      })()
    }
  • TypeScript interface defining the input schema for the attachments tool, including action type ('list' or 'download'), required fields (account, uid), and optional fields (folder, filename).
    export interface AttachmentsInput {
      action: 'list' | 'download'
    
      // Required
      account: string
      uid: number
    
      // Optional
      folder?: string
      filename?: string
    }
  • handleList function - lists all attachments for a specific email by reading the email and returning attachment metadata (filename, content_type, size, content_id).
    async function handleList(accounts: AccountConfig[], input: AttachmentsInput): Promise<any> {
      const account = resolveSingleAccount(accounts, input.account)
      const folder = input.folder || 'INBOX'
    
      const email = await readEmail(account, input.uid, folder)
    
      return {
        action: 'list',
        account: account.email,
        uid: input.uid,
        folder,
        subject: email.subject,
        total: email.attachments.length,
        attachments: email.attachments
      }
    }
  • handleDownload function - downloads a specific attachment by filename, returning base64-encoded content along with metadata.
    async function handleDownload(accounts: AccountConfig[], input: AttachmentsInput): Promise<any> {
      if (!input.filename) {
        throw new EmailMCPError(
          'filename is required for download action',
          'VALIDATION_ERROR',
          'Use attachments list action first to see available filenames'
        )
      }
    
      const account = resolveSingleAccount(accounts, input.account)
      const folder = input.folder || 'INBOX'
    
      const attachment = await getAttachment(account, input.uid, folder, input.filename)
    
      return {
        action: 'download',
        account: account.email,
        uid: input.uid,
        folder,
        ...attachment
      }
    }
  • Tool registration for 'attachments' in the registry, defining the tool name, description, annotations, and JSON Schema input schema including action enum, required fields, and optional parameters.
    {
      name: 'attachments',
      description:
        'Email attachments: list, download. List shows all attachments for an email. Download returns base64-encoded content.',
      annotations: {
        title: 'Attachments',
        readOnlyHint: true,
        destructiveHint: false,
        idempotentHint: true,
        openWorldHint: false
      },
      inputSchema: {
        type: 'object',
        properties: {
          action: {
            type: 'string',
            enum: ['list', 'download'],
            description: 'Action to perform'
          },
          account: { type: 'string', description: 'Account email (required)' },
          uid: { type: 'number', description: 'Email UID (required)' },
          folder: { type: 'string', description: 'Mailbox folder (default: INBOX)' },
          filename: { type: 'string', description: 'Attachment filename (required for download)' }
        },
        required: ['action', 'account', 'uid']
      }
    },
Behavior4/5

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

Annotations already indicate read-only, non-destructive, and idempotent behavior, which the description does not contradict. The description adds valuable context beyond annotations by specifying that download returns 'base64-encoded content,' which is a key behavioral trait not covered by annotations. However, it does not mention rate limits or auth needs, which could be relevant.

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 highly concise and front-loaded, consisting of two efficient sentences that directly state the tool's actions and outcomes without any wasted words. Each sentence earns its place by clarifying the tool's functionality.

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

Completeness4/5

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

Given the tool's moderate complexity (5 parameters, no output schema) and rich annotations, the description is mostly complete. It covers the core actions and output format for download, but could benefit from mentioning error cases or response structures for list actions. However, annotations provide safety context, making it adequate overall.

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%, so the schema already documents all parameters thoroughly. The description adds minimal semantic value beyond the schema by mentioning 'list shows all attachments for an email' and 'download returns base64-encoded content,' which loosely relates to parameters like 'action' and 'filename,' but does not provide additional details on parameter usage or constraints.

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

Purpose5/5

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

The description clearly states the tool's purpose with specific verbs ('list, download') and resource ('email attachments'), and distinguishes it from sibling tools like 'messages' or 'send' by focusing exclusively on attachment operations. It explicitly mentions what each action does: 'List shows all attachments for an email' and 'Download returns base64-encoded content.'

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

Usage Guidelines3/5

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

The description implies usage by specifying actions ('list' and 'download') and their outcomes, but does not explicitly state when to use this tool versus alternatives like 'messages' for general email handling. It provides some context (e.g., 'list shows all attachments for an email'), but lacks explicit guidance on prerequisites or exclusions.

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/n24q02m/better-email-mcp'

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