pku-treehole-mcp-server

horizon921/pku-treehole-mcp-server

3.2

If you are the rightful owner of pku-treehole-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

The 北大树洞 MCP Server is a Model Context Protocol server designed to support keyword search functionality for 北大树洞 content.

Tools
1
Resources
0
Prompts
0

北大树洞 MCP Server

这是一个支持关键词检索北大树洞内容的 MCP (Model Context Protocol) 服务器。

安装和启动

1. 安装依赖

cd treehole_mcp_server
pip install -r requirements.txt

2. 启动服务器

uvicorn main:app --host 0.0.0.0 --port 8001

服务器将在 http://localhost:8001 启动。

手动测试

1. 查看可用工具

curl http://localhost:8001/tools

2. 测试关键词检索

curl -X POST "http://localhost:8001/tools/search_treehole" \
  -H "Content-Type: application/json" \
  -d '{
    "keyword": "高数",
    "page": 1,
    "limit": 5,
    "token": "Bearer YOUR_TOKEN_HERE",
    "cookie": "YOUR_COOKIE_HERE",
    "uuid": "YOUR_UUID_HERE",
    "xsrf": "YOUR_XSRF_TOKEN_HERE"
  }'

3. 使用 Postman 测试

  • 方法: POST
  • URL: http://localhost:8001/tools/search_treehole
  • Headers: Content-Type: application/json
  • Body (raw JSON):
{
  "keyword": "高数",
  "page": 1,
  "limit": 5,
  "token": "",
  "cookie": "",
  "uuid": "",
  "xsrf": ""
}

在 MCPilot 中添加服务器

  1. 打开 MCPilot 应用
  2. 进入"设置" -> "MCP 服务器"页面
  3. 点击"添加新服务器"
  4. 填写以下信息:
    • 名称: 北大树洞
    • 基础URL: http://localhost:8001
    • 描述: 北大树洞关键词检索服务
  5. 保存配置
  6. MCPilot 将自动发现 search_treehole 工具

API 接口说明

GET /tools

返回可用工具列表

POST /tools/search_treehole

根据关键词检索树洞内容

参数:

  • keyword (必需): 搜索关键词
  • page (可选): 页码,默认1
  • limit (可选): 每页数量,默认25
  • token (可选): Authorization token
  • cookie (可选): Cookie
  • uuid (可选): UUID
  • xsrf (可选): XSRF Token

返回格式:

{
  "posts": [
    {
      "pid": 123456,
      "text": "树洞内容...",
      "timestamp": 1234567890,
      "likenum": 10,
      "reply": 5
    }
  ],
  "total": 100
}

配置认证信息

方法1: 环境变量

export TREEHOLE_TOKEN="Bearer YOUR_TOKEN"
export TREEHOLE_COOKIE="YOUR_COOKIE"
export TREEHOLE_UUID="YOUR_UUID"
export TREEHOLE_XSRF="YOUR_XSRF"

方法2: API配置

# 查看当前配置
curl http://localhost:8001/config

# 设置配置
curl -X POST "http://localhost:8001/config" \
  -H "Content-Type: application/json" \
  -d '{
    "token": "Bearer YOUR_TOKEN",
    "cookie": "YOUR_COOKIE",
    "uuid": "YOUR_UUID", 
    "xsrf": "YOUR_XSRF"
  }'

获取认证信息

  1. 打开浏览器访问 https://treehole.pku.edu.cn/web/
  2. 登录北大树洞
  3. 打开浏览器开发者工具 (F12)
  4. 切换到 Network 标签页
  5. 刷新页面或进行任意操作
  6. 查找对 pku_hole 的请求
  7. 在请求头中复制以下信息:
    • Authorization: 复制完整值
    • Cookie: 复制完整值
    • Uuid: 复制完整值
    • X-Xsrf-Token: 复制完整值

注意事项

  • 请遵守北大树洞的使用条款
  • 不要过于频繁地请求接口,建议添加适当的延时
  • 认证信息有时效性,需要定期更新
  • 生产环境建议使用 HTTPS