download_torrent
Download torrents using magnet links, HTTP URLs, or local files with the rqbit Torrent Client MCP for simplified torrent retrieval.
Instructions
Download a torrent from a magnet link, HTTP URL, or local file.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| magnet_link_or_url_or_path | Yes |
Implementation Reference
- rqbit_client/mcp_server.py:28-39 (handler)The main handler function for the 'download_torrent' MCP tool. It is decorated with @mcp.tool() for automatic registration and handles the tool execution by delegating to RqbitClient.add_torrent and serializing the result to JSON.@mcp.tool() async def download_torrent(magnet_link_or_url_or_path: str) -> str: """Download a torrent from a magnet link, HTTP URL, or local file.""" logger.info( f"Downloading torrent from magnet link/HTTP URL/local file: {magnet_link_or_url_or_path}" ) result = await rqbit_client.add_torrent(magnet_link_or_url_or_path) if isinstance(result, str): error = f"Error downloading torrent {magnet_link_or_url_or_path}: {result}" logger.error(error) return error return dumps(result)
- Supporting method in RqbitClient that implements the core logic of adding a torrent by making HTTP POST requests to the rqbit server API, handling different input types (magnet, URL, local file). Called by the tool handler.async def add_torrent( self, url_or_path: str, content: bytes | None = None ) -> dict[str, Any] | str: """Add a torrent from a magnet, HTTP URL, or local file.""" url = "/torrents?&overwrite=true" if url_or_path.startswith("http"): url += "&is_url=true" if content: return await self._safe_request("POST", url, content=content) # type: ignore if os.path.exists(url_or_path): try: with open(url_or_path, "rb") as f: return await self._safe_request("POST", url, content=f.read()) # type: ignore except FileNotFoundError: return f"Error: File not found at {url_or_path}" except IOError as e: return f"Error reading file {url_or_path}: {e}" return await self._safe_request("POST", url, content=url_or_path) # type: ignore