searchfetch 3.2.3 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -84,6 +84,13 @@ Template extraction supports `text`, `markdown`, `attribute`, and `html` formats
84
84
 
85
85
  Built-in templates live in `templates/*.json` and are shared by the Node.js and Python implementations.
86
86
 
87
+ **Available page templates** (auto-detected by URL or selectable by name):
88
+ `wikipedia`, `reddit`, `mdn-web-docs`, `gitlab`, `youtube`, `devto`, `go-pkg`, `javadoc`,
89
+ `github-repo`, `github-issue`, `npm-package`, `pypi-package`, `crates-package`,
90
+ `docker-hub`, `docs-rs`, `docs-page`
91
+
92
+ **`raw`** — special template that applies minimal filtering and returns full body content as markdown. Use when you need the complete page without template-specific extraction.
93
+
87
94
  ---
88
95
 
89
96
  ## Local Development
package/index.js CHANGED
@@ -274,16 +274,18 @@ function isAccessDenied($) {
274
274
 
275
275
  if (titleDenyPatterns.some((pattern) => title.includes(pattern))) return true;
276
276
 
277
- const bodyDenyPatterns = [
277
+ const strongBodyDenyPatterns = [
278
278
  "to continue, please type the characters",
279
279
  "our systems have detected unusual traffic",
280
- "verify you are human",
281
- "are you a robot",
282
280
  "sorry, you have been blocked",
283
- "access denied",
281
+ "bots use duckduckgo too",
284
282
  ];
285
283
 
286
- if (bodyText.length < 1200 && bodyDenyPatterns.some((pattern) => bodyText.includes(pattern)))
284
+ if (strongBodyDenyPatterns.some((pattern) => bodyText.includes(pattern))) return true;
285
+
286
+ const shortBodyDenyPatterns = ["verify you are human", "are you a robot", "access denied"];
287
+
288
+ if (bodyText.length < 1200 && shortBodyDenyPatterns.some((pattern) => bodyText.includes(pattern)))
287
289
  return true;
288
290
 
289
291
  return false;
@@ -328,7 +330,10 @@ async function fetchHtml(url, template, blockMedia) {
328
330
  timeout: 15000,
329
331
  });
330
332
  } catch (_navError) {
331
- // Allow partial rendering on timeout
333
+ // Allow partial rendering on timeout only
334
+ if (!_navError.message?.includes("timeout") && !_navError.message?.includes("Timeout")) {
335
+ throw _navError;
336
+ }
332
337
  }
333
338
 
334
339
  // Check HTTP status for access failures
@@ -377,7 +382,8 @@ async function fetchHtmlWithRetry(url, template, blockMedia) {
377
382
  attempt < FETCH_MAX_ATTEMPTS - 1 &&
378
383
  (err.message.includes("net::") ||
379
384
  err.message.includes("ERR_") ||
380
- err.message.includes("Navigation failed"))
385
+ err.message.includes("Navigation failed") ||
386
+ err.message.includes("navigating"))
381
387
  ) {
382
388
  await sleep(500);
383
389
  continue;
@@ -1017,9 +1023,55 @@ function resolveSearchTemplate(engine, query, region, safeSearch) {
1017
1023
  return { template, url };
1018
1024
  }
1019
1025
 
1026
+ function resolveDuckDuckGoLiteTemplate(query, region, safeSearch) {
1027
+ const template = {
1028
+ ...getTemplateByName("duckduckgo-search"),
1029
+ name: "duckduckgo-lite-search",
1030
+ url_template: "https://lite.duckduckgo.com/lite/?q={query}&kl={kl}&kp={kp}",
1031
+ sections: [
1032
+ {
1033
+ name: "Results",
1034
+ selector: "a.result-link",
1035
+ multiple: true,
1036
+ max_items: 10,
1037
+ children: [
1038
+ { name: "Title", selector: "", format: "text" },
1039
+ {
1040
+ name: "URL",
1041
+ selector: "",
1042
+ format: "attribute",
1043
+ attribute: "href",
1044
+ transform: "decode_ddg_url",
1045
+ },
1046
+ ],
1047
+ },
1048
+ ],
1049
+ };
1050
+ const params = mapSearchParams("duckduckgo", query, region, safeSearch);
1051
+ return { template, url: resolveUrlTemplate(template, params), engine: "duckduckgo-lite" };
1052
+ }
1053
+
1054
+ function resolveSearchCandidates(engine, query, region, safeSearch) {
1055
+ const primary = { ...resolveSearchTemplate(engine, query, region, safeSearch), engine };
1056
+ if (engine === "google") {
1057
+ return [
1058
+ primary,
1059
+ {
1060
+ ...resolveSearchTemplate("duckduckgo", query, region, safeSearch),
1061
+ engine: "duckduckgo",
1062
+ },
1063
+ resolveDuckDuckGoLiteTemplate(query, region, safeSearch),
1064
+ ];
1065
+ }
1066
+ if (engine === "duckduckgo") {
1067
+ return [primary, resolveDuckDuckGoLiteTemplate(query, region, safeSearch)];
1068
+ }
1069
+ return [primary];
1070
+ }
1071
+
1020
1072
  // === MCP SERVER & TOOLS ==================================================
1021
1073
 
1022
- const server = new McpServer({ name: "searchfetch", version: "3.2.3" });
1074
+ const server = new McpServer({ name: "searchfetch", version: "3.3.1" });
1023
1075
 
1024
1076
  // --- websearch tool ---
1025
1077
 
@@ -1065,28 +1117,41 @@ server.registerTool(
1065
1117
  },
1066
1118
  async ({ query, engine, region, safe_search, max_results, block_media }) => {
1067
1119
  try {
1068
- // 1. Resolve search template (+ url_params mapping + url building)
1069
- const { template, url } = resolveSearchTemplate(engine, query, region, safe_search);
1070
-
1071
- // 2. Fetch
1072
- const html = await fetchHtmlWithRetry(url, template, block_media);
1120
+ const candidates = resolveSearchCandidates(engine, query, region, safe_search);
1121
+ let extracted;
1122
+ let selectedEngine;
1123
+ let lastError;
1073
1124
 
1074
- // 3. Extract
1075
- const $ = cheerio.load(html);
1076
- applyRemove($, template);
1077
-
1078
- const pageOrigin = new URL(url).origin;
1079
- const context = {
1080
- origin: pageOrigin,
1081
- isWebsearch: true,
1082
- maxResultsOverride: max_results,
1083
- _maxResultsConsumed: false,
1084
- };
1125
+ for (const candidate of candidates) {
1126
+ try {
1127
+ const html = await fetchHtmlWithRetry(candidate.url, candidate.template, block_media);
1128
+ const $ = cheerio.load(html);
1129
+ applyRemove($, candidate.template);
1130
+ extracted = extractTemplate($, candidate.template, {
1131
+ origin: new URL(candidate.url).origin,
1132
+ isWebsearch: true,
1133
+ maxResultsOverride: max_results,
1134
+ _maxResultsConsumed: false,
1135
+ });
1136
+ const resultSection = extracted.find((result) => result.type === "children-multiple");
1137
+ if (resultSection?.items?.length > 0) {
1138
+ selectedEngine = candidate.engine;
1139
+ break;
1140
+ }
1141
+ lastError = new Error(`No results extracted from ${candidate.engine}.`);
1142
+ } catch (err) {
1143
+ lastError = err;
1144
+ }
1145
+ }
1085
1146
 
1086
- const extracted = extractTemplate($, template, context);
1147
+ if (!extracted || !selectedEngine) throw lastError || new Error("No search results found.");
1087
1148
 
1088
- // 4. Compose
1089
- const result = composeSearchResults(extracted);
1149
+ let result = composeSearchResults(extracted);
1150
+ if (selectedEngine !== engine) {
1151
+ result =
1152
+ `[websearch: ${engine} was unavailable; results are from ${selectedEngine}.]\n\n` +
1153
+ result;
1154
+ }
1090
1155
 
1091
1156
  return { content: [{ type: "text", text: result }] };
1092
1157
  } catch (err) {
@@ -1114,7 +1179,11 @@ server.registerTool(
1114
1179
  .string()
1115
1180
  .default("auto")
1116
1181
  .describe(
1117
- "Template to use: 'auto' (auto-detect from URL), a built-in name, or inline JSON.",
1182
+ "Template to use: 'auto' (auto-detect from URL), a built-in page template name " +
1183
+ "(wikipedia, reddit, mdn-web-docs, gitlab, youtube, devto, go-pkg, javadoc, " +
1184
+ "github-repo, github-issue, npm-package, pypi-package, crates-package, " +
1185
+ "docker-hub, docs-rs, docs-page), 'raw' for minimal-filtering full-page output, " +
1186
+ "or inline JSON.",
1118
1187
  ),
1119
1188
  start_index: z.number().default(0).describe("Character offset for pagination. Default: 0."),
1120
1189
  max_length: z
@@ -1208,6 +1277,7 @@ export {
1208
1277
  resolveEngineToTemplateName,
1209
1278
  mapSearchParams,
1210
1279
  resolveSearchTemplate,
1280
+ resolveSearchCandidates,
1211
1281
  isMarkdownContent,
1212
1282
  stripSourceMarkdown,
1213
1283
  resolveSourceUrl,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "searchfetch",
3
- "version": "3.2.3",
3
+ "version": "3.3.1",
4
4
  "description": "Fault-tolerant MCP Server for Stealth Web Search and Fetching",
5
5
  "type": "module",
6
6
  "bin": {
@@ -36,7 +36,7 @@
36
36
  "dependencies": {
37
37
  "@modelcontextprotocol/sdk": "^1.29.0",
38
38
  "cheerio": "^1.2.0",
39
- "cloakbrowser": "^0.4.5",
39
+ "cloakbrowser": "^0.4.11",
40
40
  "playwright-core": "^1.61.1",
41
41
  "turndown": "^7.2.4",
42
42
  "zod": "^4.4.3"
@@ -45,7 +45,7 @@
45
45
  "encoding-sniffer": "1.0.2"
46
46
  },
47
47
  "devDependencies": {
48
- "eslint": "^10.6.0",
49
- "prettier": "^3.9.4"
48
+ "eslint": "^10.7.0",
49
+ "prettier": "^3.9.5"
50
50
  }
51
51
  }
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "devto",
3
+ "description": "DEV Community article — title, author, and content",
4
+ "order": 20,
5
+ "url_patterns": [
6
+ "^https?://dev\\.to/[^/]+/[^/]+"
7
+ ],
8
+ "remove": [
9
+ "script",
10
+ "style",
11
+ "svg",
12
+ "img",
13
+ "nav",
14
+ "footer",
15
+ ".sidebar",
16
+ ".crayons-layout__sidebar-left",
17
+ ".crayons-layout__sidebar-right",
18
+ ".crayons-article-actions",
19
+ ".reaction-button",
20
+ ".crayons-btn",
21
+ ".spec__tags",
22
+ ".article-engagement-bar",
23
+ ".comments-container"
24
+ ],
25
+ "sections": [
26
+ {
27
+ "name": "Title",
28
+ "selector": "h1",
29
+ "format": "text",
30
+ "required": true
31
+ },
32
+ {
33
+ "name": "Author",
34
+ "selector": ".crayons-article__header__meta a, a.crayons-avatar",
35
+ "format": "text",
36
+ "required": false
37
+ },
38
+ {
39
+ "name": "Content",
40
+ "selector": "#article-body, .crayons-article__body, article.crayons-article",
41
+ "format": "markdown",
42
+ "required": true
43
+ }
44
+ ]
45
+ }
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "gitlab",
3
+ "description": "GitLab project — description, file listing, and README",
4
+ "order": 12,
5
+ "url_patterns": [
6
+ "^https?://gitlab\\.com/[^/]+/[^/]+/?$",
7
+ "^https?://gitlab\\.com/[^/]+/[^/]+/-/tree/[^/]+/?$"
8
+ ],
9
+ "remove": [
10
+ "script",
11
+ "style",
12
+ "svg",
13
+ "nav",
14
+ "footer",
15
+ "header",
16
+ ".navbar-gitlab",
17
+ ".nav-sidebar",
18
+ ".issuable-list",
19
+ ".super-sidebar",
20
+ "aside"
21
+ ],
22
+ "sections": [
23
+ {
24
+ "name": "Title",
25
+ "selector": "h1",
26
+ "format": "text",
27
+ "required": true
28
+ },
29
+ {
30
+ "name": "Description",
31
+ "selector": "meta[name='description']",
32
+ "format": "attribute",
33
+ "attribute": "content",
34
+ "required": false
35
+ },
36
+ {
37
+ "name": "Files",
38
+ "selector": "table[data-qa-selector='file_tree_table'], .tree-table",
39
+ "format": "markdown",
40
+ "required": false
41
+ },
42
+ {
43
+ "name": "README",
44
+ "selector": ".readme-holder .md, .file-content .md, .readme-holder",
45
+ "format": "markdown",
46
+ "required": false
47
+ }
48
+ ]
49
+ }
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "go-pkg",
3
+ "description": "Go package documentation on pkg.go.dev — name, overview, and docs",
4
+ "order": 22,
5
+ "url_patterns": [
6
+ "^https?://pkg\\.go\\.dev/[^/]+/?$",
7
+ "^https?://pkg\\.go\\.dev/[^/]+/[^/]+/?$",
8
+ "^https?://pkg\\.go\\.dev/[^/]+/[^/]+/[^/]+/?$"
9
+ ],
10
+ "remove": [
11
+ "script",
12
+ "style",
13
+ "svg",
14
+ "nav",
15
+ "footer",
16
+ ".go-Header",
17
+ ".go-SiteHeader",
18
+ ".go-Footer",
19
+ ".UnitMeta",
20
+ ".UnitMeta-repo",
21
+ ".UnitFiles",
22
+ ".JumpDrawer",
23
+ ".go-Main-nav",
24
+ ".go-Main-headerSubmenu",
25
+ ".Site-header",
26
+ ".UnitHeader-version",
27
+ ".UnitHeader-breadcrumb",
28
+ ".UnitHeader-details"
29
+ ],
30
+ "sections": [
31
+ {
32
+ "name": "Title",
33
+ "selector": "h1",
34
+ "format": "text",
35
+ "required": true
36
+ },
37
+ {
38
+ "name": "Overview",
39
+ "selector": ".Documentation-overview, .Overview",
40
+ "format": "markdown",
41
+ "required": false
42
+ },
43
+ {
44
+ "name": "Documentation",
45
+ "selector": ".Documentation-content, .Documentation, #documentation",
46
+ "format": "markdown",
47
+ "required": false
48
+ }
49
+ ]
50
+ }
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "javadoc",
3
+ "description": "Java SE API documentation — class/method details",
4
+ "order": 8.5,
5
+ "url_patterns": [
6
+ "^https?://docs\\.oracle\\.com/.*/docs/api/.*"
7
+ ],
8
+ "remove": [
9
+ "script",
10
+ "style",
11
+ "svg",
12
+ "nav",
13
+ "footer",
14
+ "header",
15
+ ".topNav",
16
+ ".bottomNav",
17
+ ".subNav",
18
+ ".navListSearch",
19
+ ".skipNav",
20
+ ".searchTag",
21
+ ".searchTagResult",
22
+ ".useSummary",
23
+ ".inheritedList",
24
+ ".details",
25
+ ".memberSummary",
26
+ ".colFirst",
27
+ ".colLast"
28
+ ],
29
+ "sections": [
30
+ {
31
+ "name": "Title",
32
+ "selector": ".header h2, h2.title, h2:first-of-type",
33
+ "format": "text",
34
+ "required": false
35
+ },
36
+ {
37
+ "name": "Content",
38
+ "selector": "[role='main'], .document, .rst-content, article, .content, .markdown-body, .prose, main, .contentContainer",
39
+ "format": "markdown",
40
+ "required": true
41
+ }
42
+ ]
43
+ }
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "mdn-web-docs",
3
+ "description": "MDN Web Docs article — title and main content",
4
+ "order": 15,
5
+ "url_patterns": [
6
+ "^https?://developer\\.mozilla\\.org/.*"
7
+ ],
8
+ "remove": [
9
+ "script",
10
+ "style",
11
+ "svg",
12
+ "nav",
13
+ "footer",
14
+ "header",
15
+ ".sidebar",
16
+ ".toc",
17
+ ".interactive",
18
+ ".playground",
19
+ ".bc-data",
20
+ ".prev-next",
21
+ ".notecard",
22
+ ".language-menu",
23
+ ".breadcrumbs-container"
24
+ ],
25
+ "sections": [
26
+ {
27
+ "name": "Title",
28
+ "selector": "h1",
29
+ "format": "text",
30
+ "required": true
31
+ },
32
+ {
33
+ "name": "Content",
34
+ "selector": "#content, article, main, .main-page-content",
35
+ "format": "markdown",
36
+ "required": true
37
+ }
38
+ ]
39
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "raw",
3
+ "description": "Raw page content — minimal filtering, full body as markdown (use when you need the complete page without template extraction)",
4
+ "order": 999,
5
+ "remove": [],
6
+ "sections": [
7
+ {
8
+ "name": "Content",
9
+ "selector": "body",
10
+ "format": "markdown",
11
+ "required": false
12
+ }
13
+ ]
14
+ }
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "reddit",
3
+ "description": "Reddit post — title, content, and comments",
4
+ "order": 13,
5
+ "url_patterns": [
6
+ "^https?://(?:www\\.|old\\.)?reddit\\.com/r/[^/]+/comments/[^/]+"
7
+ ],
8
+ "remove": [
9
+ "script",
10
+ "style",
11
+ "svg",
12
+ "img",
13
+ "nav",
14
+ "footer",
15
+ "header",
16
+ ".promoted-post",
17
+ "shreddit-ad-post",
18
+ ".side",
19
+ ".sidebar",
20
+ ".footer-parent",
21
+ "#header",
22
+ ".sr-header-area",
23
+ ".menuarea",
24
+ ".linkinfo",
25
+ ".panestack-title",
26
+ ".report-button",
27
+ "shreddit-join-button",
28
+ "#overlayScrollContainer",
29
+ "#right-sidebar-container",
30
+ "#left-sidebar-container"
31
+ ],
32
+ "sections": [
33
+ {
34
+ "name": "Subreddit",
35
+ "selector": "a[href*='/r/'], shreddit-post a[href*='/r/']",
36
+ "format": "text",
37
+ "required": false
38
+ },
39
+ {
40
+ "name": "Title",
41
+ "selector": "h1, shreddit-post [slot='title']",
42
+ "format": "text",
43
+ "required": true
44
+ },
45
+ {
46
+ "name": "Author",
47
+ "selector": "a[href*='/user/'], shreddit-post a[href*='/user/'], [slot='authorName']",
48
+ "format": "text",
49
+ "required": false
50
+ },
51
+ {
52
+ "name": "Link",
53
+ "selector": "a[slot='external-anchor'], a.outbound-link, a[data-testid='outbound-link']",
54
+ "format": "attribute",
55
+ "attribute": "href",
56
+ "required": false
57
+ },
58
+ {
59
+ "name": "Content",
60
+ "selector": "[slot='text-body'], .text-body, .expando, .usertext-body .md",
61
+ "format": "markdown",
62
+ "required": false
63
+ }
64
+ ]
65
+ }
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "wikipedia",
3
+ "description": "Wikipedia article — title and main content",
4
+ "order": 11,
5
+ "url_patterns": [
6
+ "^https?://[a-z]{2,4}\\.wikipedia\\.org/wiki/[^:]+$"
7
+ ],
8
+ "remove": [
9
+ "script",
10
+ "style",
11
+ "svg",
12
+ "nav",
13
+ "footer",
14
+ ".mw-editsection",
15
+ ".reflist",
16
+ ".navbox",
17
+ ".sisterproject",
18
+ ".metadata",
19
+ ".sidebar",
20
+ ".infobox",
21
+ "#toc",
22
+ ".mw-jump-link",
23
+ ".printfooter",
24
+ ".catlinks",
25
+ ".mw-authority-control",
26
+ ".shortdescription",
27
+ ".mw-indicators",
28
+ ".page-actions",
29
+ ".mw-page-title-namespace",
30
+ ".mw-heading-subtitle"
31
+ ],
32
+ "sections": [
33
+ {
34
+ "name": "Title",
35
+ "selector": "#firstHeading, h1",
36
+ "format": "text",
37
+ "required": true
38
+ },
39
+ {
40
+ "name": "Content",
41
+ "selector": "#mw-content-text .mw-parser-output",
42
+ "format": "markdown",
43
+ "required": true
44
+ }
45
+ ]
46
+ }
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "youtube",
3
+ "description": "YouTube video — title, channel, description",
4
+ "order": 30,
5
+ "url_patterns": [
6
+ "^https?://(?:www\\.)?(?:youtube\\.com/watch\\?v=|youtu\\.be/).+"
7
+ ],
8
+ "remove": [
9
+ "script",
10
+ "style",
11
+ "svg",
12
+ "img",
13
+ "nav",
14
+ "header",
15
+ "ytd-guide-renderer",
16
+ "ytd-mini-guide-renderer",
17
+ "#comments",
18
+ "#related",
19
+ "ytd-comments",
20
+ "ytd-live-chat-frame",
21
+ ".ytp-ad-module"
22
+ ],
23
+ "sections": [
24
+ {
25
+ "name": "Title",
26
+ "selector": "meta[name='title']",
27
+ "format": "attribute",
28
+ "attribute": "content",
29
+ "required": true
30
+ },
31
+ {
32
+ "name": "Channel",
33
+ "selector": "#owner a, ytd-video-owner-renderer a, #channel-name a",
34
+ "format": "text",
35
+ "required": false
36
+ },
37
+ {
38
+ "name": "Description",
39
+ "selector": "#description-inline-expander, ytd-text-inline-expander, #info-container",
40
+ "format": "markdown",
41
+ "required": false
42
+ }
43
+ ]
44
+ }