@j0hanz/superfetch 2.5.3 → 2.7.0

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 (46) hide show
  1. package/README.md +350 -226
  2. package/dist/assets/logo.svg +24837 -24835
  3. package/dist/cache.d.ts +28 -20
  4. package/dist/cache.js +292 -512
  5. package/dist/config.d.ts +41 -7
  6. package/dist/config.js +316 -154
  7. package/dist/crypto.js +25 -12
  8. package/dist/dom-noise-removal.js +382 -421
  9. package/dist/errors.d.ts +2 -2
  10. package/dist/errors.js +25 -8
  11. package/dist/fetch.d.ts +19 -16
  12. package/dist/fetch.js +1207 -538
  13. package/dist/host-normalization.js +40 -10
  14. package/dist/http-native.js +641 -283
  15. package/dist/index.js +67 -7
  16. package/dist/instructions.md +44 -31
  17. package/dist/ip-blocklist.d.ts +8 -0
  18. package/dist/ip-blocklist.js +65 -0
  19. package/dist/json.js +14 -9
  20. package/dist/language-detection.d.ts +2 -11
  21. package/dist/language-detection.js +313 -280
  22. package/dist/markdown-cleanup.d.ts +0 -1
  23. package/dist/markdown-cleanup.js +391 -429
  24. package/dist/mcp-validator.js +4 -2
  25. package/dist/mcp.js +191 -136
  26. package/dist/observability.js +89 -21
  27. package/dist/resources.js +16 -6
  28. package/dist/server-tuning.d.ts +2 -0
  29. package/dist/server-tuning.js +25 -23
  30. package/dist/session.d.ts +1 -0
  31. package/dist/session.js +41 -33
  32. package/dist/tasks.d.ts +3 -0
  33. package/dist/tasks.js +167 -51
  34. package/dist/timer-utils.d.ts +5 -0
  35. package/dist/timer-utils.js +20 -0
  36. package/dist/tools.d.ts +30 -5
  37. package/dist/tools.js +319 -184
  38. package/dist/transform-types.d.ts +6 -1
  39. package/dist/transform.d.ts +3 -2
  40. package/dist/transform.js +1243 -421
  41. package/dist/type-guards.d.ts +1 -0
  42. package/dist/type-guards.js +7 -0
  43. package/dist/workers/transform-child.d.ts +1 -0
  44. package/dist/workers/transform-child.js +118 -0
  45. package/dist/workers/transform-worker.js +87 -78
  46. package/package.json +14 -6
package/README.md CHANGED
@@ -4,18 +4,15 @@
4
4
 
5
5
  <img src="assets/logo.svg" alt="SuperFetch MCP Logo" width="300">
6
6
 
7
- [![npm version](https://img.shields.io/npm/v/@j0hanz/superfetch.svg)](https://www.npmjs.com/package/@j0hanz/superfetch) [![license](https://img.shields.io/npm/l/@j0hanz/superfetch.svg)](https://www.npmjs.com/package/@j0hanz/superfetch) [![Node.js](https://img.shields.io/badge/Node.js-%3E=20.18.1-339933?logo=nodedotjs&logoColor=white)](https://nodejs.org/) [![TypeScript](https://img.shields.io/badge/TypeScript-5.9-3178C6?logo=typescript&logoColor=white)](https://www.typescriptlang.org/) [![MCP SDK](https://img.shields.io/badge/MCP%20SDK-1.25.x-6f42c1)](https://github.com/modelcontextprotocol/sdk)
7
+ [![npm version](https://img.shields.io/npm/v/%40j0hanz%2Fsuperfetch)](https://www.npmjs.com/package/@j0hanz/superfetch) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) [![Node.js](https://img.shields.io/badge/node-%3E%3D24-brightgreen)](https://nodejs.org) [![TypeScript](https://img.shields.io/badge/TypeScript-5.9-blue)](https://www.typescriptlang.org) [![MCP SDK](https://img.shields.io/badge/MCP%20SDK-1.26-purple)](https://modelcontextprotocol.io)
8
8
 
9
- [![Install with NPX in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://insiders.vscode.dev/redirect/mcp/install?name=superfetch&inputs=%5B%5D&config=%7B%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40j0hanz%2Fsuperfetch%40latest%22%2C%22--stdio%22%5D%7D) [![Install with NPX in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://insiders.vscode.dev/redirect/mcp/install?name=superfetch&inputs=%5B%5D&config=%7B%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40j0hanz%2Fsuperfetch%40latest%22%2C%22--stdio%22%5D%7D&quality=insiders) [![Install in Claude Desktop](https://img.shields.io/badge/Claude_Desktop-Install-ff9800?style=flat-square&logo=anthropic&logoColor=white)](https://claude.ai/desktop/mcp/install?name=superfetch&config=%7B%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40j0hanz%2Fsuperfetch%40latest%22%2C%22--stdio%22%5D%7D)
9
+ [![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0078d7?logo=visual-studio-code&logoColor=white)](https://insiders.vscode.dev/redirect?url=vscode%3Amcp%2Finstall%3F%7B%22name%22%3A%22superfetch%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40j0hanz%2Fsuperfetch%40latest%22%2C%22--stdio%22%5D%7D) [![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?logo=visual-studio-code&logoColor=white)](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Amcp%2Finstall%3F%7B%22name%22%3A%22superfetch%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40j0hanz%2Fsuperfetch%40latest%22%2C%22--stdio%22%5D%7D) [![Install in Cursor](https://img.shields.io/badge/Cursor-Install-f97316?logo=cursor&logoColor=white)](https://cursor.com/install-mcp?name=superfetch&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkBqMGhhbnovc3VwZXJmZXRjaEBsYXRlc3QiLCItLXN0ZGlvIl19)
10
10
 
11
- Fetch and convert public web pages to clean, AI-friendly Markdown via MCP.
11
+ Fetch and convert public web content to clean Markdown both readable by humans and optimized for LLM context.
12
12
 
13
13
  ## Overview
14
14
 
15
- SuperFetch is a Node.js MCP server that fetches public HTTP(S) pages, extracts
16
- primary content, and converts it into clean Markdown. It runs either as a stdio
17
- MCP server (for local clients) or as a Streamable HTTP MCP server with auth,
18
- cache, and SSRF protections.
15
+ superFetch is a [Model Context Protocol](https://modelcontextprotocol.io) (MCP) server that fetches public web pages, extracts meaningful content using Mozilla's Readability algorithm, and converts the result into clean Markdown optimized for LLM context windows. It handles noise removal, caching, SSRF protection, async task execution, and supports both stdio and Streamable HTTP transports.
19
16
 
20
17
  ## Key Features
21
18
 
@@ -33,63 +30,93 @@ cache, and SSRF protections.
33
30
 
34
31
  ## Tech Stack
35
32
 
36
- - Runtime: Node.js >= 20.18.1 (engines)
37
- - Language: TypeScript 5.9.3 (dev dependency)
38
- - MCP SDK: @modelcontextprotocol/sdk ^1.25.3
39
- - HTML processing: @mozilla/readability ^0.6.0, linkedom ^0.18.12
40
- - Markdown conversion: node-html-markdown ^2.0.0
41
- - HTTP client: undici ^7.19.2
42
- - Validation: zod ^4.3.6
43
- - Package manager: npm (package-lock.json)
33
+ | Component | Technology |
34
+ | ------------------- | ----------------------------------- |
35
+ | Runtime | Node.js 24 |
36
+ | Language | TypeScript 5.9 |
37
+ | MCP SDK | `@modelcontextprotocol/sdk` ^1.26.0 |
38
+ | Content Extraction | `@mozilla/readability` ^0.6.0 |
39
+ | DOM Parsing | `linkedom` ^0.18.12 |
40
+ | Markdown Conversion | `node-html-markdown` ^2.0.0 |
41
+ | Schema Validation | `zod` ^4.3.6 |
42
+ | Package Manager | npm |
44
43
 
45
44
  ## Architecture
46
45
 
47
- Fetch pipeline (simplified):
46
+ ```text
47
+ URL → Validate → DNS Preflight → HTTP Fetch → Decompress
48
+ → Truncate HTML → Readability Extract → Noise Removal
49
+ → Markdown Convert → Cleanup Pipeline → Cache → Response
50
+ ```
48
51
 
49
- 1. Validate and normalize the URL (http/https only, max length 2048).
50
- 2. Block internal hosts and private IP ranges.
51
- 3. Rewrite supported repo URLs to raw content.
52
- 4. Fetch HTML with undici (15s timeout, 10 MB max, 5 redirects).
53
- 5. Extract main content with Readability + DOM cleanup.
54
- 6. Convert to Markdown, inject metadata, and return via MCP.
55
- 7. Cache the result and expose it as a resource or download.
52
+ 1. **URL Validation** Normalize, block private hosts, transform raw-content URLs (GitHub, GitLab, Bitbucket)
53
+ 2. **Fetch** HTTP request via `undici` with redirect following, DNS preflight SSRF checks, and size limits
54
+ 3. **Transform** Offloaded to worker threads: parse HTML with `linkedom`, extract with Readability, remove DOM noise, convert to Markdown
55
+ 4. **Cleanup** Multi-pass Markdown normalization (heading promotion, spacing, skip-link removal, TypeDoc comment stripping)
56
+ 5. **Cache + Respond** — Store result, apply inline content limits, return structured content with optional resource links
56
57
 
57
58
  ## Repository Structure
58
59
 
59
60
  ```text
60
- .
61
- ├── assets/ # Logo and static assets copied to dist
62
- ├── scripts/ # Build and validation utilities
63
- ├── src/ # MCP server implementation (TS)
64
- │ ├── workers/ # Worker-thread transform implementation
65
- ├── http-native.ts # Streamable HTTP server
66
- ├── mcp.ts # MCP server wiring
67
- │ ├── tools.ts # fetch-url tool implementation
68
- └── ...
69
- ├── tests/ # Node test runner tests (import dist)
70
- ├── CONFIGURATION.md # Full configuration reference
71
- ├── AGENTS.md # Agent guidance
61
+ superFetch/
62
+ ├── assets/
63
+ │ └── logo.svg
64
+ ├── scripts/
65
+ │ ├── tasks.mjs
66
+ └── validate-fetch.mjs
67
+ ├── src/
68
+ │ ├── workers/
69
+ │ ├── transform-child.ts
70
+ │ │ └── transform-worker.ts
71
+ ├── cache.ts
72
+ ├── config.ts
73
+ │ ├── crypto.ts
74
+ │ ├── dom-noise-removal.ts
75
+ │ ├── errors.ts
76
+ │ ├── fetch.ts
77
+ │ ├── host-normalization.ts
78
+ │ ├── http-native.ts
79
+ │ ├── index.ts
80
+ │ ├── instructions.md
81
+ │ ├── ip-blocklist.ts
82
+ │ ├── json.ts
83
+ │ ├── language-detection.ts
84
+ │ ├── markdown-cleanup.ts
85
+ │ ├── mcp-validator.ts
86
+ │ ├── mcp.ts
87
+ │ ├── observability.ts
88
+ │ ├── resources.ts
89
+ │ ├── server-tuning.ts
90
+ │ ├── session.ts
91
+ │ ├── tasks.ts
92
+ │ ├── timer-utils.ts
93
+ │ ├── tools.ts
94
+ │ ├── transform-types.ts
95
+ │ ├── transform.ts
96
+ │ └── type-guards.ts
97
+ ├── tests/
98
+ │ └── *.test.ts
72
99
  ├── package.json
73
- └── tsconfig.json
100
+ ├── tsconfig.json
101
+ └── AGENTS.md
74
102
  ```
75
103
 
76
104
  ## Requirements
77
105
 
78
- - Node.js >= 20.18.1
79
- - npm (uses package-lock.json)
106
+ - **Node.js** 24
80
107
 
81
- ## Quickstart (stdio)
108
+ ## Quickstart
82
109
 
83
110
  ```bash
84
111
  npx -y @j0hanz/superfetch@latest --stdio
85
112
  ```
86
113
 
87
- Example MCP client configuration:
114
+ Add to your MCP client configuration:
88
115
 
89
116
  ```json
90
117
  {
91
118
  "mcpServers": {
92
- "superFetch": {
119
+ "superfetch": {
93
120
  "command": "npx",
94
121
  "args": ["-y", "@j0hanz/superfetch@latest", "--stdio"]
95
122
  }
@@ -99,20 +126,22 @@ Example MCP client configuration:
99
126
 
100
127
  ## Installation
101
128
 
102
- ### NPX (recommended)
129
+ ### NPX (Recommended)
130
+
131
+ No installation required — runs directly:
103
132
 
104
133
  ```bash
105
134
  npx -y @j0hanz/superfetch@latest --stdio
106
135
  ```
107
136
 
108
- ### Global install
137
+ ### Global Install
109
138
 
110
139
  ```bash
111
140
  npm install -g @j0hanz/superfetch
112
141
  superfetch --stdio
113
142
  ```
114
143
 
115
- ### From source
144
+ ### From Source
116
145
 
117
146
  ```bash
118
147
  git clone https://github.com/j0hanz/super-fetch-mcp-server.git
@@ -124,105 +153,110 @@ node dist/index.js --stdio
124
153
 
125
154
  ## Configuration
126
155
 
127
- SuperFetch is configured entirely via environment variables. Set them in your
128
- MCP client configuration (the `env` field) or in the shell before starting the
129
- server. For the full reference, see `CONFIGURATION.md`.
130
-
131
- ### Runtime modes
132
-
133
- | Mode | Flag | Description |
134
- | ----- | --------- | ------------------------------------------------------------------- |
135
- | Stdio | `--stdio` | Communicates via stdin/stdout. No HTTP server. |
136
- | HTTP | (default) | Starts an HTTP server. Requires static token(s) or OAuth to be set. |
137
-
138
- ### CLI arguments
139
-
140
- | Argument | Type | Default | Description |
141
- | --------- | ------- | ------- | ----------------------------------- |
142
- | `--stdio` | boolean | false | Run in stdio mode (no HTTP server). |
143
-
144
- ### Core server settings
145
-
146
- | Variable | Default | Description |
147
- | ---------------------------------- | -------------------- | -------------------------------------------------------------- |
148
- | `HOST` | `127.0.0.1` | HTTP bind address. |
149
- | `PORT` | `3000` | HTTP port (1024-65535, `0` for ephemeral). |
150
- | `USER_AGENT` | `superFetch-MCP/2.0` | User-Agent for outbound requests. |
151
- | `CACHE_ENABLED` | `true` | Enable in-memory cache. |
152
- | `CACHE_TTL` | `3600` | Cache TTL in seconds (60-86400). |
153
- | `LOG_LEVEL` | `info` | Logging level (`debug`, `info`, `warn`, `error`). |
154
- | `ALLOW_REMOTE` | `false` | Allow non-loopback binds (OAuth required). |
155
- | `ALLOWED_HOSTS` | (empty) | Additional allowed Host/Origin values (comma/space separated). |
156
- | `TRANSFORM_TIMEOUT_MS` | `30000` | Worker transform timeout in ms (5000-120000). |
157
- | `TRANSFORM_STAGE_WARN_RATIO` | `0.5` | Emit warnings when stage exceeds ratio of timeout. |
158
- | `TOOL_TIMEOUT_MS` | computed | Overall tool timeout in ms (1000-300000). |
159
- | `TRANSFORM_METADATA_FORMAT` | `markdown` | Metadata format: `markdown` or `frontmatter`. |
160
- | `ENABLED_TOOLS` | `fetch-url` | Comma/space-separated list of enabled tools. |
161
- | `SUPERFETCH_EXTRA_NOISE_TOKENS` | (empty) | Extra noise tokens for DOM noise removal. |
162
- | `SUPERFETCH_EXTRA_NOISE_SELECTORS` | (empty) | Extra CSS selectors for DOM noise removal. |
163
-
164
- `TOOL_TIMEOUT_MS` defaults to 15s fetch + `TRANSFORM_TIMEOUT_MS` + 5s.
165
-
166
- ### HTTP server tuning (optional)
167
-
168
- | Variable | Default | Description |
169
- | ------------------------------ | ------- | --------------------------------------------- |
170
- | `SERVER_HEADERS_TIMEOUT_MS` | (unset) | Sets `server.headersTimeout` (1000-600000). |
171
- | `SERVER_REQUEST_TIMEOUT_MS` | (unset) | Sets `server.requestTimeout` (1000-600000). |
172
- | `SERVER_KEEP_ALIVE_TIMEOUT_MS` | (unset) | Sets `server.keepAliveTimeout` (1000-600000). |
173
- | `SERVER_SHUTDOWN_CLOSE_IDLE` | `false` | Close idle connections on shutdown. |
174
- | `SERVER_SHUTDOWN_CLOSE_ALL` | `false` | Close all connections on shutdown. |
175
-
176
- ### Auth (HTTP mode)
177
-
178
- | Variable | Default | Description |
179
- | --------------- | ------- | ----------------------------------------------------------- |
180
- | `AUTH_MODE` | auto | `static` or `oauth` (auto-selects OAuth when URLs are set). |
181
- | `ACCESS_TOKENS` | (empty) | Comma/space-separated static bearer tokens. |
182
- | `API_KEY` | (empty) | Adds a static bearer token and enables `X-API-Key`. |
183
-
184
- Static mode requires at least one token (`ACCESS_TOKENS` or `API_KEY`).
185
-
186
- ### OAuth (HTTP mode)
187
-
188
- Required when `AUTH_MODE=oauth` (or auto-selected by OAuth URLs):
189
-
190
- | Variable | Default | Description |
191
- | ------------------------- | ------- | ----------------------- |
192
- | `OAUTH_ISSUER_URL` | - | OAuth issuer. |
193
- | `OAUTH_AUTHORIZATION_URL` | - | Authorization endpoint. |
194
- | `OAUTH_TOKEN_URL` | - | Token endpoint. |
195
- | `OAUTH_INTROSPECTION_URL` | - | Introspection endpoint. |
196
-
197
- Optional:
198
-
199
- | Variable | Default | Description |
200
- | -------------------------------- | -------------------------- | ---------------------------------------- |
201
- | `OAUTH_REVOCATION_URL` | - | Revocation endpoint. |
202
- | `OAUTH_REGISTRATION_URL` | - | Dynamic client registration endpoint. |
203
- | `OAUTH_RESOURCE_URL` | `http://<host>:<port>/mcp` | Protected resource URL. |
204
- | `OAUTH_REQUIRED_SCOPES` | (empty) | Required scopes (comma/space separated). |
205
- | `OAUTH_CLIENT_ID` | - | Client ID for introspection. |
206
- | `OAUTH_CLIENT_SECRET` | - | Client secret for introspection. |
207
- | `OAUTH_INTROSPECTION_TIMEOUT_MS` | `5000` | Introspection timeout (1000-30000). |
156
+ ### Runtime Modes
157
+
158
+ | Flag | Description |
159
+ | ----------- | ------------------------------------------- |
160
+ | `--stdio` | Run in stdio mode (for desktop MCP clients) |
161
+ | `--help` | Show usage help |
162
+ | `--version` | Print server version |
163
+
164
+ When no `--stdio` flag is passed, the server starts in **HTTP mode** (Streamable HTTP on port 3000 by default).
165
+
166
+ ### Environment Variables
167
+
168
+ #### Core Settings
169
+
170
+ | Variable | Default | Description |
171
+ | ------------------ | -------------------------- | ------------------------------------------------------ |
172
+ | `HOST` | `127.0.0.1` | HTTP server bind address |
173
+ | `PORT` | `3000` | HTTP server port (1024–65535) |
174
+ | `LOG_LEVEL` | `info` | Log level: `debug`, `info`, `warn`, `error` |
175
+ | `FETCH_TIMEOUT_MS` | `15000` | HTTP fetch timeout in ms (1000–60000) |
176
+ | `CACHE_ENABLED` | `true` | Enable/disable in-memory content cache |
177
+ | `USER_AGENT` | `superFetch-MCP/{version}` | Custom User-Agent header |
178
+ | `ALLOW_REMOTE` | `false` | Allow remote connections in HTTP mode |
179
+ | `ALLOWED_HOSTS` | _(empty)_ | Comma-separated hostnames allowed to bypass block list |
180
+
181
+ #### Authentication (HTTP Mode)
182
+
183
+ | Variable | Default | Description |
184
+ | ------------------------- | --------- | --------------------------------------- |
185
+ | `ACCESS_TOKENS` | _(empty)_ | Comma-separated static bearer tokens |
186
+ | `API_KEY` | _(empty)_ | Single API key (added to static tokens) |
187
+ | `OAUTH_ISSUER_URL` | _(empty)_ | OAuth issuer URL (enables OAuth mode) |
188
+ | `OAUTH_AUTHORIZATION_URL` | _(empty)_ | OAuth authorization endpoint |
189
+ | `OAUTH_TOKEN_URL` | _(empty)_ | OAuth token endpoint |
190
+ | `OAUTH_INTROSPECTION_URL` | _(empty)_ | OAuth token introspection endpoint |
191
+ | `OAUTH_REVOCATION_URL` | _(empty)_ | OAuth token revocation endpoint |
192
+ | `OAUTH_REGISTRATION_URL` | _(empty)_ | OAuth dynamic client registration |
193
+ | `OAUTH_REQUIRED_SCOPES` | _(empty)_ | Required OAuth scopes |
194
+ | `OAUTH_CLIENT_ID` | _(empty)_ | OAuth client ID |
195
+ | `OAUTH_CLIENT_SECRET` | _(empty)_ | OAuth client secret |
196
+
197
+ #### Transform & Workers
198
+
199
+ | Variable | Default | Description |
200
+ | ------------------------------------------ | --------- | ----------------------------------------- |
201
+ | `TRANSFORM_WORKER_MODE` | `threads` | Worker mode: `threads` or `process` |
202
+ | `TRANSFORM_WORKER_MAX_OLD_GENERATION_MB` | _(unset)_ | V8 old generation heap limit per worker |
203
+ | `TRANSFORM_WORKER_MAX_YOUNG_GENERATION_MB` | _(unset)_ | V8 young generation heap limit per worker |
204
+ | `TRANSFORM_WORKER_CODE_RANGE_MB` | _(unset)_ | V8 code range limit per worker |
205
+ | `TRANSFORM_WORKER_STACK_MB` | _(unset)_ | Stack size limit per worker |
206
+
207
+ #### Content Tuning
208
+
209
+ | Variable | Default | Description |
210
+ | ---------------------------------- | ----------------- | ------------------------------------------------ |
211
+ | `SUPERFETCH_EXTRA_NOISE_TOKENS` | _(empty)_ | Additional CSS class/id tokens for noise removal |
212
+ | `SUPERFETCH_EXTRA_NOISE_SELECTORS` | _(empty)_ | Additional CSS selectors for noise removal |
213
+ | `MARKDOWN_HEADING_KEYWORDS` | _(built-in list)_ | Keywords triggering heading promotion |
214
+ | `SUPERFETCH_LOCALE` | _(system)_ | Locale for content processing |
215
+
216
+ #### Server Tuning
217
+
218
+ | Variable | Default | Description |
219
+ | ---------------------------------- | --------------- | ---------------------------------------- |
220
+ | `SERVER_MAX_CONNECTIONS` | `0` (unlimited) | Maximum concurrent HTTP connections |
221
+ | `SERVER_BLOCK_PRIVATE_CONNECTIONS` | `false` | Block connections from private IP ranges |
222
+
223
+ ### Hardcoded Defaults
224
+
225
+ | Setting | Value |
226
+ | ------------------------ | ------------------------------- |
227
+ | Max HTML size | 10 MB |
228
+ | Max inline content chars | 0 (unlimited) |
229
+ | Fetch timeout | 15 s |
230
+ | Transform timeout | 30 s |
231
+ | Tool timeout | Fetch + Transform + 5 s padding |
232
+ | Max redirects | 5 |
233
+ | Cache TTL | 86400 s (24 h) |
234
+ | Cache max keys | 100 |
235
+ | Rate limit | 100 requests / 60 s |
236
+ | Max sessions | 200 |
237
+ | Session TTL | 30 min |
238
+ | Max URL length | 2048 chars |
239
+ | Worker pool max scale | 4 |
208
240
 
209
241
  ## Usage
210
242
 
211
- ### Stdio (local MCP clients)
243
+ ### Stdio Mode
212
244
 
213
245
  ```bash
214
- npx -y @j0hanz/superfetch@latest --stdio
246
+ superfetch --stdio
215
247
  ```
216
248
 
217
- ### HTTP server (local only, static token)
249
+ The server communicates via JSON-RPC over stdin/stdout. All MCP clients that support stdio transport can connect directly.
250
+
251
+ ### HTTP Mode
218
252
 
219
253
  ```bash
220
- API_KEY=YOUR_TOKEN_HERE npm start
254
+ superfetch
255
+ # or
256
+ PORT=8080 HOST=0.0.0.0 ALLOW_REMOTE=true superfetch
221
257
  ```
222
258
 
223
- Requires `npm run build` before `npm start` when running from source.
224
-
225
- Remote bindings require `ALLOW_REMOTE=true` and OAuth configuration.
259
+ The server starts a Streamable HTTP endpoint at `/mcp`. Authenticate with bearer tokens via the `ACCESS_TOKENS` or `API_KEY` environment variables.
226
260
 
227
261
  ## MCP Surface
228
262
 
@@ -230,80 +264,130 @@ Remote bindings require `ALLOW_REMOTE=true` and OAuth configuration.
230
264
 
231
265
  #### `fetch-url`
232
266
 
233
- Fetches a webpage and converts it to clean Markdown.
267
+ Fetches a webpage and converts it to clean Markdown format optimized for LLM context.
234
268
 
235
- Parameters:
269
+ **Useful for:**
236
270
 
237
- | Name | Type | Required | Description |
238
- | ----- | ------ | -------- | ------------------------------------ |
239
- | `url` | string | Yes | Public http(s) URL, max length 2048. |
271
+ - Reading documentation, blog posts, or articles
272
+ - Extracting main content while removing navigation and ads
273
+ - Caching content to speed up repeated queries
240
274
 
241
- Structured response fields:
275
+ **Limitations:**
242
276
 
243
- - `url` (string): fetched URL
244
- - `inputUrl` (string, optional): original input URL
245
- - `resolvedUrl` (string, optional): normalized or raw-content URL
246
- - `title` (string, optional): page title
247
- - `markdown` (string, optional): inline markdown (may be truncated)
248
- - `error` (string, optional): error message on failure
277
+ - Does not execute complex client-side JavaScript interactions
249
278
 
250
- Limitations:
279
+ ##### Parameters
280
+
281
+ | Parameter | Type | Required | Default | Description |
282
+ | ------------------ | -------------- | -------- | ------- | ------------------------------------------------------------------ |
283
+ | `url` | `string` (URL) | Yes | — | The URL of the webpage to fetch (http/https, max 2048 chars) |
284
+ | `skipNoiseRemoval` | `boolean` | No | `false` | Preserve navigation, footers, and other elements normally filtered |
285
+ | `forceRefresh` | `boolean` | No | `false` | Bypass cache and fetch fresh content |
286
+
287
+ ##### Returns
288
+
289
+ ```json
290
+ {
291
+ "url": "https://example.com",
292
+ "resolvedUrl": "https://example.com",
293
+ "inputUrl": "https://example.com",
294
+ "title": "Example Domain",
295
+ "markdown": "# Example Domain\n\nThis domain is for use in illustrative examples...",
296
+ "truncated": false
297
+ }
298
+ ```
251
299
 
252
- - Only http/https URLs are accepted; URLs with embedded credentials are rejected.
253
- - Client-side JavaScript is not executed.
254
- - Content extraction quality depends on the source HTML structure. Works best
255
- with standard article and documentation layouts. Always verify output meets
256
- expectations.
300
+ | Field | Type | Description |
301
+ | ------------- | ---------- | ----------------------------------------------- |
302
+ | `url` | `string` | The canonical URL (pre-raw-transform) |
303
+ | `inputUrl` | `string` | The original URL provided by the caller |
304
+ | `resolvedUrl` | `string` | The normalized/transformed URL that was fetched |
305
+ | `title` | `string?` | Extracted page title |
306
+ | `markdown` | `string?` | Extracted content in Markdown format |
307
+ | `truncated` | `boolean?` | Whether inline markdown was truncated |
308
+ | `error` | `string?` | Error message if the request failed |
309
+ | `statusCode` | `number?` | HTTP status code for failed requests |
310
+ | `details` | `object?` | Additional error details |
257
311
 
258
- Large content handling:
312
+ ##### Annotations
259
313
 
260
- - Inline markdown is capped at 20,000 characters.
261
- - If cache is enabled and content exceeds the inline limit, the tool response
262
- includes a `resource_link` block pointing to `superfetch://cache/markdown/{urlHash}`.
263
- - If cache is disabled, inline markdown is truncated with `...[truncated]`.
264
- - In stdio mode, the tool also embeds a `resource` block containing full
265
- markdown content when available.
314
+ | Annotation | Value |
315
+ | ----------------- | ------- |
316
+ | `readOnlyHint` | `true` |
317
+ | `destructiveHint` | `false` |
318
+ | `idempotentHint` | `true` |
319
+ | `openWorldHint` | `true` |
320
+
321
+ ##### Async Task Execution
322
+
323
+ The `fetch-url` tool supports optional async task execution. Include a `task` field in the tool call to run the fetch in the background:
324
+
325
+ ```json
326
+ {
327
+ "method": "tools/call",
328
+ "params": {
329
+ "name": "fetch-url",
330
+ "arguments": { "url": "https://example.com" },
331
+ "task": { "ttl": 300 }
332
+ }
333
+ }
334
+ ```
335
+
336
+ Then poll `tasks/get` until the task status is `completed` or `failed`, and retrieve the result via `tasks/result`.
266
337
 
267
338
  ### Resources
268
339
 
269
- | URI pattern | Description | MIME type |
270
- | --------------------------------------- | ------------------------------------------ | ------------------ |
271
- | `superfetch://cache/markdown/{urlHash}` | Cached markdown content entry. | `text/markdown` |
272
- | `internal://instructions` | Server usage instructions. | `text/markdown` |
273
- | `internal://config` | Current runtime config (secrets redacted). | `application/json` |
340
+ | URI Pattern | MIME Type | Description |
341
+ | ------------------------------------------ | ------------------ | ------------------------------------------------ |
342
+ | `internal://instructions` | `text/markdown` | Server instructions and usage guidance |
343
+ | `internal://config` | `application/json` | Current runtime configuration (secrets redacted) |
344
+ | `superfetch://cache/{namespace}/{urlHash}` | `text/markdown` | Cached web content snapshots (subscribable) |
345
+
346
+ The `superfetch://cache/...` resource supports subscriptions — clients receive notifications when cached content is updated.
274
347
 
275
348
  ### Tasks
276
349
 
277
- `fetch-url` supports async execution via MCP tasks. Call `tools/call` with a
278
- `task` payload to start a background fetch, then use `tasks/get`,
279
- `tasks/result`, or `tasks/cancel` to manage it.
350
+ The server declares full MCP task support:
351
+
352
+ | Endpoint | Description |
353
+ | -------------- | ------------------------------------ |
354
+ | `tasks/list` | List tasks (scoped to session/owner) |
355
+ | `tasks/get` | Get task status by ID |
356
+ | `tasks/result` | Retrieve completed task result |
357
+ | `tasks/cancel` | Cancel an in-flight task |
280
358
 
281
359
  ## HTTP Mode Endpoints
282
360
 
283
- | Method | Path | Auth | Notes |
284
- | ------ | --------------------------------- | ---- | -------------------------------------------------- |
285
- | GET | `/health` | No | Health check. |
286
- | POST | `/mcp` | Yes | Streamable HTTP JSON-RPC requests. |
287
- | GET | `/mcp` | Yes | SSE stream (requires `Accept: text/event-stream`). |
288
- | DELETE | `/mcp` | Yes | Close the session. |
289
- | GET | `/mcp/downloads/:namespace/:hash` | Yes | Download cached markdown. |
361
+ | Method | Path | Auth | Description |
362
+ | -------- | ----------------------------------- | ---- | ---------------------------------------- |
363
+ | `GET` | `/health` | No | Health check with server stats |
364
+ | `POST` | `/mcp` | Yes | MCP JSON-RPC (Streamable HTTP) |
365
+ | `GET` | `/mcp` | Yes | SSE stream for server-initiated messages |
366
+ | `DELETE` | `/mcp` | Yes | Terminate MCP session |
367
+ | `GET` | `/mcp/downloads/{namespace}/{hash}` | Yes | Download cached content |
368
+
369
+ ### Session Behavior
370
+
371
+ - Sessions are created on the first `POST /mcp` request with an `initialize` message
372
+ - Session ID is returned in the `mcp-session-id` response header
373
+ - Sessions expire after 30 minutes of inactivity (max 200 concurrent)
290
374
 
291
- Notes:
375
+ ### Authentication
292
376
 
293
- - HTTP requests must include `MCP-Protocol-Version: 2025-11-25`.
294
- - Sessions are managed via the `mcp-session-id` header.
377
+ - **Static tokens**: Set `ACCESS_TOKENS` or `API_KEY` environment variables; pass as `Authorization: Bearer <token>`
378
+ - **OAuth**: Configure `OAUTH_*` environment variables to enable OAuth 2.0 token introspection
295
379
 
296
380
  ## Client Configuration Examples
297
381
 
298
382
  <details>
299
- <summary><strong>VS Code</strong></summary>
383
+ <summary>VS Code / VS Code Insiders</summary>
300
384
 
301
- Add to .vscode/mcp.json:
385
+ Add to your VS Code settings (`.vscode/mcp.json` or User Settings):
302
386
 
303
387
  ```json
304
388
  {
305
389
  "servers": {
306
- "superFetch": {
390
+ "superfetch": {
307
391
  "command": "npx",
308
392
  "args": ["-y", "@j0hanz/superfetch@latest", "--stdio"]
309
393
  }
@@ -314,14 +398,14 @@ Add to .vscode/mcp.json:
314
398
  </details>
315
399
 
316
400
  <details>
317
- <summary><strong>Claude Desktop</strong></summary>
401
+ <summary>Claude Desktop</summary>
318
402
 
319
- Add to claude_desktop_config.json:
403
+ Add to `claude_desktop_config.json`:
320
404
 
321
405
  ```json
322
406
  {
323
407
  "mcpServers": {
324
- "superFetch": {
408
+ "superfetch": {
325
409
  "command": "npx",
326
410
  "args": ["-y", "@j0hanz/superfetch@latest", "--stdio"]
327
411
  }
@@ -332,12 +416,16 @@ Add to claude_desktop_config.json:
332
416
  </details>
333
417
 
334
418
  <details>
335
- <summary><strong>Cursor</strong></summary>
419
+ <summary>Cursor</summary>
420
+
421
+ [![Install in Cursor](https://img.shields.io/badge/Cursor-Install-f97316?logo=cursor&logoColor=white)](https://cursor.com/install-mcp?name=superfetch&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkBqMGhhbnovc3VwZXJmZXRjaEBsYXRlc3QiLCItLXN0ZGlvIl19)
422
+
423
+ Or manually add to Cursor MCP settings:
336
424
 
337
425
  ```json
338
426
  {
339
427
  "mcpServers": {
340
- "superFetch": {
428
+ "superfetch": {
341
429
  "command": "npx",
342
430
  "args": ["-y", "@j0hanz/superfetch@latest", "--stdio"]
343
431
  }
@@ -348,12 +436,14 @@ Add to claude_desktop_config.json:
348
436
  </details>
349
437
 
350
438
  <details>
351
- <summary><strong>Windsurf</strong></summary>
439
+ <summary>Windsurf</summary>
440
+
441
+ Add to your Windsurf MCP configuration:
352
442
 
353
443
  ```json
354
444
  {
355
445
  "mcpServers": {
356
- "superFetch": {
446
+ "superfetch": {
357
447
  "command": "npx",
358
448
  "args": ["-y", "@j0hanz/superfetch@latest", "--stdio"]
359
449
  }
@@ -363,58 +453,92 @@ Add to claude_desktop_config.json:
363
453
 
364
454
  </details>
365
455
 
456
+ ## Security
457
+
458
+ ### SSRF Protection
459
+
460
+ superFetch blocks requests to private and internal network addresses:
461
+
462
+ - **Blocked hosts**: `localhost`, `127.0.0.0/8`, `10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`, `169.254.0.0/16`, `100.64.0.0/10`
463
+ - **Blocked IPv6**: `::1`, `fc00::/7`, `fe80::/10`, IPv4-mapped private addresses (`::ffff:10.*`, etc.)
464
+ - **Cloud metadata**: `169.254.169.254` (AWS), `metadata.google.internal`, `metadata.azure.com`, `100.100.100.200` (Azure IMDS)
465
+
466
+ DNS preflight checks run on every redirect hop to prevent DNS rebinding attacks.
467
+
468
+ ### Stdio Transport Safety
469
+
470
+ The server never writes non-protocol data to stdout. All logs and diagnostics go to stderr.
471
+
472
+ ### Rate Limiting
473
+
474
+ HTTP mode enforces a rate limit of 100 requests per 60-second window per client.
475
+
476
+ ### Content Safety
477
+
478
+ - HTML downloads are capped at 10 MB
479
+ - Worker threads run in isolation with configurable resource limits
480
+ - Auth tokens are stored in-memory only and compared using timing-safe equality
481
+
366
482
  ## Development Workflow
367
483
 
368
- ### Install dependencies
484
+ ### Install Dependencies
369
485
 
370
486
  ```bash
371
487
  npm install
372
488
  ```
373
489
 
374
- Use `npm ci` for clean, reproducible installs.
375
-
376
- ### Common scripts
377
-
378
- | Script | Command | Purpose |
379
- | ---------------------- | ------------------------------------------------------------------------------------------------------------------- | ------------------------------------- |
380
- | clean | `node scripts/build.mjs clean` | Remove dist and TS build info. |
381
- | validate:instructions | `node scripts/build.mjs validate:instructions` | Validate `src/instructions.md`. |
382
- | build | `node scripts/build.mjs` | Compile TS, copy assets, set exec bit |
383
- | copy:assets | `node scripts/build.mjs copy:assets` | Copy assets/instructions to dist. |
384
- | prepare | `npm run build` | Prepare package for publishing. |
385
- | dev | `tsc --watch --preserveWatchOutput` | TypeScript watch mode. |
386
- | dev:run | `node --env-file=.env --watch dist/index.js` | Run compiled server in watch mode. |
387
- | start | `node dist/index.js` | Start HTTP server (default). |
388
- | format | `prettier --write .` | Format codebase. |
389
- | type-check | `tsc --noEmit` | Type checking. |
390
- | type-check:diagnostics | `tsc --noEmit --extendedDiagnostics` | Type check diagnostics. |
391
- | type-check:trace | `node -e "require('fs').rmSync('.ts-trace',{recursive:true,force:true})" && tsc --noEmit --generateTrace .ts-trace` | Generate TS trace. |
392
- | lint | `eslint .` | Lint. |
393
- | lint:fix | `eslint . --fix` | Lint and fix. |
394
- | test | `npm run build --silent && node --test --experimental-transform-types` | Run tests (builds first). |
395
- | test:coverage | `npm run build --silent && node --test --experimental-transform-types --experimental-test-coverage` | Test with coverage. |
396
- | knip | `knip` | Dead code analysis. |
397
- | knip:fix | `knip --fix` | Fix knip issues. |
398
- | inspector | `npx @modelcontextprotocol/inspector` | MCP Inspector. |
399
- | prepublishOnly | `npm run lint && npm run type-check && npm run build` | Prepublish checks. |
490
+ ### Scripts
491
+
492
+ | Script | Command | Description |
493
+ | --------------- | ----------------------- | -------------------------------------------- |
494
+ | `dev` | `npm run dev` | TypeScript watch mode |
495
+ | `dev:run` | `npm run dev:run` | Run compiled output with watch + `.env` |
496
+ | `build` | `npm run build` | Clean, compile, copy assets, make executable |
497
+ | `start` | `npm start` | Run compiled server |
498
+ | `test` | `npm test` | Run test suite (Node.js native test runner) |
499
+ | `test:coverage` | `npm run test:coverage` | Run tests with coverage |
500
+ | `lint` | `npm run lint` | ESLint |
501
+ | `lint:fix` | `npm run lint:fix` | ESLint with auto-fix |
502
+ | `format` | `npm run format` | Prettier |
503
+ | `type-check` | `npm run type-check` | TypeScript type checking |
504
+ | `inspector` | `npm run inspector` | Build and launch MCP Inspector |
400
505
 
401
506
  ## Build and Release
402
507
 
403
- - `npm run build` runs `scripts/build.mjs`, compiling TS with
404
- `tsconfig.build.json`, copying `assets/` and `src/instructions.md` to `dist/`,
405
- and making `dist/index.js` executable.
406
- - GitHub Releases trigger the publish workflow (lint, type-check, build,
407
- version sync, then `npm publish`).
508
+ ```bash
509
+ npm run build # Clean Compile Copy Assets → chmod
510
+ npm run prepublishOnly # Lint Type-Check → Build
511
+ npm publish # Publish to npm
512
+ ```
513
+
514
+ The `prepare` script runs `npm run build` automatically on `npm install` from source.
408
515
 
409
516
  ## Troubleshooting
410
517
 
411
- - Tests import from `dist/`. Run `npm test` (builds first) or `npm run build`
412
- before running individual test files.
413
- - HTTP mode requires auth. Set `API_KEY` or `ACCESS_TOKENS` (or configure OAuth).
414
- - Non-loopback bindings require `ALLOW_REMOTE=true` and OAuth configuration.
415
- - Missing `MCP-Protocol-Version: 2025-11-25` yields a 400 error.
416
- - Large pages may return a `resource_link` to cached content instead of inline
417
- markdown.
418
- - Requests to private IPs, localhost, or `.local`/`.internal` hosts are blocked.
518
+ ### MCP Inspector
519
+
520
+ Use the built-in inspector to test the server interactively:
521
+
522
+ ```bash
523
+ npm run inspector
524
+ ```
525
+
526
+ This builds the project and launches `@modelcontextprotocol/inspector` pointing to the compiled server.
527
+
528
+ ### Common Issues
529
+
530
+ | Issue | Solution |
531
+ | ------------------------- | ------------------------------------------------------------------------------------- |
532
+ | `VALIDATION_ERROR` on URL | URL is blocked (private IP/localhost) or malformed. Do not retry. |
533
+ | `queue_full` error | Worker pool is saturated. Wait briefly, then retry or use async task mode. |
534
+ | Garbled output | Binary content (images, PDFs) cannot be converted. Ensure the URL serves HTML. |
535
+ | No output in stdio mode | Ensure `--stdio` flag is passed. Without it, the server starts in HTTP mode. |
536
+ | Auth errors in HTTP mode | Set `ACCESS_TOKENS` or `API_KEY` env var and pass as `Authorization: Bearer <token>`. |
537
+
538
+ ### Stdout / Stderr Guidance
539
+
540
+ In stdio mode, **stdout** is reserved exclusively for MCP JSON-RPC messages. Logs and diagnostics are written to **stderr**. Never pipe stdout to a log file when using stdio transport.
541
+
542
+ ## License
419
543
 
420
- <!-- markdownlint-enable MD033 -->
544
+ [MIT](https://opensource.org/licenses/MIT)