upload_media
Upload media files to an OpenWA session for later use in messages. Supports image, video, audio, and document types.
Instructions
Upload media to OpenWA for later use in messages
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | Session ID | |
| file | Yes | Public URL of the media file to upload | |
| type | Yes | Media type: image, video, audio, or document |
Implementation Reference
- src/tools/media.ts:31-39 (handler)The async handler function for the upload_media tool. It calls openwaClient with POST method to /sessions/{sessionId}/media, sending the file URL and media type in the request body.
async ({ sessionId, file, type }) => { const data = await openwaClient({ method: "POST", path: `/sessions/${sessionId}/media`, body: { file, type }, }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/tools/media.ts:25-29 (schema)Input schema for upload_media: sessionId (string), file (string - public URL of media), type (string - image/video/audio/document).
inputSchema: { sessionId: z.string().describe("Session ID"), file: z.string().describe("Public URL of the media file to upload"), type: z.string().describe("Media type: image, video, audio, or document"), }, - src/tools/media.ts:21-39 (registration)Registration of the upload_media tool on the McpServer via server.registerTool(), with its schema and handler.
server.registerTool( "upload_media", { description: "Upload media to OpenWA for later use in messages", inputSchema: { sessionId: z.string().describe("Session ID"), file: z.string().describe("Public URL of the media file to upload"), type: z.string().describe("Media type: image, video, audio, or document"), }, }, async ({ sessionId, file, type }) => { const data = await openwaClient({ method: "POST", path: `/sessions/${sessionId}/media`, body: { file, type }, }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/index.ts:22-22 (registration)The registerMediaTools(server) call that activates the upload_media registration.
registerMediaTools(server); - src/client.ts:10-35 (helper)The openwaClient helper function used by the upload_media handler to make the HTTP POST request to the OpenWA API.
export async function openwaClient<T = unknown>(opts: RequestOptions): Promise<T> { const url = `${BASE_URL}${opts.path}`; const headers: Record<string, string> = { "Content-Type": "application/json", "X-API-Key": API_KEY, }; const res = await fetch(url, { method: opts.method, headers, body: opts.body ? JSON.stringify(opts.body) : undefined, }); const text = await res.text(); if (!res.ok) { throw new Error(`OpenWA API ${res.status}: ${text}`); } try { return JSON.parse(text) as T; } catch { return text as T; } }