返回博客
教程2026年6月28日1 分钟阅读

JustSerpAPI MCP Server 教程:让 AI 助手搜索、检查并调用 SERP API

了解如何把 JustSerpAPI MCP Server 连接到 Codex、Claude Desktop、Cursor、Claude Code、OpenAI Agents SDK 和其他 MCP 兼容客户端。

MCP 是什么

MCP 是 Model Context Protocol 的缩写。它为 AI 客户端提供一种标准方式,用来连接外部工具和 API。放到 SERP API 工作流里,这意味着你的助手不只是解释请求,还可以发现可用端点、检查必填参数、调用 API,并在响应包含下一页 token 或 offset 时继续获取分页结果。

JustSerpAPI MCP Server 会把 JustSerpAPI 暴露给 Codex、Claude Desktop、Cursor、Claude Code、OpenAI Agents SDK 以及其他 MCP 兼容的 AI 助手工具。

JustSerpAPI MCP 能帮你做什么

  • 根据自然语言请求找到合适的 Google Search、Google Maps、Google Trends、Google Shopping 或 Web 端点。
  • 调用前检查必填参数、可选参数、枚举值和分页提示。
  • 使用你的 API key 调用选定的 JustSerpAPI 端点,并返回原始 JSON 数据。
  • 当上一次响应包含下一页 token 或 offset 时,继续获取分页结果。
  • 查询订阅状态、剩余 credits、最近 API 使用量、已消耗 credits 和端点趋势。
  • 让助手解释常见 API 错误,例如 402 响应。

准备 JustSerpAPI API key

使用 MCP 之前,请先准备 JustSerpAPI API key。登录 JustSerpAPI Dashboard,然后从账户或 API key 区域复制你的 key。

API key 是敏感信息。不要提交到公开仓库,不要放进截图,也不要分享给不可信的人。请把示例中的 your_api_key 替换成你的真实 key。

推荐配置:Remote HTTP

Remote HTTP 是推荐方式。你不需要在本地运行服务器,只需把托管的 MCP URL 和 Authorization header 添加到 MCP 客户端配置。

json
{
  "mcpServers": {
    "justserpapi": {
      "url": "https://mcp.justserpapi.com/mcp",
      "headers": {
        "Authorization": "Bearer your_api_key"
      }
    }
  }
}

保存配置后,重启或刷新 MCP 客户端。任何支持 Remote HTTP MCP server 的客户端都可以通过这个 URL 连接 JustSerpAPI MCP。

备选配置:本地 stdio

如果你的客户端更适合使用本地命令式 MCP server,可以通过 npx 在本地运行。

json
{
  "mcpServers": {
    "justserpapi": {
      "command": "npx",
      "args": ["-y", "justserpapi-mcp"],
      "env": {
        "JUSTSERPAPI_API_KEY": "your_api_key"
      }
    }
  }
}

这个配置会运行与 npx -y justserpapi-mcp 相同的本地命令,并通过 JUSTSERPAPI_API_KEY 传入你的 key。

本地 stdio 适合你希望 MCP server 运行在自己机器上的场景。大多数用户建议从 Remote HTTP 开始。

可以直接使用的提示词

连接成功后,可以用正常业务语言提问。

text
Find the Google search API and show me the required parameters.
text
Search Google for "best running shoes" in the United States.
text
Find the Google Maps reviews endpoint and tell me how to request the next page.
text
Get Google Trends trending-now results for the US.
text
Find the Google Shopping search API and call it for "iphone 16 case".
text
Convert this web page to Markdown: https://example.com
text
Continue to the next page of the previous JustSerpAPI result.
text
Check my remaining JustSerpAPI credits.
text
Show my API usage for the last 30 days.
text
The API returned code 402. Explain what it means and what I should check.

推荐工作流

  • 先让助手为你的搜索任务找到合适端点。
  • 调用前让它检查 schema,尤其是位置、语言、设备、分页或结果类型会影响请求时。
  • 查看必填字段后再提供业务参数,不要让助手猜测必填值。
  • 如果响应包含分页元数据,让助手根据下一页提示继续请求。
  • 调用失败时,提供响应码和错误信息,便于助手结合端点 schema 和常见 API 行为进行判断。

FAQ

API key 应该放在哪里?

Remote HTTP 使用 Authorization: Bearer your_api_key header。本地 stdio 使用 JUSTSERPAPI_API_KEY 环境变量。

MCP 会替代 API 文档吗?

不会。MCP 更适合让 AI 助手在工作流中发现并调用 API。完整端点细节和字段定义,仍然应该阅读 API 文档。

助手可以调用所有 JustSerpAPI 端点吗?

助手会通过你的 JustSerpAPI API key 调用 API。实际访问权限取决于你的账户、订阅、剩余 credits 和端点权限。调用前,建议让助手展示它计划使用的端点和参数。

下一步

如果你已经有 JustSerpAPI API key,可以先用 Remote HTTP 配置,然后让 AI 客户端为你常用的搜索工作流找到一个端点。完整端点说明请打开 JustSerpAPI 文档。源码和发布更新可以查看 JustSerpAPI MCP GitHub

继续使用 JustSerpAPI

打开 Dashboard 获取 API key,阅读完整 API 文档,或查看 MCP GitHub 项目的最新配置。