Implement stream-based download_file tool for downloading media files directly to flash or SD card

This commit is contained in:
Adolfo Reyna
2026-06-01 15:59:50 -04:00
parent 3cd3428e94
commit 092e241f89
2 changed files with 93 additions and 0 deletions
+25
View File
@@ -263,6 +263,19 @@ class MCPServer:
},
"required": ["wav_base64"]
}
},
{
"name": "download_file",
"description": "Download a file from a URL over Wi-Fi directly to the board storage or microSD card.",
"inputSchema": {
"type": "object",
"properties": {
"url": {"type": "string", "description": "The URL of the file to download"},
"filename": {"type": "string", "description": "The destination filename (e.g. 'podcast1.wav')"},
"use_sd": {"type": "boolean", "description": "Save to microSD card if true, or local flash if false (default true)", "default": True}
},
"required": ["url", "filename"]
}
}
]
},
@@ -522,5 +535,17 @@ class MCPServer:
else:
raise RuntimeError("Failed to play decoded audio stream. Check format (16kHz 16-bit PCM WAV recommended).")
elif name == "download_file":
url = str(args.get("url"))
filename = str(args.get("filename"))
use_sd = bool(args.get("use_sd", True))
from download_util import download_file
saved_path = download_file(url, filename, use_sd=use_sd)
if saved_path:
return f"Successfully downloaded file to '{saved_path}'."
else:
raise RuntimeError(f"Failed to download file from '{url}'.")
else:
raise ValueError(f"Unknown tool: {name}")