Configuration

All environment variables are optional. The server starts and works via DuckDuckGo when no keys are set. Create a .env only if you want additional providers.

cp .env.example .env  # then edit

Environment Variables#

VariableRequiredDescription
BRAVE_API_KEY or BETTER_WEB_SEARCH_BRAVE_API_KEYnoBrave Search API key (primary). Get one
TAVILY_API_KEY or BETTER_WEB_SEARCH_TAVILY_API_KEYnoTavily key. tavily.com
BETTER_WEB_SEARCH_DISABLE_CACHEnotrue → in-memory fallback (no SQLite)
BETTER_WEB_SEARCH_CACHE_PATHnoCustom SQLite path (default data/cache.db)
BETTER_WEB_SEARCH_DISABLE_BROWSERnotrue → skip Playwright fallback

Key aliases#

The config loader supports both the bare name and the BETTER_WEB_SEARCH_* prefix:

CanonicalAliases
BRAVE_API_KEYBETTER_WEB_SEARCH_BRAVE_API_KEY, BRAVE_SEARCH_API_KEY
TAVILY_API_KEYBETTER_WEB_SEARCH_TAVILY_API_KEY

The first non-empty value found wins (checked in the order listed above).

Cache settings#

VariableDefaultDescription
BETTER_WEB_SEARCH_DISABLE_CACHEfalseSet true to disable SQLite cache entirely
DISABLE_CACHEfalseAlias for the above
BETTER_WEB_SEARCH_CACHE_PATHdata/cache.dbPath to SQLite cache file
CACHE_PATHAlias for the above

Cache TTLs:

  • Search results: 15 minutes
  • Page content: 1 hour
  • Domain profiles and API patterns: permanent (self-learning)

Expired rows are pruned automatically on startup.

Browser settings#

VariableDefaultDescription
BETTER_WEB_SEARCH_DISABLE_BROWSERfalseSet true to skip Playwright browser fallback entirely
DISABLE_BROWSERfalseAlias for the above

The Playwright browser pool uses up to 3 concurrent instances, blocks images/fonts/media for speed, and uses an intelligent race between networkidle, article detection, and innerText > 1000 to determine when a page is loaded.

Server banner#

When the server starts, it prints a provider status banner to stderr:

better-web-search-mcp v0.2.3
Providers (keyless-first):
  ✓ duckduckgo (keyless) — always on
  ✗ brave (api-key) — set BRAVE_API_KEY for better results
  ✗ tavily (api-key) — optional — set TAVILY_API_KEY
Cache: data/cache.db
Browser: enabled (playwright, pool=3)

Example .env#

# BetterWebSearch MCP - environment configuration
# All keys are optional; the server starts and falls back to
# keyless providers (DuckDuckGo) when absent.

# Brave Search API key (primary provider).
# Get one at https://brave.com/search/api/
BRAVE_API_KEY=

# Tavily Search API key (optional).
# https://tavily.com/
TAVILY_API_KEY=

# SerpApi key (optional, reserved for a future provider).
# https://serpapi.com/
SERPAPI_KEY=