Skip to main content
Glama

search-router

One search tool and one read tool for an agent, with many free search backends behind them.

  • Queries go to a source that is strong for their type: papers to arXiv, OpenAlex and Semantic Scholar; code to GitHub and the Go package index; error messages to Stack Overflow and GitHub issues; library documentation to Context7; discussions to Hacker News; Chinese queries to Baidu. Everything else goes to the best general web index that has allowance left.

  • Results come back fast: connections stay warm, a backend slower than its own usual gets a second one started beside it, and a specialist that often comes back empty starts beside a general backend from the beginning.

  • A free allowance running out does not stop a search: a ledger records what each backend has spent, puts exhausted or throttled backends on a cooldown, and the next one is asked.

  • What strangers wrote is screened before an agent sees it: invisible characters, hidden markup, spam and copy farms are removed, and text that tries to instruct an AI agent is neutralized and reported.

  • The answer is small: an agent gets titles, links, short snippets and which backends were asked; the full trace is there when it asks for it.

  • Every answer says which backends were asked and how each ended, so "not found" is never stronger than the evidence.

It works with no API key. Keys add backends, raise allowances and turn on the decision model.

Status: v2, a local trial. SPEC.md is the contract and the place to start reading.

Run it

Needs Bun 1.4 or later.

bun install
bun test
bin/search-router search "request hedging grpc"
bin/search-router search "TypeError: Cannot read properties of undefined (reading 'map')" --json
bin/search-router search "retrieval augmented generation survey" --verbose
bin/search-router read https://example.com
bin/search-router read https://example.com --max-chars 5000   # 200 to 200,000, default 20,000
bin/search-router doctor
bin/search-router auth                                        # the key page, in the browser

--json prints the agent view on one line; --verbose prints the full response (timings, classification, every call, the decision trace), as JSON with --json. --no-cache answers afresh instead of from the answer cache.

Install the command

Link the launcher into a directory on your PATH, then call search-router from anywhere:

ln -s "$(pwd)/bin/search-router" ~/.local/bin/search-router

The CLI runs from source, with no build step. The launcher finds the repository through the link and runs bun run src/cli.ts with your arguments. bun run src/cli.ts <command> does the same and can stand in for search-router <command> in every example here. bun is found on PATH, then in /opt/homebrew/bin and ~/.bun/bin.

Related MCP server: gander

Use it from an agent

The MCP server speaks stdio and offers two tools, search and read. In a client that reads .mcp.json:

{
  "mcpServers": {
    "search-router": {
      "command": "bun",
      "args": ["run", "/path/to/search-router/src/server/main.ts"]
    }
  }
}

Both tool definitions together are under 1,600 characters, since a client sends them in every session. A search result is the agent view: the verdict, hits with title, URL, a snippet cut to 320 characters and a date when known, which backends were asked and how each ended, the backends skipped when nothing was found, and warnings. A read gives the page text, marked when it is only an excerpt or was cut at max_chars (a whole number from 200 to 200,000, default 20,000). Either tool takes verbose: true for the full response.

The same search within five minutes is answered from the answer cache and marked cached; only answered searches and pages read are kept.

Background process

A new CLI process would open a fresh connection to every service on each search (1.1 to 1.4 s for the first request on a connection, 0.2 s after that). So search and read are answered by a small background process that keeps connections warm. You do not start it: the first search or read answers on its own and starts one for the next call, and later calls use it. It listens on 127.0.0.1 only, on a port the system picks, and every request carries a random token kept in $SEARCH_ROUTER_HOME/daemon-<fingerprint>.json (mode 0600). It leaves by itself after 30 minutes without a request (SEARCH_ROUTER_DAEMON_IDLE_MIN changes that). Callers whose proxy variables, key variables or settings differ get separate processes, and a change in the source or in the Bun version replaces the process on the next call. A process makes network requests for every caller with the same fingerprint, including one that could not reach the network itself (a sandboxed caller, for instance), but only to the router's own services.

bin/search-router daemon status   # pid, port, uptime, requests served, log path and lines written
bin/search-router daemon stop
bin/search-router daemon start    # start now and wait until it answers

The process keeps its error output in $SEARCH_ROUTER_HOME/daemon-<fingerprint>.log (mode 0600, append only; at start, a file over 256 KiB is cut to its last 64 KiB). Every line is redacted: no key, token, header value or URL query string is written. daemon status and the background process: lines of doctor show the path and how many lines the process wrote since it started. An error nobody handled, in the background process or in the MCP server, becomes one such line and the process keeps serving. The ledger waits at most 250 ms for a lock, and the long-lived processes delete calls older than 62 days when they start and once a day after.

If it cannot be reached, the call is answered in-process as if it did not exist, and costs no more time than without it. One case costs more: when the process took a request and then failed to answer it (a timeout or a server error), the call is answered in-process once more. That call can spend allowance twice, including one paid call, and takes the wait for the process plus the in-process run. It is at most one extra run per call. daemon stop lets requests already running finish first. Three ways to bypass it: --no-daemon on search or read, SEARCH_ROUTER_DAEMON=off, and SEARCH_ROUTER_FAULTS (a drill never goes through it).

Backends

Backend

Used for

Key

You.com free MCP profile

general

none

Parallel anonymous MCP

general, page reading

none

Parallel REST (replaces the anonymous endpoint when the key is set)

general, page reading

PARALLEL_API_KEY

Tavily keyless

general

none

Tavily

general

TAVILY_API_KEY

Exa

general, finding similar things

EXA_API_KEY

TinyFish Search and Fetch

general, page reading

TINYFISH_API_KEY

DeepSeek Search

general, paid: $0.75 per 1,000 successful calls

DEEPSEEK_API_KEY

arXiv

papers

none

OpenAlex

papers; about 100 searches a day keyless, 1,000 with a free key

optional OPENALEX_API_KEY

Semantic Scholar

papers; the keyless pool is shared and often answers "too many requests"

optional SEMANTIC_SCHOLAR_API_KEY

Hacker News (Algolia)

discussion

none

Stack Exchange

error messages; 300 calls a day keyless, 10,000 with an app key

optional STACKEXCHANGE_KEY

GitHub repositories

code, when the query asks for a project (repository, library, package, source code)

optional GITHUB_TOKEN

GitHub issues

error messages

optional GITHUB_TOKEN

Context7

library documentation, for technical queries

optional CONTEXT7_API_KEY

pkg.go.dev

Go packages

none

Baidu (Qianfan web search)

Chinese queries; 50 a day free

QIANFAN_API_KEY

Bocha

Chinese queries; paid after a 1,000-call trial

BOCHA_API_KEY

Jina Reader

page reading

optional JINA_API_KEY

A specialist answers only queries of its type: a backend that answers a query it is weak for would end the search early with poor hits. When it comes back empty, the next one is asked, and a general index starts beside it.

Live runs: the key-gated general backends and readers on 2026-11-17 (one search with hits each, one page read through each keyed reader). On 2026-11-29 one search each through Stack Exchange, GitHub repositories, GitHub issues, Context7, pkg.go.dev, OpenAlex, arXiv and Hacker News came back with hits; keyless Semantic Scholar answered "too many requests". Baidu, Bocha and the keyed variants of the optional keys have not been run live. Error replies (allowance used up, rate limit) are handled as the vendors' documentation describes and most have not been seen live.

A paid backend (DeepSeek, Bocha) is planned after every free one, is never started as a hedge or in a pair, and runs only when the calls before it ended without results. SEARCH_ROUTER_PAID=off leaves it out. doctor shows its price per call, and the ledger records that price as the cost of each call.

Keyless allowances are per address and not always published. The router learns them from the responses.

Decision model

With a key for at least one decision provider, a small model helps in two places: it classifies a query the rules are unsure about, in parallel with the first search, and it grades the hits when there is a reason to (--need verify, a new name, hits that do not carry the query's words, a hit that looks like an injection). It can drop hits that do not address the query, start a second, bounded pass with backends not yet asked, and neutralize a hit or page passage it judges to be aimed at an AI agent. When the hits already carry the query's words it is not called.

Providers are tried in order, each with its own 1.5 s timer inside a 2 s cap per call:

Provider

Key

Allowance

Gemini Decision 1

GEMINI_API_KEY

10,000 a day free, reset at midnight US Pacific

TypeSafe Jev 1.14

JEV_API_KEY (or TYPESAFE_API_KEY)

the account's free credits

OpenRouter: Perplexity Decider v1.3, then Decider Flash v1.3 (free models)

OPENROUTER_API_KEY

50 a day, 1,000 after 10 credits

A request a provider blocks for its content, or answers with refusals only, goes to the next provider and does not rest the one that blocked it. A rate limit or used-up allowance rests that provider for the time it says and goes to the next. SEARCH_ROUTER_DECISION_PROVIDERS (for example jev,gemini) sets the order or leaves providers out.

Gemini was run live on 2026-11-29: classification and grading answered in 0.4 to 0.6 s on a warm connection and 1.0 to 1.2 s on a new one. Jev and OpenRouter have not been run live.

Settings

Variable

Meaning

SEARCH_ROUTER_HOME

where the ledger, keys.env and evaluation output live, default ~/.search-router

SEARCH_ROUTER_HEDGE_MS

a fixed hedge delay, for experiments

SEARCH_ROUTER_CALL_TIMEOUT_MS

per-call timeout in milliseconds (positive whole number, default 8,000)

SEARCH_ROUTER_DEADLINE_MS

total search deadline in milliseconds (positive whole number, default 10,000)

SEARCH_ROUTER_CACHE_TTL_S

seconds an answer is kept in the answer cache, 0 for none, default 300

SEARCH_ROUTER_FAULTS

pretend outcomes, for drills (uses an isolated in-memory ledger and no cache): you=quota,parallel=failed

SEARCH_ROUTER_NO_WARM

1 skips warming at server start and in the background process

SEARCH_ROUTER_DAEMON

off never uses the background process

SEARCH_ROUTER_DAEMON_IDLE_MIN

minutes without a request before the background process leaves, a positive number up to 1440, default 30

SEARCH_ROUTER_PAID

off leaves paid backends out of every search; default on

SEARCH_ROUTER_DECISION

off turns the decision model off; default auto, on when a decision provider has a key

SEARCH_ROUTER_DECISION_PROVIDERS

decision providers in the order tried, default gemini,jev,openrouter

SEARCH_ROUTER_OPENROUTER_MODELS

OpenRouter models in the order tried, replacing the two free Decider models

Keys

The quickest way: search-router auth opens a page in the browser that lists every provider with what it adds, its free tier and a link to the page where a key is made. Paste a key, save it, and press Test to spend one real call checking it. OpenRouter also offers a sign-in that saves a key without copying it. The page is served on 127.0.0.1 only, with a random token in the address, and never shows a saved key; the process leaves when you press Done or after 15 minutes without a request.

From the terminal:

bin/search-router key add                     # paste any key: the provider is recognised by its prefix
bin/search-router key list                    # per name: source (env, file, unset) and length, never the value
bin/search-router key set TAVILY_API_KEY      # hidden prompt on a terminal, first line of a pipe
bin/search-router key set TAVILY_API_KEY --clipboard   # macOS: from the clipboard
bin/search-router key import-env [NAME...]    # copy set environment variables into the file
bin/search-router key unset TAVILY_API_KEY

Keys live in $SEARCH_ROUTER_HOME/keys.env (default ~/.search-router/keys.env), one NAME=value per line: no quotes, # starts a comment line, a later line of the same name wins. The directory is 0700 and the file 0600. Known names: TAVILY_API_KEY, EXA_API_KEY, PARALLEL_API_KEY, TINYFISH_API_KEY, DEEPSEEK_API_KEY, GEMINI_API_KEY, JEV_API_KEY (also read as TYPESAFE_API_KEY), OPENROUTER_API_KEY, GITHUB_TOKEN, STACKEXCHANGE_KEY, CONTEXT7_API_KEY, OPENALEX_API_KEY, SEMANTIC_SCHOLAR_API_KEY, JINA_API_KEY, QIANFAN_API_KEY, BOCHA_API_KEY.

  • An environment variable of the same name wins over the file.

  • key add recognises a key only by a prefix one provider documents (AIza Gemini, sk-or-v1- OpenRouter, tvly- Tavily, github_pat_ and ghp_ GitHub, ctx7sk- Context7, jina_ Jina, bce-v3/ Qianfan); any other key needs its name, through key set.

  • Writing refuses when the key file's directory is inside a git working tree, so a key cannot be committed. keys.env is also in .gitignore.

  • No command, page, log or error prints a key value; key list, doctor and the key page show the source and the length only.

Untrusted text

Hits and pages are written by strangers. Before they reach an agent or the decision model, the router removes invisible and control characters and hidden markup, drops spam, copy farms and near-duplicate copies (warning filtered_spam), drops page chrome, and rewrites text aimed at AI agents, such as instruction overrides, spoofed role tags and exfiltration links, to [removed: instruction aimed at AI agents] (warning injection_sanitized). Text that only looks like an injection is judged by the decision model when one is configured. A security article that quotes an injection stays readable.

read refuses a URL whose host is local or private (localhost, .local, .internal, private, link-local and metadata addresses in any notation) before any reader service sees it.

Measure it

Offline, in the test suite: eval/policy.test.ts checks the routing decisions for 26 labelled queries (first backend, paired start, pre-classification, decision gate), and eval/sanitize/ measures spam and injection screening on labelled hits and pages.

Live:

bun run eval

runs 20 queries against each general backend alone, the router, and the router with its first choice forced to "allowance used up", and reports hits, latency, calls per backend, decision calls per provider and how often the gate ran. It spends real free allowance, about 80 searches, so run it once and read $SEARCH_ROUTER_HOME/eval/.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables AI agents to perform web searches, extract webpage content, and conduct end-to-end search-and-extract operations using multiple search providers and content extraction methods.
      -
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI agents to fetch and extract clean, readable content from web pages, and search within pages for specific queries, without needing a full browser.
      1
      MIT
    • A
      license
      B
      quality
      C
      maintenance
      Enables AI agents to perform web searches and extract full-text content from web pages via standard MCP tools, with fallback search and semantic reranking.
      2
      2
      MIT
    • A
      license
      A
      quality
      C
      maintenance
      Enables finding information online, reading web pages, finding images, capturing screenshots, and performing multi-source research with per-answer confidence.
      5
      AGPL 3.0