Back to MCP directory
publicPublicdnsLocal runtime

SerpApi Google Search

一个基于SerpApi的MCP服务器,用于快速获取搜索引擎解析结果。

article

README

🚀 SerpApi MCP 服务器

SerpApi MCP服务器可快速搭建一个MCP服务器,借助SerpApi获取解析后的搜索引擎结果页面(SERPs)。此服务器与SerpApi集成,能在多个搜索引擎上执行搜索,检索实时和存档结果,还可与MCP客户端或主机无缝交互。

🚀 快速开始

  1. 保存服务器代码:将服务器代码存入文件,例如server.py
  2. 配置API密钥:在相同目录中创建.env文件,并添加您的SerpApi API密钥:
SERPAPI_API_KEY=your_api_key_here
  1. 运行服务器:启动服务器:
python server.py
  1. 与MCP客户端集成:将服务器连接到MCP客户端或主机(例如Claude for Desktop)。对于Claude,请更新Claude_desktop_config.json
{
  "mcpServers": {
    "serpapi": {
      "command": "python",
      "args": ["path/to/server.py"]
    }
  }
}

重启客户端以加载服务器。

✨ 主要特性

  • 支持的搜索引擎丰富:涵盖Google、Google Light、Bing、Walmart、Yahoo、eBay、YouTube、DuckDuckGo、Yandex、Baidu等。
  • 实用工具:提供search工具,可在指定引擎上执行搜索,带有查询和可选参数。
  • 特色资源:具备locations资源,可查找Google地点。

📦 安装指南

要设置SerpApi MCP服务器,请安装所需的Python库:

pip install mcp serpapi python-dotenv

您还需要一个SerpApi API密钥。在SerpApi上注册以获取一个。

💻 使用示例

基础用法

列出支持的搜索引擎

获取支持的搜索引擎列表:

engines = await session.read_resource("locations")
print(engines)

执行搜索

在Google上搜索“咖啡”并带有位置过滤器:

result = await session.call_tool("search", {
    "query": "咖啡",
    "engine": "google",
    "location": "奥斯汀, 德州"
})
print(result)

📚 详细文档

配置

API密钥:在.env文件中设置SerpApi API密钥为SERPAPI_API_KEY

运行服务器

  • 生产模式:启动服务器:
python server.py
  • 开发模式:使用MCP Inspector进行调试:
mcp dev server.py

🔧 技术细节

使用MCP Inspector或MCP客户端测试服务器。对于Claude for Desktop,请在Claude_desktop_config.json中配置服务器,重启应用程序,并使用锤子图标探索和测试可用工具。

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client