delete_torrent
Remove a torrent and its associated files from the client by providing the torrent ID.
Instructions
Delete a torrent and its files.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| torrent_id | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- rqbit_client/mcp_server.py:66-75 (registration)MCP tool registration (via @mcp.tool() decorator) that defines the 'delete_torrent' tool. Calls RqbitClient.delete_torrent() and returns success/error string.
@mcp.tool() async def delete_torrent(torrent_id: str) -> str: """Delete a torrent and its files.""" logger.info(f"Deleting torrent: {torrent_id}") result = await rqbit_client.delete_torrent(torrent_id) if isinstance(result, str): error = f"Error deleting torrent {torrent_id}: {result}" logger.error(error) return error return "Successfully deleted torrent " + torrent_id - rqbit_client/wrapper/client.py:215-217 (handler)Handler implementation: makes an HTTP POST request to the /torrents/{id}/delete endpoint of the rqbit API to delete the torrent and its files.
async def delete_torrent(self, id_or_infohash: str) -> None | str: """Delete a torrent and its files.""" return await self._safe_request("POST", f"/torrents/{id_or_infohash}/delete") - rqbit_client/wrapper/client.py:78-82 (helper)Helper that wraps _request with error handling, returning error string on HTTP failures.
async def _safe_request(self, method: str, path: str, **kwargs) -> Any | str | None: try: return await self._request(method, path, **kwargs) except RqbitHTTPError as e: return str(e) - rqbit_client/wrapper/client.py:31-49 (helper)Core HTTP request helper that handles response parsing (JSON, binary, text, 204 No Content) and raises typed exceptions on errors.
async def _request(self, method: str, path: str, **kwargs) -> Any: """Make a regular API request.""" try: response = await self._client.request(method, path, **kwargs) response.raise_for_status() if response.status_code == 204: # No Content return None if response.headers.get("content-type") == "application/json": return response.json() if response.headers.get("content-type") == "application/octet-stream": return await response.read() # type: ignore return response.text except httpx.HTTPStatusError as e: raise RqbitHTTPError( f"HTTP error: {e.response.status_code} - {e.response.text}", status_code=e.response.status_code, ) from e except httpx.RequestError as e: raise RqbitHTTPError(f"Request error: {e}", status_code=0) from e