Metadata-Version: 2.5
Name: thunderstore-mcp
Version: 0.1.0
Summary: Unofficial local stdio MCP server for the Thunderstore mod repository
Requires-Python: >=3.11
Requires-Dist: httpx<1,>=0.27.1
Requires-Dist: mcp<2,>=1.12
Requires-Dist: pydantic<3,>=2.7
Description-Content-Type: text/markdown

# Thunderstore MCP

独立的 Python stdio 服务，可以从游戏社区查找模组、阅读包文档、比较版本依赖，并把选定版本的 ZIP 保存到本地。全部工具都使用 Thunderstore 的匿名公开接口，安装后即可使用。

## 安装和启动

需要 Python 3.11 或更高版本。在仓库目录使用 uv 安装并运行：

```powershell
uv sync --locked --python 3.11
uv run --no-sync thunderstore-mcp
```

启动后进程等待 MCP 客户端通过标准输入发送请求。也可以在独立虚拟环境中执行 `python -m pip install .`，然后运行 `thunderstore-mcp` 或 `python -m thunderstore_mcp`。

## MCP 客户端配置

下面的 Windows 配置直接启动本仓库虚拟环境中的服务，可复制到支持 `mcpServers` 的客户端配置中：

```json
{
  "mcpServers": {
    "thunderstore": {
      "command": "E:/GitHub/mcp/thunderstore-mcp/.venv/Scripts/thunderstore-mcp.exe"
    }
  }
}
```

仓库放在其他位置时请调整 `command`。macOS 和 Linux 使用虚拟环境中的 `bin/thunderstore-mcp`。ZIP 默认保存在 `~/Downloads/Thunderstore`；自定义目录可在同一服务条目加上 `"env": {"THUNDERSTORE_DOWNLOAD_DIR": "D:/ModDownloads/Thunderstore"}`。

## 工具

| 工具 | 参数与结果 |
|---|---|
| `list_communities` | 可按 `search` 查游戏名或别称，返回社区 `identifier`、图像和统计等字段。用 `offset` 和 `limit` 分段读取。 |
| `get_community` | 按 `community` 标识读取社区详情。 |
| `get_community_filters` | 取得该社区的 `package_categories` 和 `sections`，分别从 `id` 和 `uuid` 取搜索参数。 |
| `search_packages` | 在指定 `community` 浏览或按 `query`、`namespace` 搜索。支持 `included_categories`、`excluded_categories`、`section`、`ordering`、`include_deprecated`、`include_nsfw` 和 `page`。 |
| `get_package` | 用 `namespace` 和 `name` 查跨社区包记录。`latest` 含当前版本及原始依赖字符串，`community_listings` 列出发布社区，`package_url` 为上游项目链接。 |
| `get_listing` | 再指定 `community`，取得该社区中的分类、封面、统计、团队、依赖预览及 `listing_url` 项目主页。 |
| `get_team` | 用团队名称作为 `namespace` 获取团队资料及可用的捐赠链接。 |
| `list_versions` | 按 `namespace` 和 `name` 列出可用版本与下载、安装链接。保留站点顺序；要确定当前版本，请取 `get_package.latest.version_number`。 |
| `get_version` | 指定 `namespace`、`name` 和 `version`，返回文件大小 `size`（字节）、完整版本标识、下载地址、团队等元数据。 |
| `list_dependencies` | 查询指定 `version` 的直接前置，保留所需的确切版本和状态。支持 `page`。 |
| `list_dependants` | 按 `community`、`namespace`、`name` 查询依赖该包的项目，支持分页、废弃包与成人内容开关。 |
| `get_readme`、`get_changelog` | 按 `namespace`、`name` 和 `version` 获取该版本的 Markdown 正文或更新日志。 |
| `get_wiki`、`get_wiki_page` | 先按 `namespace` 和 `name` 读 Wiki 目录，再用 `pages` 中的 `id` 作为 `page_id` 取正文。 |
| `download_version` | 按 `namespace`、`name` 和 `version` 重新取得文件资料并下载 ZIP；返回 `path`（绝对路径）、`bytes_written` 和 `sha256`。 |

**分页**　包搜索、直接前置和反向依赖使用站点页码，从 `page=1` 开始。返回的 `next` 非空时，以相同筛选条件请求下一页。社区与版本接口一次返回完整列表，服务保留上游顺序并按 `offset`、`limit` 截取，默认 20 条，最多 100 条；将 `next_offset` 作为下一次的 `offset`，等于 `null` 表示结束。

**返回字段**　原始 REST 对象及嵌套字段照常返回。`listing_url`、本地分页信息和下载结果由服务补充。实测 `get_package` 的 `total_downloads` 和 `rating_score` 在部分包上返回 `-1`；查看社区的下载量与评分可使用 `get_listing.download_count` 和 `rating_count`。社区项目页的依赖列表可以是预览，查询完整前置请使用 `list_dependencies` 并翻页。遇到限流、无权限、资源不存在或网络故障时，工具调用会携带错误返回；HTTP 错误保留状态码。

**下载校验**　服务按版本元数据和可用的 HTTP 长度核对字节数，在临时文件中验证 ZIP 格式与上游声明的受支持校验值，然后写入最终文件名。`sha256` 是本地计算值，`verified_checksums` 列出实际通过的上游校验。重复下载到同名路径会报错并保留已有文件；传输或校验失败时清理本次临时文件。

## 调用示例

查询 Valheim 游戏社区，找到一个包并选择版本：

```text
list_communities(search="Valheim")
search_packages(community="valheim", query="BepInExPack_Valheim")
get_listing(community="valheim", namespace="denikson", name="BepInExPack_Valheim")
list_versions(namespace="denikson", name="BepInExPack_Valheim")
get_version(namespace="denikson", name="BepInExPack_Valheim", version="5.4.2200")
list_dependencies(namespace="denikson", name="BepInExPack_Valheim", version="5.4.2200")
download_version(namespace="denikson", name="BepInExPack_Valheim", version="5.4.2200")
```

## 发布到 PyPI

在 GitHub 发布 Release 时，使用 `v1.2.3` 或 `1.2.3` 这样的版本标签。GitHub Actions 会从标签读取版本号，构建并校验 wheel 和源码包，再通过 `pypi` 环境的 Trusted Publisher 上传 `thunderstore-mcp`。

## 测试

```powershell
uv sync --locked --python 3.11
uv run --no-sync pytest -q
uv run --no-sync python tests/live_smoke.py
```

`pytest` 使用模拟 HTTP 响应测试筛选参数、分页、版本依赖、站点错误和下载异常。`live_smoke.py` 另行启动真实 stdio 客户端与服务，匿名请求 Thunderstore，在临时目录验证下载；运行它需要能访问官网与下载 CDN。

### 2026-11-24 验证记录

| 验证方式 | 结果 |
|---|---|
| 离线 | 54 个测试用例通过，覆盖上游异常、参数与分页、同名文件、并发下载、中断清理及校验失败。 |
| 实站 stdio | 匿名初始化、枚举并调用全部 16 个工具。Valheim 分类筛选连续两页各返回 20 个不同包，按团队与关键词组合搜索也返回了目标包。 |
| 实站下载 | `ValheimModding-Jotunn-2.30.2.zip` 实际落盘 835,193 字节，与站点 `size` 一致。ZIP 条目 CRC、清单版本及前置 `denikson-BepInExPack_Valheim-5.4.2333` 均通过核对。本地独立回读的 SHA-256 为 `8aae92da2be0eb6820cd4cf57e2f6c1d6ad0d738d4915966e7c3d7a94e9a9b0f`，本次响应没有提供可比对的上游摘要。 |

服务使用 Thunderstore 的 Experimental 与 Cyberstorm 公开读取接口。可查阅 [官方 API 文档](https://thunderstore.io/api/docs/) 和 [Cyberstorm 接口定义](https://github.com/thunderstore-io/Thunderstore/blob/master/django/thunderstore/api/urls.py)。
