poem's profile picture
poem

multi-search

Public

119 Downloads

README

multi-search

Online web search for local LLMs. Ships in two forms from a single codebase:

  • 🧩 An LM Studio plugin with a per-chat config panel (toggle search on/off, pick mode, tick engines).
  • πŸ”Œ A standalone MCP server you can drop into any MCP host's mcp.json (LM Studio, Claude Desktop, etc.).

Bundles 14 search engines and a parallel multi-engine mode that fans out one query, interleaves results round-robin, and dedupes by URL. Also exposes a dependency-free page reader so the model can fetch and read result URLs.

No browser, no Playwright, no API keys — just Node 22's built-in fetch and a small HTML→text extractor.


Tools exposed to the model

ToolWhat it does
list_search_enginesReturns available engine ids and the current mode/defaults.
web_searchRuns a search, filters junk (empty titles, redirect wrappers), dedupes by normalized URL, ranks by host trust + title/snippet query-overlap, returns the top K with a score (0–1) and host per result.
fetch_pageFetches one URL and returns its extracted main text. If you pass query, long pages are truncated query-aware β€” paragraphs containing query terms are kept instead of just the first N chars.
web_search_fullOne-stop: web_search + concurrently fetches the top N result pages with query-aware extraction. Use this instead of web_search + multiple fetch_page calls.
get_weatherCurrent conditions + 3-day forecast for any city / ZIP / airport code. Backed by wttr.in (no API key). Use this for weather questions instead of web_search β€” search snippets almost never contain actual temperatures.

All search responses include returned, dropped_as_noise, from_cache, and per_engine_counts for transparency. When the top result score is very low (< 0.35) or zero results survive filtering, an additional note field tells the model to rephrase or pick a more specific tool.

Result ranking & noise reduction

Every web_search / web_search_full response is post-processed:

  • Junk drop β€” empty titles, search-engine redirect wrappers (duckduckgo.com/l/?, google.com/url?, etc.), non-http URLs.
  • URL normalization β€” lowercase host, strip www., strip #fragment, drop utm_* / fbclid / ref / source / gclid tracking params, strip trailing /.
  • Dedupe β€” by normalized URL, keeping the higher-scoring instance.
  • Score = 0.45 Β· titleQueryOverlap + 0.30 Β· hostTrust + 0.20 Β· snippetQueryOverlap + 0.05 Β· snippetLengthBonus.
    • Host trust is a built-in map: wikipedia/arxiv β‰ˆ 0.9, .gov 0.85, .edu / github / stackoverflow β‰ˆ 0.8, reddit β‰ˆ 0.55, pinterest β‰ˆ 0.2, unknown 0.5.
  • Top-K β€” sorted by score, sliced to topK (default 8).
  • Snippet trim β€” cap each snippet to snippetMaxChars (default 240).

Turn on includeScoreBreakdown (per-chat setting / MULTI_SEARCH_SCORE_BREAKDOWN=1) to see per-result { host_trust, title_overlap, snippet_overlap, snippet_length_bonus }.

In-process cache

A tiny LRU+TTL cache (100 search entries, 50 web_search_full entries) deduplicates repeat calls within the same plugin session. Default TTL is 5 minutes. Set cacheTtlSec to 0 (or MULTI_SEARCH_CACHE_TTL=0) to disable. Responses include from_cache: true when served from cache.

Supported engines (14)

duckduckgo, brave, bing, qwant, ecosia, startpage, metager, wikipedia, arxiv, reddit, stackoverflow, github, google-scholar, devdocs

Most reliable: duckduckgo, brave, bing, wikipedia, arxiv, reddit, stackoverflow, github. Scraped engines (ecosia, startpage, etc.) can occasionally be rate-limited β€” the multi-engine mode tolerates this and just keeps whatever returned successfully.


Install

git clone https://github.com/potkolainen/LM-Multi-Online-Search-plugin.git
cd "Multi search"
npm install
npm run build

Requires Node 22+ (uses the built-in global fetch / AbortController).


Use as a standalone MCP server

After npm run build, point your MCP host at dist/mcp.js. Example mcp.json (LM Studio, Claude Desktop, etc.):

{
  "mcpServers": {
    "multi-search": {
      "command": "node",
      "args": ["/absolute/path/to/Multi search/dist/mcp.js"],
      "cwd": "/absolute/path/to/Multi search",
      "env": {
        "MULTI_SEARCH_MODE": "multi",
        "MULTI_SEARCH_MULTI_ENGINES": "duckduckgo,brave,bing,wikipedia",
        "MULTI_SEARCH_FETCH_TOP_N": "3",
        "MULTI_SEARCH_MAX_CONTENT": "10000"
      }
    }
  }
}

Environment variables

MCP has no settings UI, so the standalone server is configured purely via env vars:

VariableDefaultRangePurpose
MULTI_SEARCH_MODEmultisingle | multiSearch strategy.
MULTI_SEARCH_SINGLE_ENGINEduckduckgoany engine idEngine used in single mode.
MULTI_SEARCH_MULTI_ENGINESduckduckgo,brave,bing,wikipediacomma listEngines queried in multi mode.
MULTI_SEARCH_MAX_RESULTS51–20Raw results per engine cap.
MULTI_SEARCH_TOP_K81–25Final top-K returned after ranking.
MULTI_SEARCH_SNIPPET_MAX24080–2000Snippet length cap (chars).
MULTI_SEARCH_CACHE_TTL3000–3600 secSearch-cache TTL. 0 = disabled.
MULTI_SEARCH_SCORE_BREAKDOWN00/1Include per-result scoring breakdown for transparency.
MULTI_SEARCH_FETCH_TOP_N30–10Pages fetched by web_search_full.
MULTI_SEARCH_FETCH_CONCURRENCY31–8Parallel page fetches.
MULTI_SEARCH_REQUEST_TIMEOUT150001000–60000 msPer-engine HTTP timeout.
MULTI_SEARCH_PAGE_TIMEOUT100001000–60000 msPage-fetch timeout.
MULTI_SEARCH_MAX_CONTENT10000500–200000 charsExtracted page text cap.
MULTI_SEARCH_USER_AGENTChrome 120 UAstringUser-Agent for all HTTP requests.

Quick smoke test

printf '%s\n%s\n' \
  '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"x","version":"0"}}}' \
  '{"jsonrpc":"2.0","id":2,"method":"tools/list"}' \
| node dist/mcp.js

Should print two JSON-RPC responses on stdout and multi-search MCP server ready on stdio on stderr.


Use as an LM Studio plugin

npm install
lms dev          # hot-reload while developing
# or
lms push         # install into LM Studio

When loaded as a plugin you get a per-chat config panel with these fields:

FieldDefaultPurpose
searchEnabledβœ… onKill-switch. When off, no tools are exposed to the model at all.
modesinglesingle or multi. Only one web_search tool is exposed at a time, matching this mode.
singleEngineduckduckgoEngine used in single mode.
maxResultsPerEngine5Raw results-per-engine cap (1–20).
topK8Final number of best-scoring results returned after ranking (1–25).
snippetMaxChars240Snippet length cap to save context (80–2000).
cacheTtlSec300Search-cache TTL in seconds. 0 disables caching.
includeScoreBreakdownoffAttach per-result scoring breakdown for transparency / debugging.
fetchTopN3Pages fetched by web_search_full (0–10).
fetchConcurrency3Parallel page fetches (1–8).
Multi: <Engine> Γ— 14duckduckgo / brave / bing / wikipediaOne checkbox per engine β€” pick which to include in multi mode.

And global plugin settings (apply across all chats):

FieldDefaultPurpose
requestTimeoutMs15000Per-engine HTTP timeout.
pageFetchTimeoutMs10000Timeout for fetch_page / web_search_full page loads.
maxContentLength10000Hard cap on extracted page text length.
userAgentChrome 120 UAUser-Agent header.

How multi-engine mode works

  • Fan out the same query to every checked engine in parallel (Promise.all).
  • Round-robin interleave: take the 1st result from each engine, then 2nd from each, then 3rd…
  • Dedupe by URL (ignoring ?query and #fragment).
  • Tag each result with its source engine so the model knows where it came from.
  • Any engine that errors or times out returns [] β€” the rest still come through.

This gives broader topical coverage than a single engine and degrades gracefully when one engine breaks.

Page extraction

fetch_page and web_search_full use a small dependency-free extractor that:

  • strips <script>, <style>, <noscript>, <svg>, <iframe>, <form>, <nav>, <aside>, <footer>, <header>,
  • prefers <article> β†’ <main> β†’ largest <div> by visible text,
  • decodes HTML entities,
  • converts block-level tags to newlines (so <p>foo</p><p>bar</p> doesn't collapse to foobar),
  • collapses whitespace,
  • truncates to maxContentLength.

It is not a full Readability re-implementation β€” for pathological pages (heavy SPA, lazy-loaded content, Cloudflare challenges) it will return less than a browser-based scraper would. The trade-off is zero native deps and instant cold start.


Project layout

src/
  engines.ts          # 14 search engines + shared helpers (fetch with timeout, etc.)
  extract.ts          # HTML β†’ main-text extractor (with query-aware truncation)
  ranking.ts          # URL normalization, dedupe, host-trust scoring, top-K filter
  cache.ts            # Tiny in-process LRU + TTL cache
  weather.ts          # wttr.in client for the get_weather tool
  configSchematics.ts # LM Studio plugin per-chat + global config schema
  toolsProvider.ts    # LM Studio plugin tool registration
  index.ts            # LM Studio plugin entry point
  mcp.ts              # Standalone MCP stdio server entry point

Both distributions share engines.ts and extract.ts, so any new engine becomes available in both modes at once.

Scripts

CommandPurpose
npm run buildCompile TypeScript to dist/.
npm run devlms dev β€” run as a hot-reloading LM Studio plugin.
npm run pushlms push β€” install the plugin into LM Studio.
npm run start:mcpnode dist/mcp.js β€” run the MCP server on stdio.

Adding a new engine

  • Implement an EngineFn in src/engines.ts:
    async function myEngine(query: string, opts: EngineOptions): Promise<SearchResult[]> { … }
    
  • Register it in the ENGINES map.
  • Add a pretty label to ENGINE_LABELS in src/configSchematics.ts.
  • (Optional) Add it to DEFAULT_MULTI if you want it ticked by default.
  • npm run build. It now appears in both the plugin's checkbox list and the MCP server's list_search_engines output.

License

MIT