Skip to main content
Glama
billyfranklim1

mcp-evolution

Download Media

download_media

Download media from a WhatsApp message and write it to disk. Returns file path, mimetype, size, and message ID without raw base64 to prevent context overflow.

Instructions

Download media from a WhatsApp message and write it to disk. Returns { path, mimetype, size, messageId } — NOT raw base64 (prevents context overflow). File is written to /tmp/mcp-evolution-media/-.. Caller is responsible for cleanup (rm the file when done).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
messageYesMessage object containing the media
convertToMp4NoConvert audio to mp4 format (forwarded to Evolution)

Implementation Reference

  • The main handler function 'registerDownloadMedia' that registers the 'download_media' tool. It sends a POST request to Evolution API's /chat/getBase64FromMediaMessage endpoint, decodes the returned base64 media data, and writes it to disk at /tmp/mcp-evolution-media/. Returns { path, mimetype, size, messageId }.
    export function registerDownloadMedia(server: McpServer, client: EvolutionClient): void {
      server.registerTool(
        "download_media",
        {
          title: "Download Media",
          description:
            "Download media from a WhatsApp message and write it to disk. " +
            "Returns { path, mimetype, size, messageId } — NOT raw base64 (prevents context overflow). " +
            "File is written to /tmp/mcp-evolution-media/<instance>-<messageId>.<ext>. " +
            "Caller is responsible for cleanup (rm the file when done).",
          inputSchema: schema,
        },
        async (args) => {
          try {
            const payload: Record<string, unknown> = { message: args.message };
            if (args.convertToMp4 !== undefined) payload["convertToMp4"] = args.convertToMp4;
    
            const data = await client.post(
              `/chat/getBase64FromMediaMessage/${client.instanceName}`,
              payload
            ) as EvolutionMediaResponse;
    
            const base64 = data.base64;
            if (!base64) {
              return {
                isError: true,
                content: [{ type: "text" as const, text: "Evolution returned no base64 data for this message." }],
              };
            }
    
            const mimetype = data.mimetype ?? data.mediaType ?? "application/octet-stream";
            const ext = mimeToExt(mimetype);
            const messageId = args.message.key.id;
            const filename = `${client.instanceName}-${messageId}.${ext}`;
            const filePath = path.join(MEDIA_DIR, filename);
    
            // Ensure media dir exists (mode 0700 — only root/owner readable)
            await fs.mkdir(MEDIA_DIR, { recursive: true, mode: 0o700 });
    
            const buf = Buffer.from(base64, "base64");
            await fs.writeFile(filePath, buf, { mode: 0o600 });
    
            const result = { path: filePath, mimetype, size: buf.length, messageId };
            return {
              content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }],
            };
          } catch (e) {
            if (e instanceof McpError) return { isError: true, content: [{ type: "text" as const, text: e.message }] };
            throw e;
          }
        }
      );
    }
  • Input schema for download_media: requires a 'message' object (with key.remoteJid, key.fromMe, key.id) and optional 'convertToMp4' boolean.
    const schema = {
      message: z.object({
        key: z.object({
          remoteJid: z.string().min(1).describe("Chat JID"),
          fromMe: z.boolean().describe("Whether sent by this instance"),
          id: z.string().min(1).describe("Message ID"),
        }),
      }).describe("Message object containing the media"),
      convertToMp4: z.boolean().optional().describe("Convert audio to mp4 format (forwarded to Evolution)"),
    };
  • Import of registerDownloadMedia from the download-media module.
    import { registerDownloadMedia } from "./download-media.js";
  • Call to registerDownloadMedia(server, client) in the registerAllTools function which registers the tool with the MCP server.
    registerDownloadMedia(server, client);
  • The mimeToExt helper function used by download_media to map a MIME type (e.g. 'image/jpeg') to a file extension ('jpg'), with fallback logic.
    export function mimeToExt(mime: string): string {
      const map: Record<string, string> = {
        "image/jpeg": "jpg",
        "image/png": "png",
        "image/gif": "gif",
        "image/webp": "webp",
        "video/mp4": "mp4",
        "video/webm": "webm",
        "audio/ogg": "ogg",
        "audio/mpeg": "mp3",
        "audio/mp4": "m4a",
        "audio/wav": "wav",
        "application/pdf": "pdf",
        "application/zip": "zip",
      };
      const sub = mime.split("/")[1]?.replace(/[^a-z0-9]/gi, "");
      return map[mime] ?? (sub !== undefined && sub.length > 0 ? sub : "bin");
    }
Behavior4/5

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

No annotations provided, so description carries full burden. It discloses that file is written to disk, returns metadata not raw base64 to prevent overflow, and caller is responsible for cleanup. This is transparent about side effects and return format.

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?

Description is three sentences, front-loaded with verb and resource, no superfluous words. Every sentence adds value (what it does, return format, file path, cleanup).

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?

No output schema, but description covers return format. File path pattern and cleanup are specified. Could mention error conditions, but for a download tool it is sufficiently complete for an agent.

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

Parameters4/5

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

Schema coverage is 100% with descriptions for both parameters. Description adds meaning beyond schema by explaining return structure, file path pattern, and cleanup responsibility, which helps agent use parameters correctly.

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?

Description clearly states action: download media from WhatsApp message and write to disk. It specifies return format and file path. No sibling tool has similar name, so no confusion.

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?

Description does not explicitly state when to use vs alternatives, but usage for downloading media is clear. It provides cleanup instructions which guide post-use behavior.

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/billyfranklim1/mcp-evolution'

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