Skip to main content
Glama

get_attachment

Open email attachments by specifying the email path and attachment pattern; downloads to temp directory and opens with default application.

Instructions

Open attachments in email by providing the email path.

The tool downloads the attachment into a temp dir and open it.

The command includes the paths and the pattern of attachment files.

The prefix mu extract --target-dir /tmp --overwrite --play SHOULD NOT appear in command.

See the man page for mu extract.

MU EXTRACT(1) General Commands Manual MU EXTRACT(1)

NAME mu-extract - display and save message parts (attachments), and open them with other tools.

SYNOPSIS mu [COMMON-OPTIONS] extract [OPTIONS] [FILE]

   mu [COMMON-OPTIONS] extract [OPTIONS] FILE PATTERN

DESCRIPTION mu extract is the mu sub-command for extracting MIME-parts (e.g., attachments) from mail messages. The sub-command works on message files, and does not require the message to be indexed in the database.

   For attachments, the file name used when saving it is the name of the
   attachment in the message. If there is no such name, or when saving
   non-attachment MIME-parts, a name is derived from the message-id of the
   message.


   If you specify a regular express pattern as the second argument, all
   attachments with filenames matching that pattern will be extracted. The
   regular expressions are basic PCRE, and are case-sensitive by default;
   see pcre(3) for more details.


   Without any options, mu extract simply outputs the list of leaf MIME-
   parts in the message. Only `leaf' MIME-parts (including RFC822
   attachments) are considered, multipart/* etc. are ignored.


   Without a filename parameter, mu extract reads a message from standard-
   input. In that case, you cannot use the second, PATTERN parameter as
   this would be ambiguous; instead, use the --matches option.

EXTRACT OPTIONS -a, --save-attachments Save all MIME-parts that look like attachments.

--save-all Save all non-multipart MIME-parts.

--parts parts Only consider the following numbered parts (comma-separated list). The numbers for the parts can be seen from running mu extract without any options but only the message file.

--target-dir dir Save the parts in dir rather than the current working directory.

--overwrite Overwrite existing files with the same name; by default overwriting is not allowed.

-u,--uncooked By default, mu transforms the attachment filenames a bit (such as by replacing spaces by dashes); with this option, leave that to the minimum for creating a legal filename in the target directory.

--matches pattern Attachments with filenames matching pattern will be extracted. The regular expressions are basic PCRE, and are case-sensitive by default; see pcre(3) for more details.

--play Try to `play' (open) the attachment with the default application for the particular file type. On MacOS, this uses the open program, on other platforms it uses xdg-open. You can choose a different program by setting the MU_PLAY_PROGRAM environment variable.

COMMON OPTIONS -d, --debug Makes mu generate extra debug information, useful for debugging the program itself. Debug information goes to the standard logging location; see mu(1).

-q, --quiet Causes mu not to output informational messages and progress information to standard output, but only to the log file. Error messages will still be sent to standard error. Note that mu index is much faster with --quiet, so it is recommended you use this option when using mu from scripts etc.

--log-stderr Causes mu to not output log messages to standard error, in addition to sending them to the standard logging location.

--nocolor Do not use ANSI colors. The environment variable NO_COLOR can be used as an alternative to --nocolor.

-V, --version Prints mu version and copyright information.

-h, --help Lists the various command line options.

EXAMPLES To display information about all the MIME-parts in a message file: $ mu extract msgfile

   To extract MIME-part 3 and 4 from this message, overwriting existing
   files with the same name:
      $ mu extract --parts=3,4 --overwrite msgfile



   To extract all files ending in `.jpg' (case-insensitive):
      $ mu extract msgfile '.*\.jpg'



   To extract an mp3-file, and play it in the default mp3-playing
   application:
      $ mu extract --play msgfile 'whoopsididitagain.mp3'



   when reading from standard-input, you need --matches, so:
      $ cat msgfile | mu extract --play --matches 'whoopsididitagain.mp3'

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commandYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The actual handler function for the 'get_attachment' tool. It runs 'mu extract --target-dir /tmp --overwrite --play' with the provided command string to open/download email attachments.
    def get_attachment(command: str) -> str:
        r"""Open attachments in email by providing the email path.
    
        The tool downloads the attachment into a temp dir and open it.
    
        The `command` includes the paths and the pattern of attachment files.
    
        The prefix `mu extract --target-dir /tmp --overwrite --play` SHOULD NOT appear in `command`.
    
        See the man page for `mu extract`.
        """
        import subprocess
    
        try:
            result = subprocess.run(
                ["mu", "extract", "--target-dir", "/tmp", "--overwrite", "--play"] + command.split(),
                capture_output=True,
                text=True,
                check=True,
            )
            return result.stdout.strip()
        except subprocess.CalledProcessError as e:
            return f"Error: {e.stderr.strip()}"
  • mu_mcp/mu_mcp.py:96-99 (registration)
    Registration of 'get_attachment' as an MCP tool. Appends the mu extract man page to the docstring, then registers via mcp.tool('get_attachment')(get_attachment).
    if get_attachment.__doc__:
        get_attachment.__doc__ += "\n\n" + mu_extract_man
    
    mcp.tool("get_attachment")(get_attachment)
  • Loads the mu-extract man page text into mu_extract_man variable, which is later appended to get_attachment's docstring.
    mu_extract_man = open("mu_mcp/mu-extract.txt", "r").read().strip()
Behavior3/5

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

The description discloses that the tool downloads the attachment to a temp dir and opens it, and warns about the command prefix. However, it lacks details on side effects, idempotency, or permissions, and the manpage dump is noisy.

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

Conciseness2/5

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

The description is unnecessarily long, including a full man page. The key information is front-loaded but diluted by excessive detail, making it less efficient for an AI agent.

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?

The description does not explain the return value, error handling, or prerequisites despite having an output schema. It leaves gaps for an AI agent to infer.

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?

The schema has 0% coverage, and the description adds meaning by stating that command includes paths and pattern, and warns about forbidden prefix. But it is not fully explicit about the expected format.

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 first sentence clearly states the tool opens attachments in email by providing the email path. It distinguishes from sibling tools like health_check, query, and view.

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 for opening attachments but does not explicitly state when to use it versus alternatives or provide when-not-to-use guidance.

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/danielfleischer/mu-mcp'

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