Send Media
send_mediaSend image, video, audio, or document messages to WhatsApp contacts or groups using a URL or base64-encoded media.
Instructions
Send a media message (image, video, audio, document) via the pinned instance.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| number | Yes | Recipient JID or phone number (e.g. 5511999999999 or group@g.us) | |
| mediatype | Yes | Media type: image, video, audio, or document | |
| media | Yes | URL or base64 of the media | |
| fileName | No | Optional filename (required for document type) | |
| caption | No | Optional caption for the media |
Implementation Reference
- src/tools/send-media.ts:29-50 (handler)The async handler function that executes the send_media tool logic. It constructs a payload with number, mediatype, media, optional fileName and caption, then POSTs to /message/sendMedia/{instanceName} and returns the response.
async (args) => { try { const payload: Record<string, unknown> = { number: args.number, mediatype: args.mediatype, media: args.media, }; if (args.fileName) payload["fileName"] = args.fileName; if (args.caption) payload["caption"] = args.caption; const data = await client.post(`/message/sendMedia/${client.instanceName}`, payload); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }], }; } catch (e) { if (e instanceof McpError) { return { isError: true, content: [{ type: "text" as const, text: e.message }] }; } throw e; } } ); - src/tools/send-media.ts:7-18 (schema)Input schema defining the tool's input parameters: number (JID or phone), mediatype (enum: image/video/audio/document), media (URL or base64 string), fileName (optional, required for document), and caption (optional).
const schema = { number: PhoneOrJidSchema, mediatype: z .enum(["image", "video", "audio", "document"]) .describe("Media type: image, video, audio, or document"), media: z.string().min(1).describe("URL or base64 of the media"), fileName: z .string() .optional() .describe("Optional filename (required for document type)"), caption: z.string().optional().describe("Optional caption for the media"), }; - src/tools/index.ts:84-84 (registration)Registration call invoking registerSendMedia(server, client) within the registerAllTools function.
registerSendMedia(server, client); - src/tools/send-media.ts:20-22 (registration)The registerSendMedia function which registers the tool with the MCP server under the name 'send_media'.
export function registerSendMedia(server: McpServer, client: EvolutionClient): void { server.registerTool( "send_media", - src/evolution-client.ts:24-60 (helper)The EvolutionClient.post method used by the handler to send the POST request to the Evolution API.
async post<T = unknown>(path: string, body: unknown): Promise<T> { return this.request<T>("POST", path, body); } async delete<T = unknown>(path: string, body?: unknown): Promise<T> { return this.request<T>("DELETE", path, body); } private async request<T>(method: string, path: string, body?: unknown): Promise<T> { const url = `${this.baseUrl}${path}`; const headers: Record<string, string> = { apikey: this.apiKey, "Content-Type": "application/json", }; const res = await fetch(url, { method, headers, body: body !== undefined ? JSON.stringify(body) : undefined, }); const text = await res.text(); if (!res.ok) { throw new McpError( ErrorCode.InternalError, `Evolution API error ${res.status}: ${text}` ); } try { return JSON.parse(text) as T; } catch { return text as unknown as T; } } }