Claude Code reads and writes your code, but to check a library's latest release notes or read an API reference, it needs tools that reach the web. An MCP server gives it those tools. This guide shows how to add web search to Claude Code with a single claude mcp add command, what Claude Code can do with it, and keeps its spending under a limit you set.
What an MCP server adds to Claude Code
MCP, the Model Context Protocol, is a standard way for an agent to call tools that live on a server. Claude Code connects to the server, reads the list of tools it offers, and decides when to call them while it works on your request.
The server at https://lovelyrouter.com/mcp speaks Streamable HTTP and authenticates with Authorization: Bearer lr-..., the same key as the REST API. Each call is billed from your prepaid balance like the same call over REST:
cost $0.0009 per search or page. A search with no results, or a page that can't be read, costs nothing.
charge a per-call fee, a per-result fee or both, capped by max_results.
charges per step: $0.006 in fast mode, $0.012 in accurate mode.
are free.
There's no subscription, and the server works whichever model endpoint Claude Code itself uses.
Connect it
Create a key with a spend limit
Create a key in API keys, give it a spend limit, and export it in your shell as
LOVELY_API_KEY.Add the server
Shellclaude mcp add --transport http lovely-tools https://lovelyrouter.com/mcp \ --header "Authorization: Bearer $LOVELY_API_KEY"This adds it to the current project only. Add
--scope userto use it in every project.Check that it connects
Run
claude mcp list. Inside a session,/mcpshows the server's status and its tools.
To share the server with your team, commit a .mcp.json at the project root instead. Claude Code expands ${LOVELY_API_KEY} from each person's environment, so the key stays out of the file:
{
"mcpServers": {
"lovely-tools": {
"type": "http",
"url": "https://lovelyrouter.com/mcp",
"headers": { "Authorization": "Bearer ${LOVELY_API_KEY}" }
}
}
}You can also test the server without Claude Code. This lists its tools:
curl https://lovelyrouter.com/mcp \
-H "Authorization: Bearer $LOVELY_API_KEY" \
-H "content-type: application/json" \
-d '{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}'The tools Claude Code gets
| Group | Tools | What Claude Code uses them for |
|---|---|---|
| Search and read | web_search, web_fetch | Search the web for up to 50 results, each with a summary written for a model, or read one page as clean Markdown. |
| Data catalog | suggest_tools, search_tools, get_tool, run_tool, get_run | Plan a task with costs, find a tool, read its input schema and price (all free), then run it and read the results. |
| Browser agent | browser_run, browser_status, browser_reply, browser_takeover | Work through pages it has to click, type or log in to. |
| Images | generate_image, get_image | Make an image from a description. |
The server tells Claude Code to use web_search and web_fetch for anything it only needs to read, and to keep the browser agent for pages it has to interact with. web_search accepts operators in the query: site:, -site:, "exact phrase", -word, lang:, after: and before:. web_fetch returns long pages in parts of about 12,000 characters, and reading on is free. Every argument and return format is in the MCP server docs.
Prompts to try
- "Find the release notes for the latest FastAPI version, read them, and list the changes that affect our routes." Claude Code searches with
web_search, then reads the notes withweb_fetch. - "Search site:github.com for open issues about this error message, after:2026-06-01, and tell me if there's a known fix." Operators narrow the search to recent issues.
- "Read https://docs.example.com/api/authentication and write a client for it in src/client.py."
web_fetchturns the page into Markdown Claude Code can work from. - "Get the transcript of this YouTube talk and add a summary with timestamps to NOTES.md." Claude Code plans with
suggest_toolsand runs the YouTube transcript tool withrun_tool. - "Sign up on our public staging site with a test address and tell me what the confirmation page says."
browser_rundoes it in a cloud browser.
Keep the cost under control
The limit covers model requests, data tools and browser runs. See API keys.
Add a line to CLAUDE.md such as: "Use web_search and web_fetch to look things up. Always set max_results on run_tool, check the price with get_tool first, and ask me before any run with more than 50 results or any browser run."
Claude Code asks before it calls an MCP tool. Allow the cheap reads with rules such as mcp__lovely-tools__web_search and mcp__lovely-tools__web_fetch, and keep approving run_tool and browser_run by hand, so you see each run before it starts.
A browser run's hold is based on max_steps times the step price, and max_steps defaults to 50. Ask for a lower max_steps for short tasks.
Today's prices for the tools Claude Code calls most:
搜索网页:最多 50 条结果,包含标题、URL、日期、站点、简短摘要和供模型阅读的长摘要(需要时可附带网页正文)。支持运算符:site:、-site:、"精确短语"、-词、lang:、after:、before:。
把任意公开网页读取为干净的 Markdown:标题和正文,不含导航和广告。适用于已知 URL 的单个页面。
Give it a goal and a start page; an AI agent drives a real browser to do it: navigate, fill forms, log in with saved secrets, ask you for codes, hand over for CAPTCHAs, wait for your approval before purchases, and return structured JSON in your schema. For tasks that need interaction; to just read a page, use Read a web page (web-fetch). $0.006 per step in fast mode, $0.012 in accurate mode (looks at screenshots when unsure, can run read-only code to read data). Each step includes 1 minute; time beyond that (e.g. waiting for your approval) costs $0.005/min. Full API: /v1/browser.
Every run and its charge is listed under Tools in your dashboard. See pricing for the rest.
Troubleshooting the connection
| Symptom | Fix |
|---|---|
claude mcp list says the server failed to connect | Check the URL is https://lovelyrouter.com/mcp and that you passed --transport http. The cURL test above shows whether the server answers. |
suggest_tools works, but run_tool returns an authentication error | The key didn't reach the server. Your shell filled in $LOVELY_API_KEY when you ran claude mcp add, so if it was empty the header holds no key. Run claude mcp remove lovely-tools, export the key, and add the server again. With .mcp.json, export the variable in the shell that starts claude. |
| The server is missing in another project | It was added to one project only. Add it again with --scope user. |
A .mcp.json server doesn't appear | Claude Code asks before it uses servers from a project's .mcp.json. Approve it when asked, or check /mcp. |
402 from a tool | Your balance or the key's spend limit can't cover the run's maximum cost. Lower max_results, top up, or raise the limit. |
429 from a tool | Ten runs are already in progress on your account. Wait for one to finish. |
Still running. Call get_run with this run id | Normal for runs over 50 seconds: Claude Code calls get_run to wait for the results. |
| The browser agent can't open your local app | It runs in the cloud and can't reach localhost or private addresses. Use a public URL. |
Frequently asked questions
Do I have to run Claude Code on this API to use the MCP server?+
No. The MCP server is separate from the model endpoint, so it works with any Claude Code setup. To run Claude Code's models on the same key and balance as well, set the base URL and key as described in the Claude Code integration docs.
How much does a web search from Claude Code cost?+
Each web_search call costs $0.0009, whether it returns 10 or 50 results, and a search with no results costs nothing. Reading a page with web_fetch costs the same per page.
When does Claude Code use the browser agent instead of web_fetch?+
The server tells Claude Code to use web_fetch for pages it only needs to read, and the browser agent for pages it has to click, type or log in to. web_fetch is faster and cheaper.
Can I use the same server in Cursor or Claude Desktop?+
Yes. Cursor takes the URL and header in its mcp.json, and Claude Desktop connects through the mcp-remote bridge. Any client that supports remote MCP servers over Streamable HTTP works with the same key.
How do I stop Claude Code from overspending?+
Give it its own API key with a spend limit, tell it in CLAUDE.md to set max_results and ask before large runs, and keep paid tools behind Claude Code's permission prompt. A run that could take the key past its limit is refused before anything is charged.
Next, see the web search API to call search from your own code, AI coding agents to run Claude Code itself on a pay-as-you-go key, and Claude Code setup for base URL, models and caching. The MCP server page covers the other clients.