rqbit的Python API包装器和MCP服务器
     
此存储库为 rqbit torrent客户端。它允许轻松集成到其他应用程序或服务中。
目录
- 先决条件 - 配置 - 安装 - 从PyPI安装(推荐) - 促进地方发展 -
- 作为Python API包装器 - 作为MCP服务器 - 通过MCP客户端 - Windsurf示例
特性
- 的API包装
rqbittorrent客户端。 - 用于标准化通信的MCP服务器接口(stdio、sse、流式http)
- 工具:
- list_torrents:列出所有种子及其详细信息。 - download_torrent:从磁铁链接或文件下载种子。 - get_torrent_details:获取特定种子的详细信息。 - get_torrent_stats:获取特定种子的统计数据/状态。 - pause_torrent:暂停洪流。 - start_torrent:启动torrent。 - forget_torrent:忘记torrent,保留文件。 - delete_torrent:删除torrent及其文件。
设置
先决条件
配置
此应用程序需要您的URL rqbit 例子
设置环境变量:复制 .env.example 向 .env 在项目的根目录中,使用您的设置对其进行编辑。应用程序将自动从以下位置加载变量 .env:
- MCP服务器:
- RQBIT_URL:rqbit实例的URL(默认值: http://localhost:3030). - RQBIT_HTTP_BASIC_AUTH_USERPASS:如果在rqbit实例中设置。
- Rqbit实例:
- RQBIT_HTTP_BASIC_AUTH_USERPASS:基本身份验证的用户名和密码,格式为 username:password. - RQBIT_HTTP_API_LISTEN_ADDR:HTTP API的监听地址(例如。, 0.0.0.0:3030). - RQBIT_UPNP_SERVER_ENABLE:启用或禁用UPnP服务器(例如。, true 或 false). - RQBIT_UPNP_SERVER_FRIENDLY_NAMEUPnP服务器的友好名称(例如。, rqbit-media). - RQBIT_EXPERIMENTAL_UTP_LISTEN_ENABLE:启用或禁用uTP侦听器(默认值: false). - 检查 rqbit 其他变量和更多信息。
安装
选择以下安装方法之一。
从PyPI安装(推荐)
此方法最适合将包用作库或在不修改代码的情况下运行服务器。
- 从PyPI安装软件包:
pip install rqbit-mcp- 创建一个
.env运行应用程序并添加应用程序的目录中的文件rqbit网址:
RQBIT_URL=http://localhost:3030- 运行MCP服务器(默认:stdio):
python -m rqbit_client促进地方发展
此方法适用于希望修改源代码的贡献者。 使用 uv:
- 克隆存储库:
git clone https://github.com/philogicae/rqbit-mcp.git
cd rqbit-mcp- 使用安装依赖项
uv:
uv sync --locked- 通过复制示例创建配置文件并添加设置:
cp .env.example .env- 运行MCP服务器(默认:stdio):
uv run -m rqbit_client对于Docker
此方法使用Docker在容器中运行服务器。 compose.yaml包括 rqbit torrent客户端。
- 克隆存储库(如果您还没有):
git clone https://github.com/philogicae/rqbit-mcp.git
cd rqbit-mcp- 通过复制示例创建配置文件并添加设置:
cp .env.example .env- 使用Docker Compose构建并运行容器(默认端口:8000):
docker compose up --build -d- 访问容器日志:
docker logs rqbit-mcp -f用法
作为Python API包装器
import asyncio
from rqbit_client.wrapper import RqbitClient
async def main():
# Read the RQBIT_URL from the .env file or fallback to default (http://localhost:3030)
async with RqbitClient() as client:
# Download a torrent
magnet_link = "magnet:?xt=urn:btih:..."
torrent = await client.download_torrent(magnet_link)
print(torrent)
# Check status
status = await client.get_torrent_stats(torrent["id"])
print(status)
# List torrents
torrents = await client.list_torrents()
print(torrents)
if __name__ == "__main__":
asyncio.run(main())作为MCP服务器
from rqbit_client import RqbitMCP
RqbitMCP.run(transport="sse") # 'stdio', 'sse', or 'streamable-http'通过MCP客户端
适用于任何兼容MCP的客户端。可用工具:
list_torrents:列出所有种子。download_torrent:通过磁力链接或文件路径下载种子。get_torrent_details:获取特定种子的详细信息。get_torrent_stats:获取特定种子的统计数据/状态。pause_torrent:暂停洪流。start_torrent:启动torrent。forget_torrent:忘记torrent,保留文件。delete_torrent:删除torrent及其文件。
Windsurf示例
配置:
{
"mcpServers": {
...
# with stdio (only requires uv)
"rqbit-mcp": {
"command": "uvx",
"args": [ "rqbit-mcp" ],
"env": {
"RQBIT_URL": "http://localhost:3030", # (Optional) Default rqbit instance URL
"RQBIT_HTTP_BASIC_AUTH_USERPASS": "username:password" # (Optional) Only if setup in rqbit instance
}
},
# with docker (only requires docker)
"rqbit-mcp": {
"command": "docker",
"args": [ "run", "-i", "-p", "8000:8000", "-e", "RQBIT_URL=http://localhost:3030", "-e", "RQBIT_HTTP_BASIC_AUTH_USERPASS=username:password", "philogicae/rqbit-mcp:latest", "rqbit-mcp" ]
},
# with sse transport (requires installation)
"rqbit-mcp": {
"serverUrl": "http://127.0.0.1:8000/sse"
},
# with streamable-http transport (requires installation)
"rqbit-mcp": {
"serverUrl": "http://127.0.0.1:8000/mcp"
},
...
}
}更新日志
看 更改日志.md 查看此项目的更改历史。
贡献
欢迎投稿!请打开问题或提交拉取请求。
许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
