返回市场
торрент搜索-MCP

торрент搜索-MCP

作者:philogicae14 星标更新:2025-09-30

项目介绍

Torrent Search MCP 服务器及 API

uv Python PyPI Actions status License: MIT Ask DeepWiki

此仓库提供了一个用于在ThePirateBay、Nyaa和YggTorrent上搜索种子的Python API和MCP(模型上下文协议)服务器。它允许轻松地集成到其他应用程序或服务中。

<a href="https://glama.ai/mcp/servers/@philogicae/torrent-search-mcp"> <img width="380" height="200" src="https://gips3.baidu.com/it/u=3790603102,1341216396&fm=3081&app=3081&f=PNG?w=760&h=400" alt="Torrent Search MCP 服务器" /> </a>

快速开始

如何使用MCP客户端 使用Docker运行以绕过常见的DNS问题

目录

功能

  • 对ThePirateBay、Nyaa和YggTorrent的API封装。
    • 您的Ygg通行证密钥会本地注入到种子文件/磁力链接中,确保其不会被外部暴露
  • 标准化通信的MCP服务器接口(标准I/O、SSE、流式HTTP)
  • FastAPI服务器接口,供替代HTTP访问(例如,直接API调用或测试)
  • 工具:
    • 在ThePirateBay、Nyaa和YggTorrent上搜索种子
    • 通过ID获取特定种子的信息
    • 通过ID获取特定种子的磁力链接或种子文件

设置

先决条件

  • 活跃的YggTorrent账户和通行证密钥(可选)。
  • Python 3.10+(用于PyPI安装)。
  • uv(用于本地开发)
  • Chromium及其所需依赖项
  • Docker和Docker Compose(用于Docker设置)

配置(可选)

如果要与YggTorrent交互,此应用需要通行证密钥。

  1. 找到您的通行证密钥:在YggTorrent网站上,导航至我的账户 -> PASSKEY字段。
  2. 设置环境变量:应用从环境变量读取配置。推荐的方式是创建一个.env文件在项目根目录下。应用会自动加载它。参见.env.example了解所有可用选项。

安装

选择以下安装方法之一。

从PyPI安装(推荐)

此方法最适合将包作为库使用或不修改代码的情况下运行服务器。

  1. 从PyPI安装包:
pip install torrent-search-mcp
crawl4ai-setup # 对于crawl4ai/playwright
playwright install --with-deps chromium # 如果前一命令失败
  1. 在您将运行应用的目录中创建一个.env文件,并添加您的通行证密钥(可选):
YGG_PASSKEY=您的通行证密钥
  1. 运行MCP服务器(默认:标准I/O):
python -m torrent_search

本地开发

此方法适用于希望修改源代码的贡献者。 使用uv

  1. 克隆仓库:
git clone https://github.com/philogicae/torrent-search-mcp.git
cd torrent-search-mcp
  1. 使用uv安装依赖项:
uv sync --locked
uvx playwright install --with-deps chromium
  1. 复制示例并创建您的配置文件,添加您的通行证密钥(可选):
cp .env.example .env
  1. 运行MCP服务器(默认:标准I/O):
uv run -m torrent_search

Docker

此方法使用Docker在容器中运行服务器。

compose.yaml配置为绕过DNS问题(使用quad9 DNS)。

  1. 克隆仓库(如果尚未克隆):
git clone https://github.com/philogicae/torrent-search-mcp.git
cd torrent-search-mcp
  1. 复制示例并创建您的配置文件,添加您的通行证密钥(可选):
cp .env.example .env
  1. 使用Docker Compose构建并运行容器(默认端口:8000):
docker compose up --build -d
  1. 访问容器日志:
docker logs torrent-search-mcp -f

使用

作为Python包装器

from torrent_search import torrent_search_api

结果 = torrent_search_api.search_torrents('...')
for 种子 in 结果:
    print(f"{种子.filename} | {种子.size} | {种子.seeders} SE | {种子.leechers} LE | {种子.date} | {种子.source}")

作为MCP服务器

from torrent_search import torrent_search_mcp

torrent_search_mcp.run(transport="sse")

作为FastAPI服务器

此项目还包括一个FastAPI服务器,作为通过标准HTTP API与库交互的另一种方式。这可用于直接API调用、与其他网络服务集成或测试目的。

运行FastAPI服务器:

# 使用Python
python -m torrent_search --mode fastapi
# 使用uv
uv run -m torrent_search --mode fastapi
  • --host <主机>:默认值:0.0.0.0
  • --port <端口>:默认值:8000
  • --reload:当代码更改时启用自动重新加载(对开发有用)。
  • --workers <工作者>:默认值:1

然后可以在http://<主机>:<端口>访问FastAPI服务器

可用端点: FastAPI服务器提供了类似于MCP服务器的功能。关键端点包括:

  • /:简单的健康检查端点。返回{"状态": "好"}
  • /docs:交互式API文档(Swagger UI)。
  • /redoc:替代API文档(ReDoc)。

环境变量(如YGG_PASSKEY)的配置方式与MCP服务器相同(通过项目根目录下的.env文件)。

通过MCP客户端

可以与任何兼容MCP的客户端一起使用。可用工具:

  • search_torrents:搜索种子。
  • get_torrent_info:通过ID获取特定种子的信息。
  • get_magnet_link_or_torrent_file:通过ID获取特定种子的磁力链接或种子文件。

使用Windsurf示例

配置:

{
  "mcpServers": {
    ...
    // 使用标准I/O(仅需uv)
    "torrent-search-mcp": {
      "命令": "uvx",
      "参数": ["torrent-search-mcp"],
      "环境": {"YGG_PASSKEY": "您的通行证密钥"} // 可选
    },
    // 使用docker(仅需docker)
    "torrent-search-mcp": {
      "命令": "docker",
      "参数": ["run", "-i", "-p", "8000:8000", "-e", "YGG_PASSKEY=您的通行证密钥", "philogicae/torrent-search-mcp:latest", "torrent-search-mcp"]
    },
    // 使用SSE传输(需要安装)
    "torrent-search-mcp": {
      "serverUrl": "http://127.0.0.1:8000/sse"
    },
    // 使用流式HTTP传输(需要安装)
    "torrent-search-mcp": {
      "serverUrl": "http://127.0.0.1:8000/mcp" // 并非每个客户端都支持
    },
    ...
  }
}

变更日志

查看CHANGELOG.md了解此项目的变更历史。

贡献

欢迎贡献!请打开一个问题或提交一个拉取请求。

许可证

本项目根据MIT许可证发布 - 查看LICENSE文件了解详情。