From 4928db6b56e5c0b444ed3e26fe581e29a9f25e6c Mon Sep 17 00:00:00 2001 From: "M. L. Giannotta" Date: Sun, 10 May 2026 16:01:34 +0800 Subject: [PATCH] fix(mcp-server): set Authorization header on DownloadMedia DownloadMedia builds its HTTP request directly instead of going through callAPI, and was missing the Bearer token that the bridge's JWT middleware requires. As a result, every download_media MCP tool call returned 401. Fetch a JWT via GetOrRefreshJwtToken (same path the rest of the helpers use) and set the Authorization header on the request. --- whatsapp-mcp-server/helpers/whatsapp.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/whatsapp-mcp-server/helpers/whatsapp.go b/whatsapp-mcp-server/helpers/whatsapp.go index b7bdf4f..9065088 100644 --- a/whatsapp-mcp-server/helpers/whatsapp.go +++ b/whatsapp-mcp-server/helpers/whatsapp.go @@ -210,6 +210,11 @@ func SendAudioVoiceMessage(recipient, mediaPath string) (bool, string) { } func DownloadMedia(messageID, chatJID string) (string, error) { + token, err := GetOrRefreshJwtToken() + if err != nil { + return "", fmt.Errorf("authentication failed: %w", err) + } + payload := map[string]string{ "message_id": messageID, "chat_jid": chatJID, @@ -218,6 +223,7 @@ func DownloadMedia(messageID, chatJID string) (string, error) { body, _ := json.Marshal(payload) req, _ := http.NewRequest("POST", apiBaseURL+"/download", bytes.NewBuffer(body)) req.Header.Set("Content-Type", "application/json") + req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token)) client := &http.Client{} resp, err := client.Do(req)