baidutiebamcp
v1.0.0
Published
百度贴吧MCP服务器,提供贴吧推荐帖子列表等功能
Maintainers
Readme
百度贴吧 MCP 服务器
这是一个基于 Model Context Protocol (MCP) 的百度贴吧服务器,提供贴吧推荐帖子列表、获取帖子详情、获取帖子评论等功能。
功能特性
工具 (Tools)
get_recommend_posts- 获取推荐帖子列表get_post_detail- 获取帖子详情get_post_comments- 获取帖子的评论列表
资源 (Resources)
tieba://recommend/posts- 推荐帖子列表tieba://{forum}/posts- 指定贴吧的帖子列表tieba://post/{post_id}- 帖子详情
安装和使用
方式一:NPX 安装(推荐)
直接使用 npx 运行,无需本地安装:
# 直接运行
npx baidutiebamcpMCP 配置文件中使用:
{
"mcpServers": {
"baidu-tieba": {
"command": "npx",
"args": ["baidutiebamcp"],
"disabled": false,
"alwaysAllow": [],
"env": {
"TIEBA_COOKIE": "你的百度贴吧Cookie,格式如:BDUSS=xxx; STOKEN=xxx; PSTM=xxx"
}
}
}
}方式二:全局安装
# 全局安装
npm install -g baidutiebamcp
# 运行
baidutiebamcpMCP 配置文件中使用:
{
"mcpServers": {
"baidu-tieba": {
"command": "baidutiebamcp",
"disabled": false,
"alwaysAllow": [],
"env": {
"TIEBA_COOKIE": "你的百度贴吧Cookie,格式如:BDUSS=xxx; STOKEN=xxx; PSTM=xxx"
}
}
}
}方式三:本地开发
# 克隆项目
git clone <repository-url>
cd baidutiebamcp
# 安装依赖
npm install
# 构建项目
npm run build
# 运行服务器
npm startMCP 配置文件中使用:
{
"mcpServers": {
"baidu-tieba": {
"command": "node",
"args": ["path/to/baidutiebaMcp/build/index.js"],
"disabled": false,
"alwaysAllow": [],
"env": {
"TIEBA_COOKIE": "你的百度贴吧Cookie,格式如:BDUSS=xxx; STOKEN=xxx; PSTM=xxx"
}
}
}
}Cookie 配置
为了获取更多内容和避免反爬限制,建议在 MCP 配置中设置百度贴吧的 Cookie。
获取 Cookie 的方法
- 打开浏览器,访问 百度贴吧
- 登录你的百度账号
- 按 F12 打开开发者工具
- 切换到 "Network" 标签页
- 刷新页面,找到任意一个请求
- 在请求头中找到
Cookie字段,复制其值
Cookie 格式示例
BDUSS=xxxxxxxxxx; STOKEN=xxxxxxxxxx; PSTM=xxxxxxxxxx; ...重要提示
- Cookie 包含敏感信息,请妥善保管
- 不要在公共场所或代码仓库中暴露 Cookie
- Cookie 有有效期,过期后需要重新获取
- 建议定期更新 Cookie 以确保服务正常运行
API 接口说明
获取推荐帖子
// 工具调用
{
"name": "get_recommend_posts",
"arguments": {
"forum": "生活", // 可选:指定贴吧
"page": 1, // 可选:页码,默认1
"page_size": 20, // 可选:每页数量,默认20
"offset": 0, // 可选:偏移量,默认0
"last_tid": "9912293948" // 可选:上一页最后一个帖子ID,用于分页
}
}获取帖子详情
// 工具调用
{
"name": "get_post_detail",
"arguments": {
"post_id": "1001" // 必需:帖子ID
}
}获取帖子评论
// 工具调用
{
"name": "get_post_comments",
"arguments": {
"thread_id": "9912985050", // 必需:帖子ID
"forum_id": "22714897", // 必需:贴吧ID
"page": 1, // 可选:页码,默认为1
"see_lz": 0 // 可选:是否只看楼主(0=否,1=是,默认为0)
}
}项目结构
baidutiebaMcp/
├── src/
│ └── index.ts # 主服务器代码
├── build/ # 编译输出目录
├── package.json # 项目配置
├── tsconfig.json # TypeScript配置
└── README.md # 说明文档