
Perplexity Server
一个用于智能代码分析和调试的Model Context Protocol (MCP)服务器,通过Perplexity AI的API实现,并与Claude桌面客户端无缝集成。
概述
Perplexity MCP 服务器
一个基于模型上下文协议(MCP)的服务器,通过Perplexity AI的API提供智能代码分析与调试功能。与Claude桌面客户端无缝协作。
功能特性
- 智能错误分析:提供编码错误的详细解析与根本原因分析
- 模式识别:自动识别常见错误模式并给出针对性解决方案
- 完整解决方案:分步修复指南并提供多种实现方案
- 最佳实践:包含编码规范与错误预防技巧
- Python支持:专门处理Python类型错误与常见编码问题
使用示例
可咨询以下问题:
- "修复这段Python代码中的TypeError"
- "这个错误信息是什么原因导致的?"
- "如何修正这段代码?"
包含您的代码片段以获取针对性分析:
python
def calculate_total(items):
total = 0
for item in items:
total = total + item['price'] # TypeError: string + int
data = [
{'name': 'Book', 'price': '10'},
{'name': 'Pen', 'price': '2'}
]
result = calculate_total(data)
服务器将提供:
- 错误的根本原因分析
- 包含代码示例的分步解决方案
- 预防类似问题的最佳实践
- 替代实现方案
安装指南
先决条件
- Node.js 18或更高版本
- Perplexity AI API密钥
方案1:通过npm安装(推荐)
bash
# 使用npm
npm install -g perplexity-mcp
# 或直接从仓库安装
npm install -g git+https://github.com/yourusername/perplexity-mcp.git
方案2:从源码安装
- 克隆仓库:
bash
git clone https://github.com/yourusername/perplexity-server.git
cd perplexity-server
- 安装依赖:
bash
npm install
- 构建并全局安装:
bash
npm run build
npm install -g .
配置Claude桌面端
添加到Claude桌面配置文件:
MacOS:~/Library/Application Support/Claude/claude_desktop_config.json
Windows:%APPDATA%/Claude/claude_desktop_config.json
json
{
"mcpServers": {
"perplexity": {
"command": "perplexity-mcp",
"args": [],
"env": {
"PERPLEXITY_API_KEY": "your-api-key-here"
}
}
}
}
或从源码安装时:
json
{
"mcpServers": {
"perplexity": {
"command": "node",
"args": ["/absolute/path/to/perplexity-server/build/index.js"],
"env": {
"PERPLEXITY_API_KEY": "your-api-key-here"
}
}
}
}
安全性
- API密钥安全存储在Claude桌面配置文件中
- 密钥通过环境变量传递给服务器
- 仓库中不存储敏感数据
- 服务器预期通过Claude环境获取API密钥
开发指南
项目结构
perplexity-server/
├── src/
│ └── index.ts # 主服务器实现
├── package.json # 项目配置
└── tsconfig.json # TypeScript配置
可用脚本
npm run build
:构建项目npm run watch
:监听变更并自动重建npm run prepare
:准备发布包npm run inspector
:运行MCP检查器进行调试
贡献指南
- Fork代码仓库
- 创建特性分支(
git checkout -b feature/amazing-feature
) - 提交变更(
git commit -m 'Add some amazing feature'
) - 推送分支(
git push origin feature/amazing-feature
) - 发起Pull Request
许可证
本项目采用MIT许可证 - 详见LICENSE文件。
致谢
- 感谢Perplexity AI提供强大API
- 基于Model Context Protocol构建