searchfetch 3.3.4__tar.gz → 4.1.0__tar.gz

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.
Files changed (67) hide show
  1. searchfetch-4.1.0/.gitignore +51 -0
  2. searchfetch-4.1.0/PKG-INFO +194 -0
  3. searchfetch-4.1.0/README.md +169 -0
  4. searchfetch-4.1.0/pyproject.toml +65 -0
  5. searchfetch-4.1.0/searchfetch/__init__.py +5 -0
  6. searchfetch-4.1.0/searchfetch/__main__.py +3 -0
  7. searchfetch-4.1.0/searchfetch/browser.py +220 -0
  8. searchfetch-4.1.0/searchfetch/compose.py +123 -0
  9. searchfetch-4.1.0/searchfetch/extract.py +231 -0
  10. searchfetch-4.1.0/searchfetch/markdown.py +55 -0
  11. searchfetch-4.1.0/searchfetch/server.py +211 -0
  12. searchfetch-4.1.0/searchfetch/templates.py +294 -0
  13. {searchfetch-3.3.4 → searchfetch-4.1.0}/templates/crates-package.json +1 -1
  14. {searchfetch-3.3.4 → searchfetch-4.1.0}/templates/devto.json +1 -1
  15. {searchfetch-3.3.4 → searchfetch-4.1.0}/templates/docker-hub.json +1 -1
  16. {searchfetch-3.3.4 → searchfetch-4.1.0}/templates/docs-page.json +1 -1
  17. {searchfetch-3.3.4 → searchfetch-4.1.0}/templates/docs-rs.json +1 -1
  18. searchfetch-4.1.0/templates/duckduckgo-lite-search.json +49 -0
  19. {searchfetch-3.3.4 → searchfetch-4.1.0}/templates/duckduckgo-search.json +3 -1
  20. {searchfetch-3.3.4 → searchfetch-4.1.0}/templates/github-issue.json +1 -1
  21. {searchfetch-3.3.4 → searchfetch-4.1.0}/templates/github-repo.json +1 -1
  22. {searchfetch-3.3.4 → searchfetch-4.1.0}/templates/gitlab.json +1 -1
  23. {searchfetch-3.3.4 → searchfetch-4.1.0}/templates/go-pkg.json +1 -1
  24. {searchfetch-3.3.4 → searchfetch-4.1.0}/templates/google-search.json +3 -1
  25. {searchfetch-3.3.4 → searchfetch-4.1.0}/templates/javadoc.json +1 -1
  26. {searchfetch-3.3.4 → searchfetch-4.1.0}/templates/mdn-web-docs.json +1 -1
  27. {searchfetch-3.3.4 → searchfetch-4.1.0}/templates/npm-package.json +1 -1
  28. {searchfetch-3.3.4 → searchfetch-4.1.0}/templates/pypi-package.json +1 -1
  29. {searchfetch-3.3.4 → searchfetch-4.1.0}/templates/raw.json +1 -1
  30. {searchfetch-3.3.4 → searchfetch-4.1.0}/templates/reddit.json +1 -1
  31. {searchfetch-3.3.4 → searchfetch-4.1.0}/templates/wikipedia.json +1 -1
  32. {searchfetch-3.3.4 → searchfetch-4.1.0}/templates/youtube.json +1 -1
  33. searchfetch-4.1.0/tests/e2e/node.mjs +186 -0
  34. searchfetch-4.1.0/tests/e2e/python.py +188 -0
  35. searchfetch-4.1.0/tests/fixtures/composition.json +168 -0
  36. searchfetch-4.1.0/tests/fixtures/extraction.json +28 -0
  37. searchfetch-4.1.0/tests/fixtures/page.html +12 -0
  38. searchfetch-4.1.0/tests/fixtures/templates.json +168 -0
  39. searchfetch-4.1.0/tests/node/browser.test.js +288 -0
  40. searchfetch-4.1.0/tests/node/builtin-templates.test.js +45 -0
  41. searchfetch-4.1.0/tests/node/compose.test.js +137 -0
  42. searchfetch-4.1.0/tests/node/extract.test.js +468 -0
  43. searchfetch-4.1.0/tests/node/fake-browser.js +45 -0
  44. searchfetch-4.1.0/tests/node/server.test.js +307 -0
  45. searchfetch-4.1.0/tests/node/templates.test.js +452 -0
  46. searchfetch-4.1.0/tests/python/conftest.py +103 -0
  47. searchfetch-4.1.0/tests/python/test_browser.py +474 -0
  48. searchfetch-4.1.0/tests/python/test_compose.py +155 -0
  49. searchfetch-4.1.0/tests/python/test_extract.py +386 -0
  50. searchfetch-4.1.0/tests/python/test_markdown.py +119 -0
  51. searchfetch-4.1.0/tests/python/test_server.py +378 -0
  52. searchfetch-4.1.0/tests/python/test_templates.py +756 -0
  53. searchfetch-3.3.4/MANIFEST.in +0 -1
  54. searchfetch-3.3.4/PKG-INFO +0 -166
  55. searchfetch-3.3.4/README.md +0 -142
  56. searchfetch-3.3.4/pyproject.toml +0 -57
  57. searchfetch-3.3.4/searchfetch.egg-info/PKG-INFO +0 -166
  58. searchfetch-3.3.4/searchfetch.egg-info/SOURCES.txt +0 -32
  59. searchfetch-3.3.4/searchfetch.egg-info/dependency_links.txt +0 -1
  60. searchfetch-3.3.4/searchfetch.egg-info/entry_points.txt +0 -2
  61. searchfetch-3.3.4/searchfetch.egg-info/requires.txt +0 -11
  62. searchfetch-3.3.4/searchfetch.egg-info/top_level.txt +0 -3
  63. searchfetch-3.3.4/selectors_utils.py +0 -31
  64. searchfetch-3.3.4/server.py +0 -1270
  65. searchfetch-3.3.4/setup.cfg +0 -4
  66. searchfetch-3.3.4/templates/__init__.py +0 -1
  67. {searchfetch-3.3.4 → searchfetch-4.1.0}/LICENSE +0 -0
@@ -0,0 +1,51 @@
1
+ # =========================
2
+ # Node.js
3
+ # =========================
4
+ node_modules/
5
+ npm-debug.log*
6
+ yarn-debug.log*
7
+ yarn-error.log*
8
+ .pnpm-debug.log*
9
+
10
+ # =========================
11
+ # Python
12
+ # =========================
13
+ __pycache__/
14
+ *.py[cod]
15
+ *$py.class
16
+ *.so
17
+ build/
18
+ develop-eggs/
19
+ dist/
20
+ downloads/
21
+ eggs/
22
+ .eggs/
23
+ lib64/
24
+ parts/
25
+ sdist/
26
+ var/
27
+ wheels/
28
+ *.egg-info/
29
+ .installed.cfg
30
+ *.egg
31
+
32
+ # =========================
33
+ # Virtual Environments
34
+ # =========================
35
+ venv/
36
+ .venv/
37
+ env/
38
+ .env
39
+
40
+ # =========================
41
+ # OS / IDE / Caching
42
+ # =========================
43
+ .DS_Store
44
+ .vscode/
45
+ .idea/
46
+ *.swp
47
+ *.swo
48
+ .cache/
49
+ .pytest_cache/
50
+ .ruff_cache/
51
+ .cloakbrowser/
@@ -0,0 +1,194 @@
1
+ Metadata-Version: 2.5
2
+ Name: searchfetch
3
+ Version: 4.1.0
4
+ Summary: Fault-tolerant MCP server for stealth web search and page fetching
5
+ Project-URL: Homepage, https://github.com/maxylev/searchfetch
6
+ Project-URL: Repository, https://github.com/maxylev/searchfetch
7
+ Author: Max
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: agent,ai,fetch,llm,mcp,search,stealth
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Topic :: Internet :: WWW/HTTP :: Indexing/Search
13
+ Requires-Python: >=3.11.5
14
+ Requires-Dist: beautifulsoup4>=4.15.0
15
+ Requires-Dist: cloakbrowser<0.7,>=0.6.5
16
+ Requires-Dist: markdownify>=1.2.4
17
+ Requires-Dist: mcp>=2.3.0
18
+ Requires-Dist: playwright<1.65,>=1.64.0
19
+ Requires-Dist: pydantic>=2.14.4
20
+ Requires-Dist: soupsieve>=4.1.3
21
+ Provides-Extra: dev
22
+ Requires-Dist: pytest>=9.2.0; extra == 'dev'
23
+ Requires-Dist: ruff>=0.17.6; extra == 'dev'
24
+ Description-Content-Type: text/markdown
25
+
26
+ # SearchFetch
27
+
28
+ An [MCP](https://modelcontextprotocol.io) server that gives AI agents web search and page
29
+ fetching through a stealth browser. Pages are rendered with JavaScript, stripped of noise, and
30
+ returned as compact Markdown.
31
+
32
+ - **Browser rendering:** [CloakBrowser](https://github.com/CloakHQ/CloakBrowser) runs Chromium
33
+ with humanized input. Each fetch uses an isolated browser context. Sites may still demand
34
+ logins or challenges.
35
+ - **Fault tolerance:** relaunches a disconnected browser and retries timeouts, network failures
36
+ and HTTP 429 (honoring `Retry-After`, capped at 30 s) once. Built-in search engines fall back
37
+ to DuckDuckGo HTML and then DuckDuckGo Lite.
38
+ - **Token-efficient output:** scripts, styles, SVGs, inline styles and embedded `data:` images
39
+ are removed before conversion; images, media and fonts are blocked at the network layer.
40
+ - **Template-driven extraction:** JSON templates for GitHub, GitLab, npm, PyPI, crates.io,
41
+ docs.rs, Docker Hub, Wikipedia, MDN, Reddit, YouTube, DEV, pkg.go.dev, Javadoc and generic
42
+ documentation sites. Custom templates can be passed inline.
43
+ - **Two runtimes:** Python (`uvx`, Python 3.11.5+) or Node.js (`npx`, Node 24+), with the same
44
+ tools, templates and output. The first run downloads the browser binary.
45
+
46
+ ## Setup
47
+
48
+ No manual install is needed. Point your MCP client at `uvx` or `npx`:
49
+
50
+ ```json
51
+ {
52
+ "mcpServers": {
53
+ "searchfetch": {
54
+ "command": "uvx",
55
+ "args": ["searchfetch"]
56
+ }
57
+ }
58
+ }
59
+ ```
60
+
61
+ For Node.js, use `"command": "npx", "args": ["-y", "searchfetch"]`. In Cursor, add a `command`
62
+ server with `uvx searchfetch` or `npx -y searchfetch`.
63
+
64
+ ## Tools
65
+
66
+ Both tools are read-only. Failures are returned as MCP tool errors.
67
+
68
+ ### `websearch`
69
+
70
+ | Parameter | Type | Default | Description |
71
+ | ------------- | ------------ | -------------- | --------------------------------------------------------------------------------- |
72
+ | `query` | string | _required_ | Search query (must not be blank). |
73
+ | `engine` | string | `"duckduckgo"` | `"duckduckgo"`, `"google"`, a search template name, or an inline JSON template. |
74
+ | `region` | string/null | `null` | Region-language code such as `"us-en"`. DuckDuckGo: `kl`; Google: `gl` and `hl`. |
75
+ | `safe_search` | boolean/null | `null` | `true` or `false` sets the engine's safe search; `null` keeps the engine default. |
76
+ | `max_results` | integer | `10` | Maximum results (positive). |
77
+ | `block_media` | boolean | `true` | Block images, media and fonts at the network layer. |
78
+
79
+ Results are a numbered list of titles, URLs and snippets. When an engine fails or returns no
80
+ results, the next template in its `fallback` chain is tried (`google` → `duckduckgo-search` →
81
+ `duckduckgo-lite-search`), and a `[websearch: …]` note at the top of the output explains why.
82
+
83
+ ### `webfetch`
84
+
85
+ | Parameter | Type | Default | Description |
86
+ | ------------- | ------- | ---------- | ------------------------------------------------------------------- |
87
+ | `url` | string | _required_ | Absolute `http`/`https` URL. |
88
+ | `template` | string | `"auto"` | `"auto"` (detect by URL), a template name, or inline JSON template. |
89
+ | `start_index` | integer | `0` | Start offset in Unicode code points (non-negative). |
90
+ | `max_length` | integer | `10000` | Maximum code points to return (positive). |
91
+ | `block_media` | boolean | `true` | Block images, media and fonts at the network layer. |
92
+
93
+ Output ends with a footer naming the template and the character window, plus the next
94
+ `start_index` when more content remains. Pages that match no template are converted whole after
95
+ removing navigation, headers, footers, sidebars, dialogs and media (`template="auto (fallback)"`).
96
+ The `raw` template converts the full `<body>` with no removal.
97
+
98
+ ## Templates
99
+
100
+ Built-in templates live in [`templates/`](templates/) and are shared by both runtimes. Page
101
+ templates: `github-repo`, `github-issue`, `npm-package`, `pypi-package`, `crates-package`,
102
+ `docs-rs`, `javadoc`, `docs-page`, `docker-hub`, `wikipedia`, `gitlab`, `reddit`,
103
+ `mdn-web-docs`, `devto`, `go-pkg`, `youtube`, `raw`. Search templates: `google-search`,
104
+ `duckduckgo-search`, `duckduckgo-lite-search`.
105
+
106
+ Templates are validated when they are loaded or passed inline:
107
+
108
+ | Field | Description |
109
+ | ----------------- | ------------------------------------------------------------------------------------------------ |
110
+ | `name` | Required unique name (inline templates default to `"custom"`). |
111
+ | `sections` | Required list of sections (see below). |
112
+ | `order` | Precedence for `auto` detection; lower wins. |
113
+ | `url_patterns` | Regular expressions (compatible with JavaScript and Python) that select the template for `auto`. |
114
+ | `remove` | CSS selectors removed before extraction. Defaults to scripts, styles, SVG, nav, footer, iframes. |
115
+ | `source_url` | Raw Markdown source tried first, e.g. `"{url}.md"`; HTML responses are ignored. |
116
+ | `cookies` | Playwright cookies added to the browser context. |
117
+ | `block_resources` | Resource types blocked when `block_media` is on. Default: `image`, `media`, `font`. |
118
+ | `url_template` | Search URL with `{placeholders}`; makes the template usable by `websearch`. |
119
+ | `url_params` | Per placeholder: `required`, `default`, and `encode: "url"`. |
120
+ | `engine` | `"duckduckgo"` or `"google"`: how `region` and `safe_search` map to URL parameters. |
121
+ | `fallback` | Name of the search template to try when this one fails. |
122
+
123
+ Each section has a `name`, a `selector` (empty selects `<body>`), and optionally `format` (`text`, `markdown`,
124
+ `attribute` with `attribute`, or `html`), `transform` (one or a list of `strip`,
125
+ `decode_google_url`, `decode_ddg_url`, `json_parse`, `resolve_href`), `required`, `multiple`,
126
+ `max_items`, and `children` (fields extracted from inside each matched element).
127
+
128
+ Selectors separated by top-level commas are ordered fallbacks: the first selector that matches
129
+ wins, and an empty fallback selects the current element. Children search inside their parent
130
+ element and its ancestors, never neighbouring results, so a missing field stays missing. Missing
131
+ `required` sections or fields are reported as errors.
132
+
133
+ A records section whose first item has `Author`/`User` and `Comment`/`Body` fields is rendered as
134
+ a comment thread; other records render as indented `Key: value` blocks.
135
+
136
+ ## Development
137
+
138
+ ```bash
139
+ npm ci && uv sync --locked --extra dev
140
+ git config core.hooksPath .githooks # optional: format, lint and unit tests before commits
141
+
142
+ npm test # Node (node:test) and Python (pytest) unit tests
143
+ npm run lint # ESLint and Ruff
144
+ npm run format # Prettier and Ruff format (format:check to verify)
145
+ npm run e2e # real browser against local fixtures, plus the packed npm and wheel builds
146
+ npm run check # everything CI runs
147
+ npm run inspect:node # MCP Inspector (inspect:py for Python)
148
+ ```
149
+
150
+ ### Layout
151
+
152
+ | Path | Contents |
153
+ | ---------------------------- | ------------------------------------------------------------------------- |
154
+ | `src/` | Node.js runtime (`index.js` is the `searchfetch` executable). |
155
+ | `searchfetch/` | Python package (`python -m searchfetch` or the `searchfetch` script). |
156
+ | `templates/` | Shared templates; bundled into the npm package and the Python wheel. |
157
+ | `tests/fixtures/` | Shared fixtures that keep both runtimes' extraction and output identical. |
158
+ | `tests/node`, `tests/python` | Unit tests. |
159
+ | `tests/e2e/` | MCP end-to-end tests over stdio against a local HTTP server. |
160
+
161
+ The runtimes mirror each other module for module (`templates`, `extract`, `markdown`, `compose`,
162
+ `browser`, `server`). Any change to one should be made to the other, with a shared fixture if
163
+ the behavior is observable.
164
+
165
+ ### Releasing
166
+
167
+ Bump `version` in both `package.json` and `pyproject.toml` (then `npm install` and `uv lock`),
168
+ commit, and push a matching tag:
169
+
170
+ ```sh
171
+ git tag -a v4.1.1 -m "v4.1.1" && git push origin main v4.1.1
172
+ ```
173
+
174
+ The Publish workflow checks that the tag matches both versions, runs lint and unit tests, stages
175
+ the npm release, publishes to PyPI, and then creates the GitHub Release with generated notes. To
176
+ retry a tag, run the workflow manually from the Actions tab with that tag.
177
+
178
+ Both registries use trusted publishing (OIDC), so no tokens are stored in the repository. The npm
179
+ trusted publisher (`maxylev/searchfetch`, workflow `publish.yml`) allows staged publishing only:
180
+ CI runs `npm stage publish` with automatic provenance, and the version goes live after a
181
+ maintainer approves it with 2FA on npmjs.com or with `npm stage list searchfetch` and
182
+ `npm stage approve <stage-id>`. PyPI publishes from the `pypi` environment.
183
+
184
+ ### Limits
185
+
186
+ - HTML-to-Markdown conversion uses turndown (Node) and markdownify (Python). They agree on
187
+ common content, but edge cases such as tables differ.
188
+ - After the DOM is ready, each fetch waits up to five seconds for network activity to settle.
189
+ Pages that keep rendering after that may return partial content.
190
+ - CloakBrowser is held at 0.6.x in both runtimes: 0.7 requires a license key (free with email,
191
+ one concurrent session) on every launch and fails without a terminal unless
192
+ `CLOAKBROWSER_LICENSE_KEY` is set, which would break zero-config `uvx`/`npx` use.
193
+ - E2E tests use local fixtures. Live search-engine availability and third-party page layouts
194
+ change over time and need separate live checks.
@@ -0,0 +1,169 @@
1
+ # SearchFetch
2
+
3
+ An [MCP](https://modelcontextprotocol.io) server that gives AI agents web search and page
4
+ fetching through a stealth browser. Pages are rendered with JavaScript, stripped of noise, and
5
+ returned as compact Markdown.
6
+
7
+ - **Browser rendering:** [CloakBrowser](https://github.com/CloakHQ/CloakBrowser) runs Chromium
8
+ with humanized input. Each fetch uses an isolated browser context. Sites may still demand
9
+ logins or challenges.
10
+ - **Fault tolerance:** relaunches a disconnected browser and retries timeouts, network failures
11
+ and HTTP 429 (honoring `Retry-After`, capped at 30 s) once. Built-in search engines fall back
12
+ to DuckDuckGo HTML and then DuckDuckGo Lite.
13
+ - **Token-efficient output:** scripts, styles, SVGs, inline styles and embedded `data:` images
14
+ are removed before conversion; images, media and fonts are blocked at the network layer.
15
+ - **Template-driven extraction:** JSON templates for GitHub, GitLab, npm, PyPI, crates.io,
16
+ docs.rs, Docker Hub, Wikipedia, MDN, Reddit, YouTube, DEV, pkg.go.dev, Javadoc and generic
17
+ documentation sites. Custom templates can be passed inline.
18
+ - **Two runtimes:** Python (`uvx`, Python 3.11.5+) or Node.js (`npx`, Node 24+), with the same
19
+ tools, templates and output. The first run downloads the browser binary.
20
+
21
+ ## Setup
22
+
23
+ No manual install is needed. Point your MCP client at `uvx` or `npx`:
24
+
25
+ ```json
26
+ {
27
+ "mcpServers": {
28
+ "searchfetch": {
29
+ "command": "uvx",
30
+ "args": ["searchfetch"]
31
+ }
32
+ }
33
+ }
34
+ ```
35
+
36
+ For Node.js, use `"command": "npx", "args": ["-y", "searchfetch"]`. In Cursor, add a `command`
37
+ server with `uvx searchfetch` or `npx -y searchfetch`.
38
+
39
+ ## Tools
40
+
41
+ Both tools are read-only. Failures are returned as MCP tool errors.
42
+
43
+ ### `websearch`
44
+
45
+ | Parameter | Type | Default | Description |
46
+ | ------------- | ------------ | -------------- | --------------------------------------------------------------------------------- |
47
+ | `query` | string | _required_ | Search query (must not be blank). |
48
+ | `engine` | string | `"duckduckgo"` | `"duckduckgo"`, `"google"`, a search template name, or an inline JSON template. |
49
+ | `region` | string/null | `null` | Region-language code such as `"us-en"`. DuckDuckGo: `kl`; Google: `gl` and `hl`. |
50
+ | `safe_search` | boolean/null | `null` | `true` or `false` sets the engine's safe search; `null` keeps the engine default. |
51
+ | `max_results` | integer | `10` | Maximum results (positive). |
52
+ | `block_media` | boolean | `true` | Block images, media and fonts at the network layer. |
53
+
54
+ Results are a numbered list of titles, URLs and snippets. When an engine fails or returns no
55
+ results, the next template in its `fallback` chain is tried (`google` → `duckduckgo-search` →
56
+ `duckduckgo-lite-search`), and a `[websearch: …]` note at the top of the output explains why.
57
+
58
+ ### `webfetch`
59
+
60
+ | Parameter | Type | Default | Description |
61
+ | ------------- | ------- | ---------- | ------------------------------------------------------------------- |
62
+ | `url` | string | _required_ | Absolute `http`/`https` URL. |
63
+ | `template` | string | `"auto"` | `"auto"` (detect by URL), a template name, or inline JSON template. |
64
+ | `start_index` | integer | `0` | Start offset in Unicode code points (non-negative). |
65
+ | `max_length` | integer | `10000` | Maximum code points to return (positive). |
66
+ | `block_media` | boolean | `true` | Block images, media and fonts at the network layer. |
67
+
68
+ Output ends with a footer naming the template and the character window, plus the next
69
+ `start_index` when more content remains. Pages that match no template are converted whole after
70
+ removing navigation, headers, footers, sidebars, dialogs and media (`template="auto (fallback)"`).
71
+ The `raw` template converts the full `<body>` with no removal.
72
+
73
+ ## Templates
74
+
75
+ Built-in templates live in [`templates/`](templates/) and are shared by both runtimes. Page
76
+ templates: `github-repo`, `github-issue`, `npm-package`, `pypi-package`, `crates-package`,
77
+ `docs-rs`, `javadoc`, `docs-page`, `docker-hub`, `wikipedia`, `gitlab`, `reddit`,
78
+ `mdn-web-docs`, `devto`, `go-pkg`, `youtube`, `raw`. Search templates: `google-search`,
79
+ `duckduckgo-search`, `duckduckgo-lite-search`.
80
+
81
+ Templates are validated when they are loaded or passed inline:
82
+
83
+ | Field | Description |
84
+ | ----------------- | ------------------------------------------------------------------------------------------------ |
85
+ | `name` | Required unique name (inline templates default to `"custom"`). |
86
+ | `sections` | Required list of sections (see below). |
87
+ | `order` | Precedence for `auto` detection; lower wins. |
88
+ | `url_patterns` | Regular expressions (compatible with JavaScript and Python) that select the template for `auto`. |
89
+ | `remove` | CSS selectors removed before extraction. Defaults to scripts, styles, SVG, nav, footer, iframes. |
90
+ | `source_url` | Raw Markdown source tried first, e.g. `"{url}.md"`; HTML responses are ignored. |
91
+ | `cookies` | Playwright cookies added to the browser context. |
92
+ | `block_resources` | Resource types blocked when `block_media` is on. Default: `image`, `media`, `font`. |
93
+ | `url_template` | Search URL with `{placeholders}`; makes the template usable by `websearch`. |
94
+ | `url_params` | Per placeholder: `required`, `default`, and `encode: "url"`. |
95
+ | `engine` | `"duckduckgo"` or `"google"`: how `region` and `safe_search` map to URL parameters. |
96
+ | `fallback` | Name of the search template to try when this one fails. |
97
+
98
+ Each section has a `name`, a `selector` (empty selects `<body>`), and optionally `format` (`text`, `markdown`,
99
+ `attribute` with `attribute`, or `html`), `transform` (one or a list of `strip`,
100
+ `decode_google_url`, `decode_ddg_url`, `json_parse`, `resolve_href`), `required`, `multiple`,
101
+ `max_items`, and `children` (fields extracted from inside each matched element).
102
+
103
+ Selectors separated by top-level commas are ordered fallbacks: the first selector that matches
104
+ wins, and an empty fallback selects the current element. Children search inside their parent
105
+ element and its ancestors, never neighbouring results, so a missing field stays missing. Missing
106
+ `required` sections or fields are reported as errors.
107
+
108
+ A records section whose first item has `Author`/`User` and `Comment`/`Body` fields is rendered as
109
+ a comment thread; other records render as indented `Key: value` blocks.
110
+
111
+ ## Development
112
+
113
+ ```bash
114
+ npm ci && uv sync --locked --extra dev
115
+ git config core.hooksPath .githooks # optional: format, lint and unit tests before commits
116
+
117
+ npm test # Node (node:test) and Python (pytest) unit tests
118
+ npm run lint # ESLint and Ruff
119
+ npm run format # Prettier and Ruff format (format:check to verify)
120
+ npm run e2e # real browser against local fixtures, plus the packed npm and wheel builds
121
+ npm run check # everything CI runs
122
+ npm run inspect:node # MCP Inspector (inspect:py for Python)
123
+ ```
124
+
125
+ ### Layout
126
+
127
+ | Path | Contents |
128
+ | ---------------------------- | ------------------------------------------------------------------------- |
129
+ | `src/` | Node.js runtime (`index.js` is the `searchfetch` executable). |
130
+ | `searchfetch/` | Python package (`python -m searchfetch` or the `searchfetch` script). |
131
+ | `templates/` | Shared templates; bundled into the npm package and the Python wheel. |
132
+ | `tests/fixtures/` | Shared fixtures that keep both runtimes' extraction and output identical. |
133
+ | `tests/node`, `tests/python` | Unit tests. |
134
+ | `tests/e2e/` | MCP end-to-end tests over stdio against a local HTTP server. |
135
+
136
+ The runtimes mirror each other module for module (`templates`, `extract`, `markdown`, `compose`,
137
+ `browser`, `server`). Any change to one should be made to the other, with a shared fixture if
138
+ the behavior is observable.
139
+
140
+ ### Releasing
141
+
142
+ Bump `version` in both `package.json` and `pyproject.toml` (then `npm install` and `uv lock`),
143
+ commit, and push a matching tag:
144
+
145
+ ```sh
146
+ git tag -a v4.1.1 -m "v4.1.1" && git push origin main v4.1.1
147
+ ```
148
+
149
+ The Publish workflow checks that the tag matches both versions, runs lint and unit tests, stages
150
+ the npm release, publishes to PyPI, and then creates the GitHub Release with generated notes. To
151
+ retry a tag, run the workflow manually from the Actions tab with that tag.
152
+
153
+ Both registries use trusted publishing (OIDC), so no tokens are stored in the repository. The npm
154
+ trusted publisher (`maxylev/searchfetch`, workflow `publish.yml`) allows staged publishing only:
155
+ CI runs `npm stage publish` with automatic provenance, and the version goes live after a
156
+ maintainer approves it with 2FA on npmjs.com or with `npm stage list searchfetch` and
157
+ `npm stage approve <stage-id>`. PyPI publishes from the `pypi` environment.
158
+
159
+ ### Limits
160
+
161
+ - HTML-to-Markdown conversion uses turndown (Node) and markdownify (Python). They agree on
162
+ common content, but edge cases such as tables differ.
163
+ - After the DOM is ready, each fetch waits up to five seconds for network activity to settle.
164
+ Pages that keep rendering after that may return partial content.
165
+ - CloakBrowser is held at 0.6.x in both runtimes: 0.7 requires a license key (free with email,
166
+ one concurrent session) on every launch and fails without a terminal unless
167
+ `CLOAKBROWSER_LICENSE_KEY` is set, which would break zero-config `uvx`/`npx` use.
168
+ - E2E tests use local fixtures. Live search-engine availability and third-party page layouts
169
+ change over time and need separate live checks.
@@ -0,0 +1,65 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.33"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "searchfetch"
7
+ version = "4.1.0"
8
+ description = "Fault-tolerant MCP server for stealth web search and page fetching"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.11.5"
13
+ authors = [{ name = "Max" }]
14
+ keywords = ["mcp", "search", "fetch", "llm", "ai", "agent", "stealth"]
15
+ classifiers = [
16
+ "Programming Language :: Python :: 3",
17
+ "Topic :: Internet :: WWW/HTTP :: Indexing/Search",
18
+ ]
19
+ dependencies = [
20
+ "beautifulsoup4>=4.15.0",
21
+ # CloakBrowser 0.7 requires a license key on every launch; see README "Limits".
22
+ "cloakbrowser>=0.6.5,<0.7",
23
+ "markdownify>=1.2.4",
24
+ "mcp>=2.3.0",
25
+ # CloakBrowser 0.6 imports playwright._impl._js_handle, which Playwright 1.65 removed.
26
+ "playwright>=1.64.0,<1.65",
27
+ "pydantic>=2.14.4",
28
+ "soupsieve>=4.1.3",
29
+ ]
30
+
31
+ [project.optional-dependencies]
32
+ dev = ["pytest>=9.2.0", "ruff>=0.17.6"]
33
+
34
+ [project.urls]
35
+ Homepage = "https://github.com/maxylev/searchfetch"
36
+ Repository = "https://github.com/maxylev/searchfetch"
37
+
38
+ [project.scripts]
39
+ searchfetch = "searchfetch.server:main"
40
+
41
+ [tool.hatch.build.targets.wheel]
42
+ packages = ["searchfetch"]
43
+
44
+ # Templates live at the repository root so both runtimes share them; bundle them in the wheel.
45
+ [tool.hatch.build.targets.wheel.force-include]
46
+ "templates" = "searchfetch/templates"
47
+
48
+ [tool.hatch.build.targets.sdist]
49
+ include = ["searchfetch/", "templates/", "tests/", "README.md", "LICENSE"]
50
+
51
+ [tool.pytest.ini_options]
52
+ testpaths = ["tests/python"]
53
+ addopts = "-q"
54
+
55
+ [tool.ruff]
56
+ line-length = 100
57
+ target-version = "py311"
58
+ extend-exclude = ["node_modules"]
59
+
60
+ [tool.ruff.lint]
61
+ select = ["E", "F", "I", "W", "UP", "B", "SIM", "RUF"]
62
+
63
+ [tool.ruff.format]
64
+ quote-style = "double"
65
+ indent-style = "space"
@@ -0,0 +1,5 @@
1
+ """SearchFetch: an MCP server for stealth web search and page fetching."""
2
+
3
+ from importlib.metadata import version
4
+
5
+ __version__ = version("searchfetch")
@@ -0,0 +1,3 @@
1
+ from searchfetch.server import main
2
+
3
+ main()