How to Add Free Web Search to OpenCode with MCP (No API Key)
OpenCode is an open source AI coding agent that runs in your terminal and works with models from many providers. Its code is at anomalyco/opencode (it used to live at sst/opencode). OpenCode gets extra tools from MCP servers. Add an MCP search tool and OpenCode can look things up on the live web and read full pages when it needs them. The same server works in your other MCP clients too.
We use AgentSearch, which ships as the @agentsearchhq/agentsearch-mcp package on npm and also runs as a free hosted remote MCP server. You don't need an API key, an account, or a wallet:
Free tier: 25 free searches per IP, then pay per call. No key needed.
Two versions of OpenCode. OpenCode 2 is the current version. It installs from npm as @opencode/cli (npm install -g @opencode/cli) or with curl -fsSL https://opencode.ai/v2/install | bash. OpenCode 1 is still on npm as opencode-ai. Both use the opencode command and the same config files. This guide covers both and says where they differ.
What we tested: on November 25, 2026 we installed OpenCode 2.4.1 (@opencode/cli, the current release) and OpenCode 1.19.6 (opencode-ai, the latest OpenCode 1 release) on Linux, each with fresh config folders and no sign-in to any model provider. We added both servers below with opencode mcp add, checked what it wrote to opencode.json, and ran opencode mcp list. We then ran opencode run against a small local stand-in for a model. OpenCode 2 called the hosted search tool and OpenCode 1 called the local one, and both got live results back. We used @agentsearchhq/agentsearch-mcp 1.8.7 (the current npm release). We did not test the OpenCode desktop app or a real model. Steps we didn't run ourselves are quoted from the OpenCode MCP docs.
Why add an MCP search tool?
- No search key to manage. OpenCode 2 has a built-in
websearchtool, but it runs through third-party search providers that you pick and usually connect with that provider's account or API key. AgentSearch's free tier needs neither. - Raw results. AgentSearch returns ranked results (title, URL, snippet, domain) as JSON, so OpenCode picks what to open.
- Full pages.
agentsearch_extractturns a URL into clean markdown, andagentsearch_renderloads JavaScript-heavy pages in a headless browser first. - News and screenshots. Dated news results and page screenshots are separate tools.
- One setup for every client. The same server works in Cursor, Claude Code, Zed, goose and other MCP clients.
Where OpenCode keeps MCP servers
MCP servers live under the mcp key of an OpenCode config file. Per the OpenCode config docs:
| Scope | Config file |
|---|---|
| One project | opencode.json (or opencode.jsonc) in the project folder, or .opencode/opencode.json |
| Every project | ~/.config/opencode/opencode.json (or .jsonc) |
Project settings override global ones. opencode mcp add writes to the project file by default and to the global file with --global. After editing a file by hand, start a new OpenCode session (OpenCode 2 also has opencode reload).
Option A: Add the local MCP server
With opencode mcp add (OpenCode 2)
From your project folder, run:
opencode mcp add agentsearch -- npx -y @agentsearchhq/agentsearch-mcp
Everything after -- is the command OpenCode starts. In our test it printed MCP server "agentsearch" added to .../opencode.json and wrote this to the project's opencode.json:
{
"mcp": {
"servers": {
"agentsearch": {
"type": "local",
"command": ["npx", "-y", "@agentsearchhq/agentsearch-mcp"]
}
}
}
}
Add --global (opencode mcp add agentsearch --global -- npx -y @agentsearchhq/agentsearch-mcp) to put it in ~/.config/opencode/opencode.json for every project. In our test that kept the other settings already in the file. The -y flag skips npx's install prompt, which a background process can't answer. The server runs on your machine as a local process over stdio. You need Node.js 20 or newer.
By hand (OpenCode 1 and 2)
OpenCode 1 uses a shorter shape, with each server name directly under mcp and an enabled flag:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"agentsearch": {
"type": "local",
"command": ["npx", "-y", "@agentsearchhq/agentsearch-mcp"],
"enabled": true
}
}
}
command is one array: the program first, then each argument as its own item. OpenCode 2 still reads this shape. In our test the same file connected in both 1.19.6 and 2.4.1, so use it if your team runs both versions. In OpenCode 2's own shape (mcp.servers), turn a server off with "disabled": true, not enabled.
Option B: Use the hosted server (no Node.js)
AgentSearch runs a free hosted remote MCP server at https://relay.agentsearchhq.com/mcp. It uses the Streamable HTTP transport and needs no sign-in, so there are no headers.
opencode mcp add agentsearch-hosted --url https://relay.agentsearchhq.com/mcp
That wrote:
{
"mcp": {
"servers": {
"agentsearch-hosted": {
"type": "remote",
"url": "https://relay.agentsearchhq.com/mcp"
}
}
}
}
For OpenCode 1, put "type": "remote", the url and "enabled": true directly under mcp.agentsearch-hosted. Remote servers use OAuth by default, and OpenCode asks you to sign in only when a server requires it. The AgentSearch relay doesn't, and in our test both versions showed it as connected with no sign-in prompt.
Pick one option. If you add both, the model sees two copies of each tool.
Step 2: Check the connection
Run opencode mcp list from the project folder. In our OpenCode 2.4.1 test, with both servers configured, it showed:
✓ agentsearch connected
✓ agentsearch-hosted connected
OpenCode 1.19.6 shows the same thing in a boxed list with each server's command or URL under its name.
If it says "No MCP servers configured". OpenCode 2 runs a background server, and the first opencode mcp list in a folder it hasn't opened yet printed that message in each new folder in our test, even though the file was correct. Running the same command a few seconds later showed both servers connected. opencode debug config shows which config files OpenCode found and what it read from them. Inside the TUI, /mcps lists servers and lets you connect or disconnect them.
What the tools do:
agentsearch_web_search: web search that returns up to 5 results (title, URL and a snippet). 25 free calls per IP.agentsearch_news_search,agentsearch_search_and_readandagentsearch_screenshot: news with publish dates, search plus the top pages as markdown in one call, and page screenshots. 10 free calls per IP each.agentsearch_extract: reads a URL and returns clean markdown or text. Free trial of 5 calls a day per IP.agentsearch_render: loads a JavaScript-heavy page in a headless browser first, then returns its content. Free trial of 3 calls a day per IP.agentsearch_review_lookupandagentsearch_review_submit: read and share agent-written reviews of web tools (local server only).
The search, news, search + read and screenshot allowances are totals per IP and don't reset. The extract and render trials reset daily. The local server has all 8 tools. The hosted one has the first 6.
Step 3: Try it
Start OpenCode in your project with opencode and ask for something that needs current information:
Search the web for the latest stable release of Vite and tell me if our package.json is behind.
Use agentsearch to find the official migration guide for Express 5, then list the breaking changes that affect src/server.ts.
Find the changelog for the newest TypeScript release and extract the section on breaking changes.
For a one-off run, opencode run "..." works the same way. Search results are snippets. When OpenCode needs the whole page, it can call agentsearch_extract, or agentsearch_render for pages built with JavaScript.
How OpenCode 2 calls MCP tools (Code Mode)
OpenCode 2 doesn't hand every MCP tool to the model by default. It uses Code Mode: the model gets one execute tool that runs a short piece of JavaScript, plus a catalog of the tools it can call from that code. In our test the catalog listed agentsearch (8 tools) and agentsearch-hosted (6 tools), and the model's call looked like this:
return await tools["agentsearch-hosted"].agentsearch_web_search({ query: "OpenCode open source AI coding agent" })
OpenCode ran it and passed the JSON results back to the model. Server names with a hyphen need the bracket form shown above, so a short name like agentsearch is easier for the model to get right.
To give the model the tools directly instead, add "codemode": false to the server entry. With that set, our test request listed them as agentsearch_agentsearch_web_search, agentsearch_agentsearch_extract and so on: the server name, an underscore, then the tool name. OpenCode 1 has no Code Mode and always lists them that way. In our OpenCode 1.19.6 run, the model called agentsearch_agentsearch_web_search directly and got results.
Permissions and fewer tools
Searches ran without a prompt in our test. Neither version asked before calling the AgentSearch tools. OpenCode 2 sets permissions with a permissions list in opencode.json, where each rule has an action, a resource and an effect (allow, ask or deny). MCP tools use the <server>_<tool> name as the action. Per the permissions docs, this asks before any AgentSearch call:
{
"permissions": [
{ "action": "agentsearch_*", "resource": "*", "effect": "ask" }
]
}
Hide tools you don't use. A deny rule removes matching tools from the model. With "codemode": false and this rule, the two review tools disappeared from the request in our test:
{
"permissions": [
{ "action": "agentsearch_agentsearch_review_*", "resource": "*", "effect": "deny" }
]
}
In OpenCode 1, the MCP docs do the same with a tools map and glob patterns, for example "tools": { "agentsearch_agentsearch_review_*": false }. We didn't test that one.
Built-in web search. If you only want AgentSearch to answer search requests in OpenCode 2, the web search docs say "websearch": false removes the built-in tool.
Optional: pay per call with a wallet
When you need more than the free allowance, the local server can pay per call in USDC on Base over x402, with no account and no API key. Paid calls go to AgentSearch's direct x402 API: search and news $0.003, extract $0.002, render $0.005, search + read $0.005, screenshot $0.004. See pricing for details. Calls are settled only after a successful answer.
Use a new, dedicated wallet that holds only a small amount of USDC. The wallet setup guide walks through it. With release 1.8.7, a wallet key makes extract and render paid once their free trial is used up. Search, news, search + read and screenshots stay on the free tier unless you also set AGENTSEARCH_MODE=paid.
Keep the key out of opencode.json. OpenCode replaces {env:NAME} in config values with that environment variable, so the file only holds a reference. Add a second server with the variables:
opencode mcp add agentsearch-paid \
--env 'AGENTSEARCH_WALLET_PRIVATE_KEY={env:AGENTSEARCH_WALLET_PRIVATE_KEY}' \
--env AGENTSEARCH_MODE=paid \
--env AGENTSEARCH_MAX_TOTAL_ATOMIC=50000 \
-- npx -y @agentsearchhq/agentsearch-mcp
Keep the single quotes so your shell doesn't touch {env:...}. In our test (OpenCode 2.4.1, no key set) it wrote the reference as plain text:
"agentsearch-paid": {
"type": "local",
"command": ["npx", "-y", "@agentsearchhq/agentsearch-mcp"],
"environment": {
"AGENTSEARCH_WALLET_PRIVATE_KEY": "{env:AGENTSEARCH_WALLET_PRIVATE_KEY}",
"AGENTSEARCH_MODE": "paid",
"AGENTSEARCH_MAX_TOTAL_ATOMIC": "50000"
}
}
Then set AGENTSEARCH_WALLET_PRIVATE_KEY in the shell that starts OpenCode, for example from your password manager. We didn't run paid calls in this test. Turn the free agentsearch server off ("disabled": true in OpenCode 2, "enabled": false in OpenCode 1) so the model doesn't see two copies of each tool, and never commit a real key to opencode.json.
Spend caps. The server checks these before it signs anything:
AGENTSEARCH_MAX_TOTAL_ATOMICcaps total spend per server session, in USDC atomic units (1000000 = $1.00). The default is $1.00; the example sets $0.05.AGENTSEARCH_MAX_PER_CALL_ATOMIClowers the per-call ceiling (the default ceiling is $0.020).
When a cap is reached, the tool returns a message saying nothing was signed instead of paying.
Troubleshooting
The server doesn't show up. Run opencode debug config to see which files OpenCode read. Check that the file is valid JSON (or JSONC) and that you're running OpenCode from the project folder. Logs are in ~/.local/share/opencode/log/ on Linux (opencode debug paths prints the folders on your machine).
npx: command not found or an engine error. The local server needs Node.js 20 or newer with npx on the PATH OpenCode sees. Or use the hosted server (Option B).
The first start times out. The first npx run downloads the package, and OpenCode 2 waits 30 seconds for a server to start by default. Run npx -y @agentsearchhq/agentsearch-mcp once in a terminal (it prints a "listening on stdio" line; press Ctrl+C), then try again. The MCP docs also show a timeout setting for slow servers.
OpenCode never calls the tool. Name it in the prompt ("use agentsearch to..."), and disable MCP servers you don't need so the search tool stands out.
Extract or Render says a wallet is needed. The free trial for the day is used up (5 extracts, 3 renders per IP), or you set AGENTSEARCH_FREE_TRIAL=0. Nothing was charged. Add a wallet server or wait for the next day.
Search says it needs payment. The 25 free searches for your IP are used up. Add a wallet and set AGENTSEARCH_MODE=paid, or call the direct x402 API from your own code.
FAQ
Do I need an API key to add web search to OpenCode?
No. The agentsearch MCP server (npx -y @agentsearchhq/agentsearch-mcp) needs no key, account or wallet. You get 25 free searches per IP, then pay per call.
Where is the OpenCode MCP config?
In opencode.json (or opencode.jsonc) under the mcp key: in your project folder for one project, or in ~/.config/opencode/opencode.json for every project. opencode mcp add writes the project file unless you add --global.
Does OpenCode support remote MCP servers?
Yes. Use "type": "remote" with a url, or run opencode mcp add <name> --url <url>. AgentSearch's hosted server at https://relay.agentsearchhq.com/mcp needs no headers and no sign-in.
Does this work with OpenCode 1?
Yes. We tested OpenCode 1.19.6 with the classic mcp.<name> config shape, and it connected and called the search tool. OpenCode 2 reads the same shape, and opencode mcp add in OpenCode 2 writes the newer mcp.servers shape.
How much do paid calls cost?
On the direct x402 API: search and news $0.003, extract $0.002, render $0.005, search + read $0.005 and screenshot $0.004 per call, in USDC on Base. You pay only after the free allowance is used up.
Is it safe to let OpenCode read web pages?
Treat web content as untrusted input. A page can contain text written to steer an AI, and OpenCode ran the search tools without asking in our test. Add an ask permission rule for the page tools when OpenCode can also run shell commands or edit files.
Get started
Run opencode mcp add agentsearch -- npx -y @agentsearchhq/agentsearch-mcp in your project (or paste the JSON into opencode.json), check it with opencode mcp list, then start opencode and ask about something that changed last week. No Node.js? Use the hosted remote MCP server instead. Using other tools too? See How to Add Free Web Search to Goose with MCP and How to Add Free Web Search to Claude Code with MCP. Setup for other clients is on the MCP page.
More from the blog
- How to Add Free Web Search to Goose with MCP (No API Key)
- How to Add Free Web Search to Zed with MCP (No API Key)
- How to Add Free Web Search to Claude Code with MCP (No API Key)
- How to Add Free Web Search to OpenAI Codex CLI with MCP (No API Key)
- How to Add Free Web Search to Google Gemini CLI with MCP (No API Key)
- Free Remote MCP Server for Web Search: Hosted, No Install, No API Key
Service pages: Web Search API · Web Extract API · Web Render API