Claude MCP Web Search: Live Results for an Agent
To give a Claude agent live search results over MCP, add the Perceptlayer MCP server at https://perceptlayer.com/mcp with your API key, then let the agent find and call the Google Search endpoint through the search_endpoints, get_endpoint and call_endpoint tools. Each successful search call costs 1 credit and failed calls cost nothing. This tutorial wires it up in Claude Code and in a Python agent, then counts the credits per question.
What do you need before you start?
You need a Perceptlayer API key, the claude CLI or the Claude Agent SDK for Python, and an environment variable holding the key. Keys start with sk_live_. Every account gets 100 free credits after verifying an email address, with no credit card, so you can run everything below without paying. Get a free API key first, then export it.
export API_KEY="sk_live_..."
The same key authenticates plain HTTP calls with the X-API-Key header and the MCP server with an Authorization: Bearer header. Where headers aren't possible, the api_key query parameter also works. The authentication section of the docs is the place to read more about keys.
How does a Claude agent search the web over MCP?
The Model Context Protocol lets an agent discover and call tools on a remote server. Perceptlayer's server speaks Streamable HTTP, the protocol's standard transport for remote servers, and gives the agent access to a catalogue of 707 websites and 3,834 endpoints, all returning JSON.
The server's tools are search_endpoints, get_endpoint and call_endpoint. The AI agents (MCP) section of the docs covers the server, and the protocol site describes MCP itself.
Step 1: How do you add the MCP server to Claude Code?
Run one command. It registers the server under the name perceptlayer, using the HTTP transport and your key as a Bearer token. Claude Code stores the entry in its MCP configuration.
claude mcp add --transport http perceptlayer https://perceptlayer.com/mcp \
--header "Authorization: Bearer $API_KEY"
Confirm the server connected:
claude mcp list
You should see perceptlayer in the list. Inside a Claude Code session, the /mcp command shows the connection status of the server. If you want the entry scoped to a project instead of your user, the Claude Code MCP documentation lists the scope options.
Ask a question that needs live search
Start claude and ask something the model can't know from training, such as: "Use Perceptlayer to search Google for the latest Claude Code release notes and list the top five result titles with their URLs."
The agent needs access to three tools to reach the Google Search endpoint: search_endpoints, get_endpoint and call_endpoint. If your permission settings block any of them, the call will fail, so allow all three.
Step 2: Which Google Search endpoint should the agent use?
The Google Search API has 7 endpoints, and every one costs 1 credit per successful call. For an agent answering open questions, start with /v1/google-search/search, which takes a required query and optional parameters for country (gl), language (hl), result count and paging. The others fit narrower jobs, so tell the agent which to prefer if you care.
| Endpoint | Required | Use it when |
|---|---|---|
/v1/google-search/search |
query |
General web search with the full parameter set |
/v1/google-search/search-light |
query |
A smaller parameter set, with num for result count |
/v1/google-search/search-ai-overview |
query |
You want the AI Overview for a query |
/v1/google-search/google-ai-mode-search |
q |
You want an AI Mode answer, with follow_up_token for follow-ups |
/v1/google-search/search-light-autocomplete |
query |
Query suggestions, with hl and limit |
Note that google-ai-mode-search uses q where the others use query. A hard-coded script needs to get that right. The Google Search API page lists all seven, including search-advanced and search-advanced-place, and the search engines hub shows related sources.
When is Claude's built-in web search enough?
Often it is. If you want a quick, prose answer to an occasional question and don't need to control how the search runs, Claude's own web search tool may be all you need, and you should start there. Check Anthropic's web search tool documentation for how to enable it on your surface and plan. A structured endpoint earns its place when the agent needs fields it can rely on. /v1/google-search/search takes gl and hl to fix country and language, amount to set the result count, and returns separate fields for organic results, related questions and related searches. Two sibling endpoints return an AI Overview or an AI Mode answer for a query. The cost is a key, a credit per call and a prompt that handles errors. If your agent only reads the answer and never parses it, that overhead may not pay off. For a longer comparison of tool-calling approaches, read MCP vs function calling for live web data.
Step 3: How do you check the endpoint outside the agent?
Call the endpoint directly with cURL before trusting an agent with it. If the request works from your terminal, any later failure is in the agent's prompt or tool use, not in the data call. The -i flag prints the response headers so you can see the status.
curl -i "https://api.perceptlayer.com/v1/google-search/search?query=claude%20code%20release%20notes" \
-H "X-API-Key: $API_KEY"
The endpoint returns the search results as JSON. This excerpt is from a recorded response to a different request, query=best restaurants in Berlin&hl=en&safe=off, trimmed with …:
{
"organic_results": [
{
"position": 1,
"title": "The Best Restaurants in Berlin - Food Guide & Map",
"link": "https://andershusa.com/best-restaurants-berlin-germany-guide/",
"snippet": "Dec 3, 2025 — Tim Raue is the most internationally renowned restaurant in Berlin. It holds two Michelin stars, has been frequently ranked on The World's 50 ..."
},
{
"position": 2,
"title": "Restaurants - Berlin",
"link": "https://guide.michelin.com/us/en/berlin-region/berlin/restaurants",
"snippet": "Berlin and surroundings: 1-48 of 79 restaurants · POTS · Rutz · GOLVET · Bandol sur mer · Nobelhart & Schmutzig · Oukan · 136 · FACIL."
}
],
"related_questions": [
{ "question": "What is the coolest restaurant in Berlin?", "next_page_token": "…" },
{ "question": "What is famous to eat in Berlin?", "next_page_token": "…" }
]
}
Each item in organic_results has a position, a title, a link and a snippet, which is what an agent needs to cite a page. related_questions holds follow-up questions the agent can use to refine a search. The full response has more fields, including related_searches and local_results. To see a real response for your own query before you wire up the agent, run it in the playground on the Google Search API page; the Search endpoint page lists every parameter.
Break the call on purpose to see the failure shape. Send a bad key and you get HTTP 401 with a body like {"error": {"code": "invalid_api_key", ...}}, and the response carries X-Credits-Used: 0. The errors section of the docs is the reference for error responses.
Step 4: How do you build a Python agent that uses the server?
Use the Claude Agent SDK, point mcp_servers at the Perceptlayer URL, and allow the three tools by name. The script below asks one question, prints the answer, and counts how many times the agent called call_endpoint. The script counts only call_endpoint calls. search_endpoints and get_endpoint only look up the catalogue and cost nothing, so leaving them out doesn't hide any spend. The count includes failed calls, which are free, so it can be higher than the number of billed calls. For the exact figure, read the credits used and remaining that each call_endpoint result reports.
Install the SDK with pip install claude-agent-sdk, then save this as agent.py:
import asyncio
import os
from claude_agent_sdk import (
AssistantMessage,
ClaudeAgentOptions,
TextBlock,
ToolUseBlock,
query,
)
QUESTION = "What changed in the latest Claude Code release? Cite the result URLs you used."
SYSTEM_PROMPT = (
"You answer questions with live web search. "
"Use the perceptlayer MCP tools to find and call a Google Search endpoint. "
"Make at most 3 search calls per question. Cite the URLs you relied on."
)
OPTIONS = ClaudeAgentOptions(
system_prompt=SYSTEM_PROMPT,
mcp_servers={
"perceptlayer": {
"type": "http",
"url": "https://perceptlayer.com/mcp",
"headers": {"Authorization": f"Bearer {os.environ['API_KEY']}"},
}
},
allowed_tools=[
"mcp__perceptlayer__search_endpoints",
"mcp__perceptlayer__get_endpoint",
"mcp__perceptlayer__call_endpoint",
],
)
async def main():
data_calls = 0
async for message in query(prompt=QUESTION, options=OPTIONS):
if not isinstance(message, AssistantMessage):
continue
for block in message.content:
if isinstance(block, ToolUseBlock) and block.name.endswith("call_endpoint"):
data_calls += 1
elif isinstance(block, TextBlock):
print(block.text)
print(f"\ndata calls: {data_calls}")
asyncio.run(main())
The Agent SDK documentation covers the options used above.
Step 5: What does the script print?
Run it with python agent.py. The agent's answer text prints as it arrives, followed by one summary line in this format, where <n> is a number from your run:
data calls: <n>
Compare that number with the cap in the system prompt. The credits used and remaining come from the call_endpoint results themselves, which report both. If the count is higher than the cap, tighten the prompt.
Why cap the number of search calls?
Each successful search call costs 1 credit, so the number of calls sets the credit cost of a question. The prompt line "at most 3 search calls per question" asks the agent to keep that spend to 3 credits, and the counter shows whether it does. The model can ignore the instruction, so treat the cap as a guardrail, not a guarantee, and check the printed count while you tune the prompt. For a hard limit, enforce it in your own code, for example by stopping the run after the third call_endpoint call.
What does each question cost?
A successful call_endpoint call to a Google Search endpoint costs 1 credit, so an agent that searches twice spends 2 credits. The figures below count only those search calls; search_endpoints and get_endpoint cost nothing, so they add no credits. The free tier of 100 credits, granted once on signup, covers 100 search calls, and purchased credits last 12 months with no subscription and no seats. The table below counts Perceptlayer credits only. Claude model tokens are billed separately by Anthropic, so the real cost of a question is higher than the credit figure.
| Workload | Calls | Credits | Covered by |
|---|---|---|---|
| 100 questions × 1 search each | 100 | 100 | Free credits (100 on signup) |
| 33 questions × 3 searches each | 99 | 99 | Free credits (100 on signup) |
| 10,000 questions × 1 search each | 10,000 | 10,000 | Starter pack (10,000 credits) |
| 5,000 questions × 3 searches each | 15,000 | 15,000 | Build pack (50,000 credits) |
The third row is 10,000 calls × 1 credit = 10,000 credits, exactly the Starter pack's 10,000. The last row is 5,000 questions × 3 calls × 1 credit = 15,000 credits, within the Build pack's 50,000. The pricing page shows what each pack costs, and the credits section of the docs covers credits.
Because failed calls are free, a rate-limited or erroring call doesn't add to the total. Only a successful response debits credits.
What happens when a call fails?
A failed call returns an HTTP status and a JSON body with error.code, error.message and error.request_id, and it costs nothing. Give the agent a rule for each case in the system prompt so it knows whether to retry, change the query, or stop, and doesn't loop.
| Code | Status | What the agent should do |
|---|---|---|
invalid_parameters |
422 | Check the parameters against the endpoint page, fix, retry once |
rate_limited |
429 | Wait for the seconds in the Retry-After header, then retry; see rate limits |
source_error |
502 | Retry once, then report that search is unavailable |
temporarily_unavailable |
503 | Wait for the seconds in the Retry-After header, then retry |
insufficient_credits |
402 | Stop and tell the user to top up |
invalid_api_key |
401 | Stop; the key is wrong or revoked |
restricted_endpoint |
403 | Stop; the endpoint needs the restricted-endpoint terms accepted in the dashboard |
Add a sentence such as "If a tool call fails with insufficient_credits or invalid_api_key, stop and say so" to SYSTEM_PROMPT. Retrying a returned error is safe for your balance because failures aren't billed. A timeout is the exception: if the reply was lost, the request may have succeeded and been billed, and requests have no idempotency key. Retry Web API Calls Without Paying Twice covers how to handle that.
Next step: point the same server at more sources
The server isn't limited to Google Search. The same key and the same three tools reach the rest of the catalogue, so the agent can move from a search result to a listing, a review page or a price without a new integration. Some endpoints, covering social, personal and SEO data, need you to accept the restricted-endpoint terms in the dashboard first.
Add the server with the command in step 1, ask your agent a question that needs live data, and check the credit count it prints. For more on using the server with agents, see the MCP docs, and for related reading, see MCP server for web scraping, capping web data spend for agents and Google search results as JSON. More agent tutorials are in the AI agents category.
APIs in this post
Frequently asked questions
How much does a Claude MCP web search cost with Perceptlayer?
A successful call to a Google Search endpoint costs 1 credit. The free tier gives 100 credits on signup, and the smallest pack is 10,000 credits, enough for 10,000 search calls at 1 credit each. See pricing for what credits cost. Failed calls cost nothing and return X-Credits-Used: 0, so errors never add to your bill.
Do I need the Claude Agent SDK, or does Claude Code work on its own?
Claude Code works on its own. The claude mcp add command registers the server, and you ask questions in the terminal. The Agent SDK is for embedding the same behaviour in your own application, where you want to control the prompt, cap the number of searches and print the credits used per question.
Can I use the key in a header other than Authorization?
On plain HTTP calls, send the key in X-API-Key, or in the api_key query parameter where headers aren't possible. The MCP server uses an Authorization: Bearer header in the Claude Code command shown above. Keys start with sk_live_, and the authentication section of the docs has more on keys.
What does the agent do when search is rate limited?
A rate-limited call returns HTTP 429 with the code rate_limited, and it isn't billed. The response carries a Retry-After header with the seconds to wait, and a 503 does too. Free accounts get 1 request a second, shared by all the account's keys. Put a retry rule in the system prompt so the agent waits that long and tries again instead of looping.
What are the data-use terms for search results?
Data is collected from publicly available sources and returned as found at the time of the call. How you use results is your responsibility, so check the terms that apply to your use case. Social, personal and SEO endpoints need you to accept the restricted-endpoint terms, and you shouldn't use personal data to contact people without a lawful basis.