Labsco
gabrimatic logo

MCP Web Search Tool

โ˜… 15

from gabrimatic

A server for real-time web search using pluggable providers, powered by the Brave Search API.

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedAccount requiredNeeds API keys

MCP Web Search Tool

An MCP server that gives an assistant live web search, full-page reading, and source citations. Stdio transport, pluggable providers, no scraper dependencies.

Claude Desktop Example

CI License: MIT Node

Quick start ยท Tools ยท Configuration ยท Clients ยท Security ยท Changelog


Overview

Five tools: web_search, news_search, image_search, fetch_url, list_providers. Search returns ranked summaries with stable ids; fetch_url reads the page behind any id. Brave Search is the primary provider; DuckDuckGo runs without a key as a fallback.

Tools

Each tool returns two content blocks: a Markdown rendering for the model and a fenced JSON block with the structured payload. Errors come back as isError: true content with an actionable message; only unknown-tool calls throw a protocol error.

Live web search. Use first for current, source-backed answers.

ParameterTypeDescription
search_termstring, requiredQuery string.
providerenum"brave search" or "duckduckgo". Defaults to Brave when a key is set, otherwise DuckDuckGo.
countint (1โ€“20)Number of results. Default 10.
offsetintPagination offset (web only).
cursorstringOpaque cursor from a previous response.
freshnessstringpd (24h), pw (week), pm (month), py (year), or YYYY-MM-DDtoYYYY-MM-DD.
countrystringISO country code.
search_langstringUI language, e.g. en.
safesearchenumoff, moderate, strict.
include_domainsstring[]Restrict results to these hosts.
exclude_domainsstring[]Drop results from these hosts (hostname-suffix match).

Recent news with source name and publish date. Brave only.

Image results with thumbnails. Brave only.

fetch_url

Reads a search result or arbitrary http(s) URL. Pass a result id from a previous search (preferred) or a full URL.

ParameterTypeDescription
id_or_urlstringA result id (e.g. r_a1b2c3d4e5f6) or a full http(s) URL.
urlstringDeprecated alias for id_or_url.
max_charsint (200โ€“200 000)Soft cap on returned characters. Default 8000.
cursorstringCursor from a previous response to continue reading.

Returns the page title, readable text (scripts, styles, nav, footer, and aside stripped), the first 25 outbound links, HTTP status, content-type, byte length, and a nextCursor when truncated.

Refuses non-http(s) schemes and any host that resolves to a private, loopback, link-local, multicast, or IPv4-mapped IPv6 private address. Details: SECURITY.md.

list_providers

Returns the registered providers and the current default. Call this once if you are unsure whether news_search or image_search are available in this session.


Project layout

src/
โ”œโ”€โ”€ index.ts                    MCP server: tool registry, dispatch, rendering
โ”œโ”€โ”€ config.ts                   env loader, validation, defaults
โ”œโ”€โ”€ providers/
โ”‚   โ”œโ”€โ”€ SearchProvider.ts       abstract contract and shared types
โ”‚   โ”œโ”€โ”€ SearchProviderFactory   registry and default selection
โ”‚   โ”œโ”€โ”€ BraveSearchProvider     web/news/images via Brave API
โ”‚   โ””โ”€โ”€ DuckDuckGoProvider      keyless HTML-lite fallback
โ”œโ”€โ”€ services/
โ”‚   โ”œโ”€โ”€ SearchService.ts        provider dispatch, LRU+TTL cache
โ”‚   โ””โ”€โ”€ FetchService.ts         safe URL fetch, readable extraction
โ””โ”€โ”€ utils/
    โ”œโ”€โ”€ http.ts                 native fetch, retry/backoff/timeout
    โ”œโ”€โ”€ html.ts                 zero-dep HTML to text + links
    โ”œโ”€โ”€ cache.ts                LRU+TTL cache
    โ””โ”€โ”€ ids.ts                  stable result-id minting and resolution
tests/                          vitest suite

Add a provider

import { SearchProvider, SearchResponse, SearchOptions } from './SearchProvider.js';

export class MyProvider extends SearchProvider {
  getName() { return 'My Provider'; }
  override requiresApiKey() { return true; }
  async search(query: string, _opts: SearchOptions = {}): Promise<SearchResponse> {
    const out = this.emptyResponse(query, 'web');
    out.results = mapped; // shape: SearchResult[]
    return out;
  }
}

Register it in SearchProviderFactory.setupDefaults. Result ids are minted automatically when you call mintResultId(url) on each entry.


Development

npm run dev          # tsx watch mode
npm test             # vitest (23 tests)
npm run lint
npm run format
npm run build

CI runs on Node 20, 22, and 24, plus a Docker image build. Tests cover the LRU+TTL cache, HTML extractor, DuckDuckGo parser, search-service caching, HTTP retry/backoff, SSRF guard, domain match, and the result-id resolver.


Example prompts

  • "What are analysts saying about the MVP race after tonight's NBA games?"
  • "Summarise the top three results for RAG benchmarks 2025 and pull the abstract from the first paper."
  • "Find images of the Webb telescope's latest deep field, then open the NASA page and quote the caption."
  • "What's the weather in Berlin right now?"

Developer

By Soroush Yousefpour

ยฉ All rights reserved.

YouTube Video

A short demo of MCP Web Search Tool with Claude:

Claude + MCP Web Search โ€“ Live Demo

Medium Article

Background on the project and how it works:

Deep Dive into MCP Web Search Tool

Support

Buy Me A Book