P

Perplexity 高级搜索集成包

@code-yeongyu/perplexity-advanced-mcp
0 Stars 418 次浏览 code-yeongyu 更新于 2026-08-23

一个先进的集成包,利用 OpenRouter 和 Perplexity API 提供增强的网络搜索功能,支持简单和复杂的查询处理,并且具备文件附件支持。

该服务暂未提供标准配置,请参考 README 手动接入

服务介绍

Perplexity Advanced MCP

GitHub
PyPI
smithery badge

한국어


概述

Perplexity Advanced MCP 是一个高级集成包,利用 OpenRouterPerplexity API 提供增强的查询处理能力。通过直观的命令行界面和强大的 API 客户端,该包能够无缝地与 AI 模型进行交互,适用于简单和复杂的查询。

perplexity-mcp 的比较

虽然 perplexity-mcp 使用 Perplexity AI 的 API 提供基本的网页搜索功能,但 Perplexity Advanced MCP 提供了几个额外的功能:

  • 多供应商支持: 支持 PerplexityOpenRouter API,为您提供选择供应商的灵活性
  • 查询类型优化: 区分简单和复杂查询,优化成本和性能
  • 文件附件支持: 允许将文件内容作为上下文包含在您的查询中,从而实现更精确和具有上下文的响应
  • 增强的重试逻辑: 实现强大的重试机制以提高可靠性

总体而言,这是与编辑器(如 ClineCursor)集成时处理代码库最合适的 MCP。

功能

  • 统一的 API 客户端: 支持 OpenRouterPerplexity API,并且可以配置模型来处理简单和复杂的查询。
  • 命令行界面 (CLI): 使用 Typer 管理 API 密钥配置并运行 MCP 服务器。
  • 高级查询处理: 结合文件附件处理,允许您在查询中包含上下文数据。
  • 强大的重试机制: 利用 Tenacity 进行重试逻辑,确保一致且可靠的 API 通信。
  • 可定制的日志记录: 灵活的日志配置,用于详细的调试和运行时监控。

最佳 AI 配置

为了获得最佳的 AI 助手体验(例如 Cursor, Claude for Desktop),我建议在项目说明或 AI 规则中添加以下配置:

<perplexity-advanced-mcp>
    <description>
        Perplexity is an LLM that can search the internet, gather information, and answer users' queries.

        For example, let's suppose we want to find out the latest version of Python.
        1. You would search on Google.
        2. Then read the top two or three results directly to verify.

        Perplexity does that work for you.

        To answer a user's query, Perplexity searches, opens the top search results, finds information on those websites, and then provides the answer.

        Perplexity can be used with two types of queries: simple and complex. Choosing the right query type to fulfill the user's request is most important.
    </description>
    <simple-query>
        <description>
            It's cheap and fast. However, it's not suitable for complex queries. On average, it's more than 10 times cheaper and 3 times faster than complex queries.
            Use it for simple questions such as "What is the latest version of Python?"
        </description>
        <pricing>
            $1/M input tokens
            $1/M output tokens
        </pricing>
    </simple-query>

    <complex-query>
        <description>
            It's slower and more expensive. Compared to simple queries, it's on average more than 10 times more expensive and 3 times slower.
            Use it for more complex requests like "Analyze the attached code to examine the current status of a specific library and create a migration plan."
        </description>
        <pricing>
            $1/M input tokens
            $5/M output tokens
        </pricing>
    </complex-query>

    <instruction>
        When reviewing the user's request, if you find anything unexpected, uncertain, or questionable, **and you think you can get answer from the internet**, do not hesitate to use the "ask_perplexity" tool to consult Perplexity. However, if the internet is not required to satisfy users' request, it's meaningless to ask to perplexity.
        Since Perplexity is also an LLM, prompt engineering techniques are paramount.
        Remember the basics of prompt engineering, such as providing clear instructions, sufficient context, and examples
        Include as much context and relevant files as possible to smoothly fulfill the user's request. When adding files as attachments, make sure they are absolute paths.
    </instruction>
</perplexity-advanced-mcp>

此配置有助于 AI 助手更好地理解何时以及如何使用 Perplexity 搜索功能,从而优化成本和性能。

使用

通过 Smithery 安装

要通过 Smithery 自动为 Claude Desktop 安装 Perplexity Advanced MCP:

npx -y @smithery/cli install @code-yeongyu/perplexity-advanced-mcp --client claude

快速开始使用 uvx

运行 MCP 服务器最简单的方法是使用 uvx

uvx perplexity-advanced-mcp -o <openrouter_api_key> # or -p <perplexity_api_key>

您还可以通过环境变量配置 API 密钥:

export OPENROUTER_API_KEY="your_key_here"
# or
export PERPLEXITY_API_KEY="your_key_here"

uvx perplexity-advanced-mcp

注意:

  • 同时提供 OpenRouter 和 Perplexity API 密钥会导致错误
  • 当同时提供了 CLI 参数和环境变量时,CLI 参数优先

CLI 使用 Typer 构建,确保了用户友好的命令行体验。

MCP 搜索工具

该包包括一个通过 ask_perplexity 函数集成的 MCP 搜索工具。它支持简单和复杂的查询,并处理文件附件以提供额外的上下文。

  • 简单查询: 提供快速高效的响应。
  • 复杂查询: 进行详细的推理并支持格式为 XML 的文件附件。

配置

  • API 密钥: 通过命令行选项或环境变量配置 OPENROUTER_API_KEYPERPLEXITY_API_KEY
  • 模型选择: 配置(在 src/perplexity_advanced_mcp/config.py 中)将查询类型映射到特定模型:
    • OpenRouter:
      • 简单查询:perplexity/sonar
      • 复杂查询:perplexity/sonar-reasoning
    • Perplexity:
      • 简单查询:sonar-pro
      • 复杂查询:sonar-reasoning-pro

开发背景与理念

这个项目源于我个人的好奇心和实验。遵循最近的 "vibe coding" 趋势,超过 95% 的代码是通过 Cline + Cursor IDE 编写的。人们常说“空谈无用,给我看代码”——好吧,有了 Wispr Flow 的语音转文字魔法,我真的是说了几句话,代码就出现了!大部分开发工作都是我说“写 x y z 的代码,修复这里的 x y z 错误。”然后按回车键完成的。令人惊讶的是,创建这个完全功能性的项目只花了不到几个小时的时间。

从项目脚手架到文件结构,所有内容都是通过 LLM 编写和审查的。甚至用于 PyPI 发布的 GitHub Actions 工作流和发布审批流程也是通过 Cursor 处理的。作为一个人类开发者,我的角色是:

  • 启动和停止 MCP 服务器以帮助 AI 进行适当的测试
  • 在出现问题时复制并提供错误日志
  • 从互联网上查找并提供 Python MCP SDK 文档和示例
  • 请求修改看起来不正确的代码

在这个许多事情都可以自动化和替代的世界里,我希望这个 MCP 能够帮助像你这样的开发者发现除了编写代码之外的价值。愿这个工具能帮助你成为能够做出更高层次决策和考虑的新时代开发者。

开发

要贡献或修改此包:

1. 克隆仓库:

gh repo clone code-yeongyu/perplexity-advanced-mcp

2. 安装依赖:

uv sync

3. 贡献代码:

欢迎贡献!请遵循现有的代码风格和提交指南。

许可证

本项目采用 MIT 许可证。

相关 MCP 服务