https://github.com/helallao/perplexity-ai
- 2026-01-19:增加SKILL,
.claude/skills/perplexity-search - 2026-01-16: 重构项目结构,增加oai 端点适配
- 2026-01-13: 新增心跳检测功能,支持定时检测token健康状态并通过Telegram通知
- 2026-01-03: webui控制
- 2026-01-02:新增多token池支持,支持动态管理号池(列举/新增/删除)
- 2026-01-02:MCP 响应现在包含
sources字段,返回搜索结果的来源链接 - 2025-12-31:增加健康检查endpoint, http://127.0.0.1:8000/health
从示例文件复制并编辑 token_pool_config.json:
# 复制示例配置文件
cp token_pool_config-example.json token_pool_config.json编辑 token_pool_config.json,填入你的 Perplexity 账户 token:
{
"heart_beat": {
"enable": true,
"question": "今天是几号?",
"interval": 6,
"tg_bot_token": "your-telegram-bot-token",
"tg_chat_id": "your-telegram-chat-id"
},
"tokens": [
{
"id": "account1@example.com",
"csrf_token": "your-csrf-token-1",
"session_token": "your-session-token-1"
},
{
"id": "account2@example.com",
"csrf_token": "your-csrf-token-2",
"session_token": "your-session-token-2"
}
]
}获取 Token 的方法: 打开 perplexity.ai -> F12 开发者工具 -> Application -> Cookies
csrf_token对应next-auth.csrf-tokensession_token对应__Secure-next-auth.session-token
心跳检测功能可以定期检查每个 token 的健康状态,并通过 Telegram 通知结果:
| 配置项 | 说明 |
|---|---|
enable |
是否启用心跳检测 |
question |
用于检测的测试问题 |
interval |
检测间隔时间(小时) |
tg_bot_token |
Telegram Bot Token(用于发送通知) |
tg_chat_id |
Telegram Chat ID(接收通知的聊天ID) |
如果不需要心跳检测功能,可以省略
heart_beat配置或将enable设为false
# 创建 .env 文件(可选)
cp token_pool_config-example.json token_pool_config.json
cp .env.example .env
# 启动服务
docker compose up -dservices:
perplexity-mcp:
image: shancw/perplexity-mcp:latest
container_name: perplexity-mcp
ports:
- "${MCP_PORT:-8000}:8000"
environment:
# MCP 认证密钥
- MCP_TOKEN=${MCP_TOKEN:-sk-123456}
# 管理员 Token(用于号池管理 API,可选)
- PPLX_ADMIN_TOKEN=${PPLX_ADMIN_TOKEN:-}
# SOCKS 代理配置 (可选)
# 格式: socks5://[user[:pass]@]host[:port][#remark]
# - SOCKS_PROXY=${SOCKS_PROXY:-}
volumes:
# 挂载 token 池配置文件
- ./token_pool_config.json:/app/token_pool_config.json:ro
restart: unless-stopped# Perplexity MCP Server 环境变量配置
# 复制此文件为 .env 并填入实际值
# ============================================
# MCP 服务配置
# ============================================
# MCP 服务端口
MCP_PORT=8000
# MCP API 认证密钥 (客户端需要在 Authorization header 中携带此密钥)
MCP_TOKEN=sk-123456
# 管理员 Token(用于号池管理 API:新增/删除 token 等操作)
PPLX_ADMIN_TOKEN=your-admin-token支持配置多个 Perplexity 账户 token,实现负载均衡和高可用。
- 创建 JSON 配置文件
token_pool_config.json:
{
"tokens": [
{
"id": "user1",
"csrf_token": "your-csrf-token-1",
"session_token": "your-session-token-1"
},
{
"id": "user2",
"csrf_token": "your-csrf-token-2",
"session_token": "your-session-token-2"
}
]
}{
"mcpServers": {
"perplexity": {
"type": "http",
"url": "http://127.0.0.1:8000/mcp",
"headers": {
"Authorization": "Bearer sk-123456"
}
}
}
}Base URL: http://127.0.0.1:8000/v1
认证: 在请求头中添加 Authorization: Bearer <MCP_TOKEN>
curl http://127.0.0.1:8000/v1/models \
-H "Authorization: Bearer sk-123456"curl http://127.0.0.1:8000/v1/chat/completions \
-H "Authorization: Bearer sk-123456" \
-H "Content-Type: application/json" \
-d '{
"model": "perplexity-search",
"messages": [{"role": "user", "content": "今天天气怎么样"}],
"stream": false
}'curl http://127.0.0.1:8000/v1/chat/completions \
-H "Authorization: Bearer sk-123456" \
-H "Content-Type: application/json" \
-d '{
"model": "perplexity-reasoning",
"messages": [{"role": "user", "content": "分析一下人工智能的发展趋势"}],
"stream": true
}'| 模型 ID | 模式 | 说明 |
|---|---|---|
| Search 模式(Pro) | ||
perplexity-search |
pro | 默认搜索模型 |
sonar-search |
pro | Sonar 模型 |
gpt-5-2-search |
pro | GPT-5.2 |
claude-4-5-sonnet-search |
pro | Claude 4.5 Sonnet |
grok-4-1-search |
pro | Grok 4.1 |
| Reasoning 模式 | ||
perplexity-reasoning |
reasoning | 默认推理模型 |
gpt-5-2-thinking-reasoning |
reasoning | GPT-5.2 Thinking |
claude-4-5-sonnet-thinking-reasoning |
reasoning | Claude 4.5 Sonnet Thinking |
gemini-3-0-pro-reasoning |
reasoning | Gemini 3.0 Pro |
kimi-k2-thinking-reasoning |
reasoning | Kimi K2 Thinking |
grok-4-1-reasoning-reasoning |
reasoning | Grok 4.1 Reasoning |
| Deep Research 模式 | ||
perplexity-deepsearch |
deep research | 深度研究模型 |
以 ChatBox 为例:
- 打开设置 → AI 模型提供商 → 添加自定义提供商
- 填入:
- API Host:
http://127.0.0.1:8000 - API Key:
sk-123456(与 MCP_TOKEN 一致)
- API Host:
- 选择模型如
perplexity-search或perplexity-reasoning
perplexity/
├── server/ # MCP 服务器模块
│ ├── __init__.py # 包入口,导出主要组件
│ ├── main.py # 服务启动入口
│ ├── app.py # FastMCP 应用实例、认证中间件、核心查询逻辑
│ ├── mcp.py # MCP 工具定义 (list_models, search, research)
│ ├── oai.py # OpenAI 兼容 API (/v1/models, /v1/chat/completions)
│ ├── admin.py # 管理端点 (健康检查、号池管理、心跳控制)
│ ├── utils.py # 服务器专用工具函数 (验证、OAI模型映射)
│ ├── client_pool.py # 多账户连接池管理
│ └── web/ # 前端 Web UI (React + Vite)
│ ├── src/
│ │ ├── components/ # 组件
│ │ ├── hooks/ # React Hooks
│ │ ├── lib/
│ │ │ └── api.ts # API 请求封装
│ │ ├── pages/
│ │ │ └── Playground.tsx # Playground 页面
│ │ └── index.tsx # 入口文件
│ └── vite.config.ts # Vite 配置
├── client.py # Perplexity API 客户端
├── config.py # 配置常量
├── exceptions.py # 自定义异常
├── logger.py # 日志配置
└── utils.py # 通用工具函数 (重试、限流、JSON解析)
复制 .claude/commands/pp/ 目录下创建指令文件:
使用方式:
/pp:query 你的问题- 快速搜索/pp:reasoning 你的问题- 推理模式,多步思考分析/pp:research 你的问题- 深度研究,最全面彻底


