SerpApi MCP Server

by ilyazub
Verified

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

Integrations

  • Manages environment variables for the MCP server, specifically for storing and accessing the SerpApi API key

  • Retrieves parsed search results from Baidu search engine via SerpApi

  • Performs searches on DuckDuckGo and retrieves parsed search results via SerpApi

SerpApi MCP 服务器

构建一个 MCP 服务器:

  • 使用 API 密钥通过 SerpApi快速获取已解析的搜索引擎结果页面

此 MCP(模型上下文协议)服务器与SerpApi集成,可在各种搜索引擎中执行搜索,并检索实时和已归档结果。它提供工具和资源,以便与 MCP 客户端或主机(例如 Grok 或 Claude for Desktop)进行无缝交互。


安装

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

pip install mcp serpapi python-dotenv

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

快速入门

  1. 保存服务器代码:将服务器代码放在文件中,例如 server.py。
  2. 配置 API 密钥:在与 SerpApi API 密钥相同的目录中创建一个 .env 文件:
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、沃尔玛、雅虎、eBay、YouTube、DuckDuckGo、Yandex、百度
  • 工具
  • 搜索:使用查询和可选参数在指定引擎上执行搜索。
  • 资源
  • 位置:查找 Google 位置。

使用示例

这些示例假设 MCP 客户端(例如,使用 MCP 客户端 SDK 以 Python 编写)已连接到服务器。列出支持的引擎检索支持的搜索引擎列表:

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

执行搜索使用位置过滤器在 Google 上搜索“咖啡”:

result = await session.call_tool("search", { "query": "coffee", "engine": "google", "location": "Austin, TX" })

打印(结果)

配置

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

运行服务器

生产模式:使用以下命令启动服务器:

python server.py

开发模式:使用 MCP Inspector 进行调试:

mcp dev server.py

测试

使用 MCP 检查器或 MCP 客户端测试服务器。对于 Claude 桌面版,请在Claude_desktop_config.json中配置服务器,重启应用,然后使用锤子图标探索和测试可用的工具。

-
security - not tested
F
license - not found
-
quality - not tested

MCP 服务器与 SerpApi 集成,可从 Google、Bing、Yahoo 等多个搜索引擎检索搜索结果,从而可以快速访问实时和存档的搜索数据。

  1. Installation
    1. Quick Start
      1. Features
        1. Usage Examples
          1. Configuration
            1. Running the Server
          2. Testing
            ID: ps1js70fi2