API: providers/duckduckgo

better-web-search-mcp


better-web-search-mcp / providers/duckduckgo

providers/duckduckgo#

Classes#

DuckDuckGoProvider#

Defined in: src/providers/duckduckgo.ts:18

DuckDuckGo provider (free, keyless fallback).

Scrapes the public HTML search endpoint and parses results with cheerio. Always enabled — no API key required. On any failure (network, timeout, parse) it returns an empty array and logs a warning rather than throwing.

Implements#

Constructors#

Constructor#

new DuckDuckGoProvider(): DuckDuckGoProvider

Returns#

DuckDuckGoProvider

Properties#

PropertyModifierTypeDefault valueDescriptionDefined in
namereadonly"duckduckgo""duckduckgo"Stable provider identifier (e.g. “brave”, “tavily”, “duckduckgo”).src/providers/duckduckgo.ts:19

Methods#

search(query, opts): Promise<SearchResult[]>

Defined in: src/providers/duckduckgo.ts:21

Run a search and return normalized results.

Implementations MUST NOT throw on provider errors (missing key, HTTP 401/429, timeout). They return an empty array and log a warning instead, so one failing provider never breaks the aggregate search.

Parameters#
ParameterType
querystring
optsSearchOptions
Returns#

Promise<SearchResult[]>

Implementation of#

SearchProvider.search

Functions#

isChallengePage()#

isChallengePage(html): boolean

Defined in: src/providers/duckduckgo.ts:105

Whether the HTML is a bot-detection challenge rather than a result page.

The endpoint answers a throttled request with a 2xx status and an anomaly page, so status alone cannot tell the two apart. Requiring both the absence of result markup and a challenge marker avoids calling a genuinely empty search a block.

Parameters#

ParameterType
htmlstring

Returns#

boolean


parseHtmlResults()#

parseHtmlResults(html, limit): SearchResult[]

Defined in: src/providers/duckduckgo.ts:113

Parse DuckDuckGo HTML search results into normalized SearchResults.

Parameters#

ParameterType
htmlstring
limitnumber

Returns#

SearchResult[]