Skip to main content
Glama

MCP WebSearch

MCP server for Claude Code: web search via Perplexity Sonar and image generation — all with one OpenRouter key.

Built for one task: not letting the agent accidentally overspend. The expensive search model is not the default, and image generation has a separate tool to estimate the cost before calling.

Installation

git clone git@github.com:DrSeedon/mcp-websearch.git ~/.claude/mcp-servers/websearch
cd ~/.claude/mcp-servers/websearch
npm install
cp .env.example .env   # и вписать свой ключ

Registration in Claude Code:

claude mcp add websearch node ~/.claude/mcp-servers/websearch/index.js \
  -e OPENROUTER_API_KEY=sk-or-v1-...

Requires Node 18+ (uses native fetch and ESM).

Related MCP server: sysauto Ask MCP Server

Environment variables

Variable

Required

Purpose

OPENROUTER_API_KEY

yes

OpenRouter key. Checked at startup

HTTPS_PROXY / HTTP_PROXY

no

Proxy, if direct access to openrouter.ai is blocked

The key is only read from the environment — it is not and must not be in the code.

Tools

Web search via Perplexity Sonar. Returns the answer, sources, and request cost.

Model

Cost

When

sonar

~$0.006

Default. Facts, documentation, regular research

sonar-pro-search

~$0.03

Only if sonar failed on THE SAME question

There are no other search models — the list is hardcoded.

Why it matters: the price difference is fivefold. If the expensive model were the default, the agent would call it without thinking. Tested on a live setup: 171 out of 425 requests went through the expensive tier simply because the model was not specified explicitly.

generate_image

Image generation. Supports reference images as input and aspect ratios from 21:9 to 9:16.

Model

Purpose

nano-banana

Default, good quality

nano-banana-lite

Budget option

riverflow-fast / riverflow-pro / riverflow-max

Alternative engine, from fast to high quality

seedream

Another style option

generate_image_cost

Estimates the generation cost before the call. Needed so the model choice is deliberate, not "just pick the first one from the list".

Logs

requests.log (in .gitignore) — JSONL, one line per call: [iso] tool: {json}.

  • search — request, full response, sources, model, tokens, cost

  • generate_image — prompt, save paths, size, references; base64 is not written to the log

  • next to the image, a .json file with the same prompt and metadata is saved in generated/

What is not committed

.env, requests.log, generated/ (archive of generated images), node_modules/. Logs and images contain request history — that is private data and has no place in the repository.

Related MCP Connectors

Related MCP Servers