web-search-mcp

web-search-mcp

MCP server that enables live web search via Gemini's built-in grounding, returning synthesized answers with source citations through a single web_search tool.

Category
访问服务器

README

web-search-mcp

An MCP server that gives IBM BOB live web search via Gemini's built-in grounding, registered as an upstream on the LiteLLM MCP Gateway.

BOB  ──►  LiteLLM proxy (MCP Gateway)  ──►  this server  ──►  LiteLLM proxy  ──►  Gemini (grounding)

LiteLLM connects to this server as an MCP client and re-exposes its tool at LiteLLM's own /mcp endpoint, so BOB gains search through a config entry rather than a code change.

Instead of returning raw search results, the tool calls a Gemini model through the LiteLLM proxy with the googleSearchRetrieval grounding tool. Gemini searches the web internally and returns a synthesised answer with source citations.

One tool is exposed:

Tool Arguments Returns
web_search query {query, answer, sources[{title, url}]}

1. Credentials

Three values are required; the server refuses to start without them.

  1. Gemini API key — from aistudio.google.comGet API key (starts with AIza). Set in your LiteLLM config as GEMINI_API_KEY. → used by LiteLLM, not this server directly.

  2. LiteLLM API key — the master key set in your LiteLLM proxy config. → LITELLM_API_KEY

  3. MCP auth token — a shared secret you generate yourself:

    python -c "import secrets; print(secrets.token_urlsafe(32))"
    

    MCP_AUTH_TOKEN (this server) and WEB_SEARCH_MCP_TOKEN (LiteLLM env)

2. Run it locally

cp .env.example .env   # fill in LITELLM_BASE_URL, LITELLM_API_KEY, MCP_AUTH_TOKEN
uv sync
uv run web-search-mcp

In a second terminal, start the LiteLLM proxy (run from the project root):

export GEMINI_API_KEY=AIzaSy...
export WEB_SEARCH_MCP_TOKEN=<same value as MCP_AUTH_TOKEN>
uvx --from 'litellm[proxy]==1.94.1' litellm --config litellm/config.example.yaml

Verify the MCP server:

curl -s localhost:8000/healthz   # {"status":"ok"} -- no auth needed
curl -i localhost:8000/mcp       # 401, because no token was sent

Then inspect the tool interactively:

npx @modelcontextprotocol/inspector

Connect with transport Streamable HTTP to http://127.0.0.1:8000/mcp, add header Authorization: Bearer <MCP_AUTH_TOKEN>, then call web_search from the Tools tab.

3. Register with LiteLLM

Merge the mcp_servers block from litellm/config.example.yaml into your LiteLLM config:

mcp_servers:
  web_search:
    url: "https://your-host/mcp"
    transport: http
    auth_type: bearer_token
    auth_value: os.environ/WEB_SEARCH_MCP_TOKEN
    allowed_tools: ["web_search"]

web_search should appear in LiteLLM's tool list (UI → MCP Servers, or through the proxy's /mcp endpoint). Then ask BOB something that requires current information and check that it calls the tool and cites URLs.

4. Deploy

docker build -t web-search-mcp .
docker run -p 8000:8000 --env-file .env web-search-mcp

The image is platform-agnostic — Code Engine, OpenShift, Kubernetes, Cloud Run. It binds 0.0.0.0 and honours an injected PORT. Point /healthz at your platform's liveness probe; it is intentionally unauthenticated so probes work without a token.

Supply LITELLM_BASE_URL, LITELLM_API_KEY, and MCP_AUTH_TOKEN as platform secrets, never baked into the image.

Layout

src/web_search_mcp/
  config.py         environment settings; fails fast when required values are missing
  gemini_client.py  LiteLLM/Gemini grounding client -- knows Gemini, not MCP
  cache.py          TTL/LRU cache to avoid redundant Gemini calls
  server.py         MCPServer, the web_search tool, /healthz, ASGI assembly
  auth.py           bearer-token ASGI middleware
  __main__.py       uvicorn entrypoint

Run the tests (fully mocked — no network, no API calls):

uv run pytest

Notes for whoever maintains this

  • Gemini grounding returns an answer, not a list of results. The tool response shape is {answer, sources} rather than {results[]}. Bob reads the answer and cites the source URLs directly.
  • sources may be empty. Gemini sometimes omits grounding citations even when it used search internally. This is not an error.
  • Error messages tell the model whether retrying can help. A rate limit says wait; a bad API key says an operator must intervene; a proxy timeout says retry shortly.
  • Auth middleware is pure ASGI, not Starlette's BaseHTTPMiddleware, because the MCP endpoint streams and BaseHTTPMiddleware buffers.
  • streamable_http_app() is used directly, not mounted. It already serves at /mcp and runs its own session-manager lifespan; mounting it under /mcp would nest the path to /mcp/mcp and drop that lifespan.
  • LiteLLM version: the proxy has a known incompatibility with mcp>=2.0 so it cannot be installed in the same venv as this server. Use uvx --from 'litellm[proxy]==1.94.1' to run it in isolation. Version 1.95.0 has a FastAPI import bug; stay on 1.94.1 until that is resolved upstream.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选