Skip to main content
Glama
ilyazub

SerpApi MCP Server

by ilyazub

SerpApi MCP 服务器

建造

构建一个 MCP 服务器:

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

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


安装

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

pip install mcp serpapi python-dotenv

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

Related MCP server: G-Search MCP

快速入门

  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
A
license - permissive license
-
quality - not tested

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ilyazub/serpapi-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server