MIT License
10
最近更新:4个月前

一个用于智能代码分析和调试的Model Context Protocol (MCP)服务器,通过Perplexity AI的API实现,并与Claude桌面客户端无缝集成。

Perplexity MCP 服务器

一个基于模型上下文协议(MCP)的服务器,通过Perplexity AI的API提供智能代码分析与调试功能。与Claude桌面客户端无缝协作。

Perplexity Server MCP server

功能特性

  • 智能错误分析:提供编码错误的详细解析与根本原因分析
  • 模式识别:自动识别常见错误模式并给出针对性解决方案
  • 完整解决方案:分步修复指南并提供多种实现方案
  • 最佳实践:包含编码规范与错误预防技巧
  • 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)

服务器将提供:

  1. 错误的根本原因分析
  2. 包含代码示例的分步解决方案
  3. 预防类似问题的最佳实践
  4. 替代实现方案

安装指南

先决条件

  • 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:从源码安装

  1. 克隆仓库:
bash 复制代码
git clone https://github.com/yourusername/perplexity-server.git
cd perplexity-server
  1. 安装依赖:
bash 复制代码
npm install
  1. 构建并全局安装:
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检查器进行调试

贡献指南

  1. Fork代码仓库
  2. 创建特性分支(git checkout -b feature/amazing-feature
  3. 提交变更(git commit -m 'Add some amazing feature'
  4. 推送分支(git push origin feature/amazing-feature
  5. 发起Pull Request

许可证

本项目采用MIT许可证 - 详见LICENSE文件。

致谢