download_from_url
Download a file from a specified URL using this tool, which retrieves and returns the file path for further audio analysis on the MCP server. Input only the URL to proceed.
Instructions
Downloads a file from a given URL and returns the path to the downloaded file. Be careful, you will never know the name of the song.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes |
Implementation Reference
- src/mcp_music_analysis/server.py:200-219 (handler)The handler function decorated with @mcp.tool() that implements the logic to download an audio file from a URL, validate it's mp3 or wav, save to temp directory, and return the path.@mcp.tool() def download_from_url(url: str) -> str: """ Downloads a file from a given URL and returns the path to the downloaded file. Be careful, you will never know the name of the song. """ # mettre une exception si ce n'est pas un fichier audio ! if not url.endswith(".mp3") and not url.endswith(".wav"): raise ValueError(f"URL: {url} is not a valid audio file") response = requests.get(url) if response.status_code == 200: file_path = os.path.join(tempfile.gettempdir(), "downloaded_file") with open(file_path, "wb") as file: file.write(response.content) return file_path else: raise ValueError(f"Failed to download file from URL: {url}")