内容
# tieba-mcp
<p align="center">
<img src="assets/logo.svg" alt="tieba-mcp logo" width="240">
</p>
<p align="center">
<strong>百度贴吧 MCP 服务器</strong> — 让 AI 助手能够搜索贴吧、浏览帖子、查看用户信息
</p>
<p align="center">
<img src="https://img.shields.io/badge/node-%3E%3D22-brightgreen" alt="Node version">
<img src="https://img.shields.io/badge/license-MIT-blue" alt="License">
<img src="https://img.shields.io/badge/MCP-v1.0-4A9EFF" alt="MCP version">
</p>
---
## 简介
`tieba-mcp` 是一个基于 [MCP (Model Context Protocol)](https://modelcontextprotocol.io/) 的百度贴吧服务器,让 Claude 等 AI 助手可以直接与百度贴吧交互。
目前网上还没有百度贴吧的官方 MCP 服务器,本项目填补了这一空白。
### 特性
- 纯只读操作,无需登录或 Cookie
- 6 个 MCP 工具覆盖用户、帖子、贴吧三大场景
- 基于 stdio 传输,兼容所有 MCP 客户端
- TypeScript 编写,类型安全
## 快速开始
### 环境要求
- Node.js >= 22
- 支持 MCP 的客户端(Claude Code、Claude Desktop、VS Code + Claude 插件等)
### 安装与配置
**1. 克隆仓库**
```bash
git clone https://github.com/Sartherland/tieba-mcp.git
cd tieba-mcp
npm install
npm run build
```
**2. 配置 MCP 客户端**
Claude Code — 在项目根目录创建 `.mcp.json`:
```json
{
"mcpServers": {
"tieba": {
"command": "node",
"args": ["dist/index.js"]
}
}
}
```
Claude Desktop — 编辑 `claude_desktop_config.json`:
```json
{
"mcpServers": {
"tieba": {
"command": "node",
"args": ["D:/Desktop/claude/tieba-mcp/dist/index.js"]
}
}
}
```
## 可用工具
### 贴吧相关
| 工具 | 说明 |
|------|------|
| `tieba_forum_threads` | 浏览贴吧帖子列表,支持按最新回复/最新发帖排序 |
| `tieba_forum_search` | 吧内搜索,支持关键词和用户筛选 |
| `tieba_post` | 获取帖子内容,包含楼层回复 |
### 用户相关
| 工具 | 说明 |
|------|------|
| `tieba_user_info` | 获取用户基本信息(UID、用户名、头像等) |
| `tieba_user_posts` | 获取用户发帖列表(分页) |
| `tieba_user_like_forums` | 获取用户关注的贴吧列表 |
### 系统
| 工具 | 说明 |
|------|------|
| `tieba_health` | 检查上游 API 服务状态 |
> 所有工具均为只读,无需认证。
## 使用示例
在 Claude 中可以这样使用:
```
帮我查一下"显卡吧"最近有哪些热门帖子
```
```
搜索"彩虹六号吧"里关于"新干员"的帖子
```
```
查看用户"贴吧大神"的基本信息
```
## 环境变量
| 变量 | 默认值 | 说明 |
|------|--------|------|
| `TIEBA_API_BASE` | `https://cf.eztb.org` | 上游 API 地址 |
## 架构
```
AI 助手 (Claude)
│ MCP 协议 (stdio)
▼
tieba-mcp 服务器
│ HTTP / SSE
▼
Tieba-API-SCF (cf.eztb.org)
│
▼
百度贴吧服务器
```
## 工作原理
本 MCP 服务器通过 [Tieba-API-SCF](https://github.com/Dilettante258/Tieba-API-SCF) 代理请求,后者是对百度贴吧内部 API 的 REST 封装。MCP 服务器与上游 API 之间的所有通信均通过 HTTPS 加密传输。
## 项目结构
```
tieba-mcp/
├── src/
│ ├── index.ts # 入口:启动 stdio 传输
│ ├── server.ts # McpServer 创建和工具注册
│ ├── client/
│ │ └── tieba-client.ts # HTTP 客户端(含 SSE 流处理)
│ ├── tools/
│ │ ├── system.tools.ts # tieba_health
│ │ ├── user.tools.ts # 用户相关工具
│ │ └── forum.tools.ts # 贴吧相关工具
│ ├── schemas/common.ts # 共享 Zod Schema
│ └── types/api.ts # API 类型定义
├── assets/
│ ├── logo.svg # Logo
│ └── icon.svg # 小尺寸图标
├── tests/ # 测试文件
├── dist/ # 编译输出
├── package.json
├── tsconfig.json
└── README.md
```
## 相关项目
- [Tieba-API-SCF](https://github.com/Dilettante258/Tieba-API-SCF) — 上游 REST API 服务
- [aiotieba](https://github.com/Starry-OvO/aiotieba) — Python 异步贴吧 API 库
- [Model Context Protocol](https://modelcontextprotocol.io/) — MCP 官方文档
## License
[MIT](LICENSE)