Skip to main content
Glama

getAttachment

Retrieve specific email attachments by ID from an AgentMail inbox using inbox, message, and attachment IDs for efficient AI agent workflows.

Instructions

Get attachment by ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
attachment_idYes
inbox_idYes
message_idYes

Implementation Reference

  • Node.js handler function for getAttachment tool: fetches attachment by thread_id and attachment_id, detects MIME type, extracts text from PDF or DOCX using pdf-parse and mammoth, returns text or error.
    export async function getAttachment(client: AgentMailClient, args: Args): Promise<Attachment> {
        const { thread_id, attachment_id } = args
    
        const response = await client.threads.getAttachment(thread_id, attachment_id)
        const fileBytes = Buffer.from(await response.arrayBuffer())
    
        const fileKind = await fileTypeFromBuffer(fileBytes)
        const fileType = fileKind?.mime
    
        let text = undefined
    
        if (fileType === 'application/pdf') {
            const parser = new PDFParse({ data: fileBytes, CanvasFactory })
            const pdfData = await parser.getText()
            text = pdfData.text
        } else if (fileType === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') {
            const result = await mammoth.extractRawText({ buffer: fileBytes })
            text = result.value
        } else {
            return {
                error: `Unsupported file type: ${fileType || 'unknown'}`,
                file_type: fileType,
            }
        }
    
        return { text, file_type: fileType }
    }
  • Python handler function for get_attachment tool: fetches attachment, detects type with filetype, extracts text from PDF using pymupdf or DOCX using docx, returns Attachment model with text or error.
    def get_attachment(client: AgentMail, kwargs: Kwargs):
        it = client.threads.get_attachment(
            thread_id=kwargs["thread_id"], attachment_id=kwargs["attachment_id"]
        )
        file_bytes = b"".join(it)
    
        file_kind = filetype.guess(file_bytes)
        file_type = file_kind.mime if file_kind else None
    
        text = ""
        if file_type == "application/pdf":
            for page in pymupdf.Document(stream=file_bytes):
                text += page.get_text() + "\n"
        elif (
            file_type
            == "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
        ):
            for paragraph in docx.Document(io.BytesIO(file_bytes)).paragraphs:
                text += paragraph.text + "\n"
        else:
            return Attachment(
                error=f"Unsupported file type: {file_type or 'unknown'}",
                file_type=file_type,
            )
    
        return Attachment(text=text, file_type=file_type)
  • Node.js tool registration for 'get_attachment' using GetAttachmentParams schema and getAttachment handler.
        name: 'get_attachment',
        description: 'Get attachment',
        params_schema: GetAttachmentParams,
        func: getAttachment,
    },
  • Python tool registration for 'get_attachment' using GetAttachmentParams schema and get_attachment handler.
    Tool(
        name="get_attachment",
        description="Get attachment",
        params_schema=GetAttachmentParams,
        func=get_attachment,
    ),
  • Node.js Zod schema for getAttachment parameters: inbox_id, thread_id, attachment_id.
    export const GetAttachmentParams = z.object({
        inbox_id: InboxIdSchema,
        thread_id: ThreadIdSchema,
        attachment_id: AttachmentIdSchema,
    })
Behavior1/5

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

No annotations are provided, so the description carries full burden but offers minimal behavioral information. It doesn't disclose whether this is a read-only operation, what format the attachment is returned in, error conditions, authentication needs, or rate limits. The description is too basic to inform the agent about how the tool behaves.

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 extremely concise with just four words, front-loaded and zero waste. It efficiently states the core purpose without unnecessary elaboration, though this brevity contributes to gaps in other dimensions.

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

Completeness1/5

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

Given the complexity (3 required parameters, no annotations, no output schema), the description is completely inadequate. It doesn't explain what an attachment is in this system, how to use the IDs, what the tool returns, or any error handling. For a tool with multiple required identifiers and no structured documentation, this leaves the agent with insufficient context.

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

Parameters1/5

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

Schema description coverage is 0%, meaning none of the three required parameters (attachment_id, inbox_id, message_id) are documented in the schema. The description adds no meaning beyond the tool name, failing to explain what these IDs are, how to obtain them, or their relationships. This leaves parameters completely undocumented.

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 attachment by ID' clearly states the action (get) and resource (attachment), but it's vague about scope and doesn't differentiate from potential siblings. It doesn't specify whether this retrieves metadata, content, or both, nor does it mention what an 'attachment' represents in this context.

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 sibling tools like getMessage and getThread, it's unclear if attachments are accessible through those tools or if this is the exclusive method. No prerequisites or context about required IDs are mentioned.

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/agentmail-to/agentmail-toolkit'

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