API: providers/duckduckgo
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#
Properties#
| Property | Modifier | Type | Default value | Description | Defined in |
|---|---|---|---|---|---|
name | readonly | "duckduckgo" | "duckduckgo" | Stable provider identifier (e.g. “brave”, “tavily”, “duckduckgo”). | src/providers/duckduckgo.ts:19 |
Methods#
search()#
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#
| Parameter | Type |
|---|---|
query | string |
opts | SearchOptions |
Returns#
Promise<SearchResult[]>
Implementation of#
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#
| Parameter | Type |
|---|---|
html | string |
Returns#
boolean
parseHtmlResults()#
parseHtmlResults(
html,limit):SearchResult[]
Defined in: src/providers/duckduckgo.ts:113
Parse DuckDuckGo HTML search results into normalized SearchResults.
Parameters#
| Parameter | Type |
|---|---|
html | string |
limit | number |