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.
This commit is contained in:
M. L. Giannotta
2026-05-10 16:01:34 +08:00
parent c9523748f9
commit 4928db6b56
+6
View File
@@ -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)