get_torrent
Retrieve a torrent's magnet link or file path by its unique ID from YggTorrent or La Cale torrent databases.
Instructions
Get a specific torrent (either magnet link or torrent file path) by id.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| torrent_id | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- fr_torrent_search/mcp_server.py:65-72 (handler)MCP tool handler: The @mcp.tool() decorated function that implements the 'get_torrent' tool logic. Calls get_client().get_torrent(torrent_id) and returns the result as a string.
@mcp.tool() def get_torrent(torrent_id: str) -> str: """Get a specific torrent (either magnet link or torrent file path) by id.""" logger.info(f"Getting torrent for: {torrent_id}") result = get_client().get_torrent(torrent_id) if isinstance(result, bytes): return "Received raw bytes, not supported via this tool." return result or "Torrent not found" - FrTorrentApi.get_torrent(): Aggregator client method that delegates to the appropriate sub-API (YggTorrent or LaCale) based on the torrent_id prefix.
def get_torrent(self, torrent_id: str, **kwargs) -> str | bytes | None: """ Get a specific torrent by delegating to the appropriate API. """ self.ensure_initialized() api = self._get_api_for_id(torrent_id) if api: return api.get_torrent(torrent_id, **kwargs) return None - BaseTorrentApi.get_torrent(): Core base class implementation that iterates through modes (FILE, MAGNET, BYTES) calling get_torrent_as() to return the first successful result.
def get_torrent(self, torrent_id: str, **kwargs) -> str | bytes | None: """ Get a specific torrent. Args: torrent_id: The ID of the torrent. Returns: The .torrent filename, magnet link, .torrent bytes or None. """ for mode in self.order: result = self.get_torrent_as(torrent_id, mode, **kwargs) if result: return result return None - BaseTorrentApi.get_torrent_as(): Helper that dispatches to download_torrent_file (FILE), get_magnet_link (MAGNET), or download_torrent_file_bytes (BYTES) based on mode.
def get_torrent_as( self, torrent_id: str, mode: Mode | str, **kwargs ) -> str | bytes | None: """ Get a specific torrent by mode. Args: torrent_id: The ID of the torrent. mode: The mode to use to get the torrent. Returns: The .torrent filename, magnet link, .torrent bytes or None. """ _mode: Mode = Mode(mode) if isinstance(mode, str) else mode if _mode not in self.order: logger.error(f"Invalid mode: {_mode.value}") else: try: if _mode == Mode.FILE: return self.download_torrent_file(torrent_id, **kwargs) elif _mode == Mode.MAGNET: return self.get_magnet_link(torrent_id) elif _mode == Mode.BYTES: return self.download_torrent_file_bytes(torrent_id) except Exception as e: logger.error( f"Failed to get torrent ({_mode.value}) for ID {torrent_id}: {e}" ) return None - fr_torrent_search/mcp_server.py:65-66 (registration)Registration: The @mcp.tool() decorator on line 65 registers 'get_torrent' as an MCP tool.
@mcp.tool() def get_torrent(torrent_id: str) -> str: