Serpapi
OpenCode plugin for SerpApi — secure MCP-first search across Google, Bing, Amazon, Walmart, YouTube, Google Maps, Google Scholar, and 100+ other engines.
2
171
近 7 天 171
37.6
生态多维模型
4 天前
2026-09-30
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-serpapi@0.1.1"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-serpapi@0.1.1"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D opencode-serpapiOpenCode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
An OpenCode plugin that connects your agent to SerpApi's hosted MCP server for Google, Amazon, Walmart, eBay, YouTube, Google Maps, Google Scholar, and 100+ other engines.
Quick Start
1. Get an API key
Sign up at serpapi.com and set the key:
Free tier – 250 searches/month, no credit card required.
export SERPAPI_API_KEY="your_serpapi_key"
2. Install the plugin
Add the npm package name to the plugin list in opencode.json. OpenCode
automatically installs npm plugins at startup:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-serpapi"]
}
Restart OpenCode (or start a new session). OpenCode downloads the published package and the plugin registers SerpApi as a remote MCP server automatically.
3. Use it
Ask in natural language and the agent picks the tool and engine on its own:
Search Google for the best Python web frameworks
Compare prices for AirPods Pro on Amazon, Walmart, and eBay
Find academic papers about transformer architectures published after 2020
Find well-reviewed coffee shops near Times Square
How it works
This is an OpenCode MCP integration with a native HTTPS fallback. The plugin:
- Registers the hosted SerpApi MCP server at
https://mcp.serpapi.com/mcp. - Reads
SERPAPI_API_KEYfrom the OpenCode process and resolves it into the MCPAuthorization: Bearer ...header. - Exposes a native
serpapi_searchtool that callshttps://serpapi.com/search.jsonwith the runtime's built-infetch. - Registers the bundled
serpapi-web-searchskill for engine selection, routing, credential safety, and response guidance.
The MCP server is the preferred route. When its tools are unavailable or the
server is disabled, the native tool remains available as the direct HTTPS route.
An existing user-defined mcp.serpapi configuration is preserved.
Features
- MCP-native search — OpenCode receives the
searchtool from theserpapiMCP server. - All SerpApi engines — the MCP server supports Google, Bing, Amazon, Walmart, eBay, YouTube, Google Maps, Google Scholar, and other engines.
- MCP header authentication — the key is read from
SERPAPI_API_KEYand sent in the MCPAuthorizationheader, not embedded in the MCP URL or source code. - Structured results — the MCP server supports JSON, compact responses, Markdown output, and engine-specific parameter validation.
- Local search guidance — the bundled skill helps the model choose engines and use engine-specific parameters without owning credentials or making API requests.
- Portable fallback —
serpapi_searchuses the runtime's built-infetch, with no CLI, shell, or cURL dependency. - Engine-aware queries — the native tool maps its generic
qargument to engine-specific fields such as Amazon'sk, Walmart'squery, eBay's_nkw, and YouTube'ssearch_query.
Supported Engines
| Category | Engines |
|---|---|
| Web Search | Google, Google Light, Bing, DuckDuckGo, Yahoo, Yandex, Baidu, Naver |
| AI Search | Google AI Mode, Google AI Overview, Bing Copilot, Brave AI Mode |
| Shopping | Amazon, Walmart, eBay, Google Shopping, Home Depot |
| Local / Maps | Google Maps, Google Local, Yelp, TripAdvisor, OpenTable |
| Research | Google Scholar, Google Patents, Google Trends |
| News | Google News |
| Media | Google Images, Google Videos, YouTube, Google Lens |
| Travel | Google Flights, Google Hotels, Google Travel Explore |
| Jobs | Google Jobs |
| Finance | Google Finance |
| Apps | Google Play, Apple App Store |
Engines not listed in the plugin's query-field map still pass through with q.
See the full, current list at serpapi.com/search-engine-apis. Detailed engine, MCP, CLI, REST, credential, and response guidance is bundled under skills/serpapi-web-search/references/.
Troubleshooting
- "Tool not showing up" — confirm
opencode-serpapiis listed underplugininopencode.json, confirmSERPAPI_API_KEYis available to OpenCode, and restart OpenCode. - "Invalid API key" — replace
SERPAPI_API_KEYwith the current key from the SerpApi dashboard, then restart OpenCode so the MCP header is rebuilt. - MCP connection problems — run
opencode mcp list; theserpapientry should reportconnected. - Native request failure — the tool returns
SerpApi search failed: ...with the configured key redacted.
If MCP is unavailable, ask the agent to use serpapi_search. Confirm that
SERPAPI_API_KEY is available to the OpenCode process.
Development
npm install
npm test
npm run typecheck
The test suite mocks fetch and covers request parameter mapping, trusted-key
enforcement, HTTP failures, missing credentials, and resolved MCP header
configuration. The plugin configures the serpapi MCP server, whose primary
tool is search, and also exposes serpapi_search as a native HTTPS route.
The bundled skill provides routing and operational guidance; engines.ts
supplies query-field mapping for native requests.
Related
- SerpApi MCP Server — for Claude Desktop, VS Code, and Cursor
- SerpApi Docs — full API reference
- SerpApi Playground — interactive API explorer
- OpenCode Plugin Docs
License
MIT License — see LICENSE file for details.
同类生态推荐
Raven
opencode-raven
Context-saving search and on-demand MCP routing for OpenCode through focused Raven agents.
Navigator
opencode-navigator
Search, navigate, and manage OpenCode sessions from the TUI
Zhihu Websearch
opencode-zhihu-websearch
Zhihu Web Search as an OpenCode websearch provider