搜索API集成服务

一个集成Perplexity AI搜索API的MCP服务器,为AI助手和其他MCP客户端提供网页搜索功能,支持多查询、区域搜索和域名过滤。

  • by s-abinash
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 s-abinash/perplexity-search-mcp

使用说明

根据全局信息,翻译目标语言为中文,且“API”必须翻译为“API”,原文内容“Perplexity Search API MCP Server”翻译为中文是“Perplexity搜索API MCP服务器”

一个模型上下文协议(MCP)服务器,提供与Perplexity AI的搜索API的集成。此服务器允许AI助手和其他MCP客户端使用Perplexity不断更新的索引执行网络搜索,并获取排名搜索结果。

特点/功能

  • 使用Perplexity AI的搜索API(非聊天/LLM)进行网络搜索🔍
  • 返回带有标题、URL和摘要的排序搜索结果
  • 📅 发布日期和最后更新时间戳
  • 🌍 带国家过滤的区域搜索
  • 🎯 域名过滤以将结果限制在特定网站
  • 🔄 支持多查询(一次请求最多可包含5个查询)
  • ⚙️ 可配置的结果数量和内容提取深度

先决条件

安装

  1. 克隆此存储库:
git clone https://github.com/s-abinash/perplexity-mcp.git
cd perplexity-mcp
  1. 安装依赖项:
npm install
  1. 构建项目:
npm run build

配置

设置您的API密钥

你需要设置 PERPLEXITY_API_KEY 使用包含您Perplexity API密钥的环境变量。

选项1:在你的shell中导出

export PERPLEXITY_API_KEY=your_api_key_here

选项2:使用.env文件(用于开发) 创建一个 .env 项目根目录中的文件:

PERPLEXITY_API_KEY=your_api_key_here

MCP客户端配置

要使用此服务器与MCP客户端(如Claude Desktop)配合,需在您的MCP配置文件中添加以下内容:

**Note:** Some systems may require the full path to the `node` executable instead of just `node`. You can find the full path by running: ```bash which node ``` For example, it might return `/usr/local/bin/node` or `/home/username/.nvm/versions/node/v20.0.0/bin/node`.

对于 macOS 上的 Claude Desktop (~/Library/Application Support/Claude/claude_desktop_config.json):

{
  "mcpServers": {
    "perplexity": {
      "command": "node",
      "args": ["/absolute/path/to/perplexity-mcp/dist/index.js"],
      "env": {
        "PERPLEXITY_API_KEY": "your_api_key_here"
      }
    }
  }
}

如果你遇到问题,尝试使用 node 的完整路径:

{
  "mcpServers": {
    "perplexity": {
      "command": "/usr/local/bin/node",
      "args": ["/absolute/path/to/perplexity-mcp/dist/index.js"],
      "env": {
        "PERPLEXITY_API_KEY": "your_api_key_here"
      }
    }
  }
}

适用于Windows的Claude Desktop (%APPDATA%\Claude\claude_desktop_config.json):

{
  "mcpServers": {
    "perplexity": {
      "command": "node",
      "args": ["C:\\path\\to\\perplexity-mcp\\dist\\index.js"],
      "env": {
        "PERPLEXITY_API_KEY": "your_api_key_here"
      }
    }
  }
}

如果你在Windows上遇到问题,请尝试使用node的完整路径:

{
  "mcpServers": {
    "perplexity": {
      "command": "C:\\Program Files\\nodejs\\node.exe",
      "args": ["C:\\path\\to\\perplexity-mcp\\dist\\index.js"],
      "env": {
        "PERPLEXITY_API_KEY": "your_api_key_here"
      }
    }
  }
}
To find your node path: - **macOS/Linux**: Run `which node` in terminal - **Windows**: Run `where node` in Command Prompt

使用方法

服务器提供了一个工具: perplexity_search

参数

  • query (必需):字符串或字符串数组(最多5个)- 搜索查询/多个搜索查询
  • max_results (可选,默认值:10):要返回的结果数量(1-20)
  • max_tokens_per_page (可选,默认值:1024):从每页中提取的最大标记数
  • country (可选):用于区域搜索的ISO 3166-1 alpha-2国家代码(例如,“US”、“GB”、“DE”、“JP”)
  • search_domain_filter (可选):用于过滤结果的域名数组(最多20个)

示例

基本搜索:

{
  "query": "latest AI developments 2024",
  "max_results": 5
}

区域搜索:

{
  "query": "government policies on renewable energy",
  "country": "US",
  "max_results": 10
}

域名过滤搜索:

{
  "query": "climate change research",
  "search_domain_filter": ["science.org", "nature.com", "cell.com"],
  "max_results": 10
}

多查询搜索:

{
  "query": [
    "artificial intelligence trends 2024",
    "machine learning breakthroughs",
    "AI applications in healthcare"
  ],
  "max_results": 5
}

响应格式

服务器返回格式化后的搜索结果,其中包含:

  • 结果数量及标题
  • URL
  • 代码片段(页面内容的预览)
  • 出版日期(如有)
  • 最后更新日期(如有)

单个查询响应示例:

# Search Results for: "latest AI developments 2024"

### 1. 2024: A year of extraordinary progress in AI
**URL:** https://blog.google/technology/ai/2024-progress/
**Snippet:** In 2024, we released the first models in our Gemini 2.0...
**Published:** 2025-01-23
**Last Updated:** 2025-09-25

---

### 2. The 2025 AI Index Report
**URL:** https://hai.stanford.edu/ai-index/2025
**Snippet:** Read the translation. In 2023, researchers introduced...
**Published:** 2024-09-10

---

多查询响应示例:

# Multi-Query Search Results

## Query 1: "artificial intelligence trends 2024"
[Results for query 1...]

---

## Query 2: "machine learning breakthroughs"
[Results for query 2...]

---

使用MCP客户端的示例用法

当与像Claude这样的MCP客户端一起使用时:

User: Can you search for "latest developments in quantum computing" and limit to academic sources?

Claude: I'll search for that using Perplexity's Search API.
[Uses perplexity_search tool with:
  query="latest developments in quantum computing"
  search_domain_filter=["arxiv.org", "science.org", "nature.com"]
  max_results=10
]

服务器将从Perplexity不断更新的索引中返回排名搜索结果,包括标题、网址、摘要片段和发布日期。

发展

以开发模式运行服务器:

npm run dev

构建项目:

npm run build

API 参考

如需了解有关Perplexity API的更多信息,请参阅:

故障排除

“PERPLEXITY_API_KEY”环境变量是必需的

确保你已经设置了 PERPLEXITY_API_KEY 在启动服务器之前设置环境变量。

“未知工具:perplexity_search”

确保您的MCP客户端已正确连接到服务器,并且能够看到可用的工具。

API速率限制

请留意Perplexity API的速率限制。请查看您的API套餐以了解详情。

许可证

麻省理工学院(MIT)

做出贡献

欢迎贡献!请随时提交拉取请求。