download_torrent
Initiate torrent downloads by providing a magnet link, HTTP URL, or local file path to the rqbit client.
Instructions
Download a torrent from a magnet link, HTTP URL, or local file.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| magnet_link_or_url_or_path | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- rqbit_client/mcp_server.py:28-39 (registration)The tool 'download_torrent' is registered as an MCP tool via the @mcp.tool() decorator. It handles downloading a torrent from a magnet link, HTTP URL, or local file path.
@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) - rqbit_client/mcp_server.py:28-39 (handler)The handler function 'download_torrent' accepts a magnet link, HTTP URL, or file path, logs the request, calls rqbit_client.add_torrent(), and returns the result as a JSON string or an error message.
@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) - The 'add_torrent' method on RqbitClient is the helper that the tool delegates to. It POSTs to /torrents?&overwrite=true (with &is_url=true if the input starts with 'http'), sending either file contents or the raw URL string as the request body.
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 - rqbit_client/mcp_server.py:28-28 (schema)The tool's schema is implicitly defined by the function signature: it takes a single string parameter 'magnet_link_or_url_or_path' and returns a string.
@mcp.tool()