@j0hanz/fetch-url-mcp 0.0.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 +570 -0
- package/dist/AGENTS.md +115 -0
- package/dist/assets/logo.svg +24837 -0
- package/dist/cache.d.ts +47 -0
- package/dist/cache.js +316 -0
- package/dist/cli.d.ts +17 -0
- package/dist/cli.js +48 -0
- package/dist/config.d.ts +142 -0
- package/dist/config.js +480 -0
- package/dist/crypto.d.ts +3 -0
- package/dist/crypto.js +49 -0
- package/dist/dom-noise-removal.d.ts +1 -0
- package/dist/dom-noise-removal.js +488 -0
- package/dist/errors.d.ts +10 -0
- package/dist/errors.js +61 -0
- package/dist/fetch.d.ts +42 -0
- package/dist/fetch.js +1544 -0
- package/dist/host-normalization.d.ts +1 -0
- package/dist/host-normalization.js +77 -0
- package/dist/http-native.d.ts +5 -0
- package/dist/http-native.js +1313 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +91 -0
- package/dist/instructions.md +57 -0
- package/dist/ip-blocklist.d.ts +8 -0
- package/dist/ip-blocklist.js +74 -0
- package/dist/json.d.ts +1 -0
- package/dist/json.js +34 -0
- package/dist/language-detection.d.ts +2 -0
- package/dist/language-detection.js +364 -0
- package/dist/markdown-cleanup.d.ts +6 -0
- package/dist/markdown-cleanup.js +474 -0
- package/dist/mcp-validator.d.ts +15 -0
- package/dist/mcp-validator.js +44 -0
- package/dist/mcp.d.ts +4 -0
- package/dist/mcp.js +421 -0
- package/dist/observability.d.ts +21 -0
- package/dist/observability.js +211 -0
- package/dist/prompts.d.ts +7 -0
- package/dist/prompts.js +28 -0
- package/dist/resources.d.ts +8 -0
- package/dist/resources.js +216 -0
- package/dist/server-tuning.d.ts +13 -0
- package/dist/server-tuning.js +47 -0
- package/dist/server.d.ts +4 -0
- package/dist/server.js +174 -0
- package/dist/session.d.ts +39 -0
- package/dist/session.js +218 -0
- package/dist/tasks.d.ts +63 -0
- package/dist/tasks.js +327 -0
- package/dist/timer-utils.d.ts +5 -0
- package/dist/timer-utils.js +20 -0
- package/dist/tools.d.ts +135 -0
- package/dist/tools.js +812 -0
- package/dist/transform-types.d.ts +126 -0
- package/dist/transform-types.js +5 -0
- package/dist/transform.d.ts +36 -0
- package/dist/transform.js +2341 -0
- package/dist/type-guards.d.ts +14 -0
- package/dist/type-guards.js +13 -0
- package/dist/workers/transform-child.d.ts +1 -0
- package/dist/workers/transform-child.js +136 -0
- package/dist/workers/transform-worker.d.ts +1 -0
- package/dist/workers/transform-worker.js +128 -0
- package/package.json +91 -0
package/README.md
ADDED
|
@@ -0,0 +1,570 @@
|
|
|
1
|
+
<!-- markdownlint-disable MD033 -->
|
|
2
|
+
|
|
3
|
+
# Fetch URL MCP Server
|
|
4
|
+
|
|
5
|
+
<img src="assets/logo.svg" alt="Fetch URL MCP Logo" width="300">
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@j0hanz/fetch-url-mcp) [](https://opensource.org/licenses/MIT) [](https://nodejs.org) [](https://www.typescriptlang.org) [](https://modelcontextprotocol.io)
|
|
8
|
+
|
|
9
|
+
[](https://insiders.vscode.dev/redirect?url=vscode%3Amcp%2Finstall%3F%7B%22name%22%3A%22fetch-url-mcp%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40j0hanz%2Ffetch-url-mcp%40latest%22%2C%22--stdio%22%5D%7D) [](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Amcp%2Finstall%3F%7B%22name%22%3A%22fetch-url-mcp%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40j0hanz%2Ffetch-url-mcp%40latest%22%2C%22--stdio%22%5D%7D) [](https://cursor.com/install-mcp?name=fetch-url-mcp&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkBqMGhhbnovZmV0Y2gtdXJsLW1jcEBsYXRlc3QiLCItLXN0ZGlvIl19)
|
|
10
|
+
|
|
11
|
+
Fetch and convert public web content to clean Markdown both readable by humans and optimized for LLM context.
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
Fetch URL 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.
|
|
16
|
+
|
|
17
|
+
## Key Features
|
|
18
|
+
|
|
19
|
+
- HTML to Markdown using Mozilla Readability + node-html-markdown.
|
|
20
|
+
- Raw content URL rewriting for GitHub, GitLab, Bitbucket, and Gist.
|
|
21
|
+
- In-memory LRU cache for faster repeat fetches.
|
|
22
|
+
- Stdio or Streamable HTTP transport with session management.
|
|
23
|
+
- SSRF protections: blocked private IP ranges and internal hostnames.
|
|
24
|
+
|
|
25
|
+
> **Note:** Content extraction quality varies depending on the HTML structure and
|
|
26
|
+
> complexity of the source page. Fetch URL works best with standard article and
|
|
27
|
+
> documentation layouts. Always verify the fetched content to ensure it meets
|
|
28
|
+
> your expectations, as some pages may require manual adjustment or alternative
|
|
29
|
+
> approaches.
|
|
30
|
+
|
|
31
|
+
## Tech Stack
|
|
32
|
+
|
|
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 |
|
|
43
|
+
|
|
44
|
+
## Architecture
|
|
45
|
+
|
|
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
|
+
```
|
|
51
|
+
|
|
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
|
|
57
|
+
|
|
58
|
+
## Repository Structure
|
|
59
|
+
|
|
60
|
+
```text
|
|
61
|
+
fetch-url-mcp/
|
|
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
|
+
│ ├── server-tuning.ts
|
|
89
|
+
│ ├── session.ts
|
|
90
|
+
│ ├── tasks.ts
|
|
91
|
+
│ ├── timer-utils.ts
|
|
92
|
+
│ ├── tools.ts
|
|
93
|
+
│ ├── transform-types.ts
|
|
94
|
+
│ ├── transform.ts
|
|
95
|
+
│ └── type-guards.ts
|
|
96
|
+
├── tests/
|
|
97
|
+
│ └── *.test.ts
|
|
98
|
+
├── package.json
|
|
99
|
+
├── tsconfig.json
|
|
100
|
+
└── AGENTS.md
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Requirements
|
|
104
|
+
|
|
105
|
+
- **Node.js** ≥ 24
|
|
106
|
+
|
|
107
|
+
## Quickstart
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
npx -y @j0hanz/fetch-url-mcp@latest --stdio
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Add to your MCP client configuration:
|
|
114
|
+
|
|
115
|
+
```json
|
|
116
|
+
{
|
|
117
|
+
"mcpServers": {
|
|
118
|
+
"fetch-url-mcp": {
|
|
119
|
+
"command": "npx",
|
|
120
|
+
"args": ["-y", "@j0hanz/fetch-url-mcp@latest", "--stdio"]
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Installation
|
|
127
|
+
|
|
128
|
+
### NPX (Recommended)
|
|
129
|
+
|
|
130
|
+
No installation required — runs directly:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
npx -y @j0hanz/fetch-url-mcp@latest --stdio
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Global Install
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
npm install -g @j0hanz/fetch-url-mcp
|
|
140
|
+
fetch-url-mcp --stdio
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### From Source
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
git clone https://github.com/j0hanz/fetch-url-mcp.git
|
|
147
|
+
cd fetch-url-mcp
|
|
148
|
+
npm install
|
|
149
|
+
npm run build
|
|
150
|
+
node dist/index.js --stdio
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Configuration
|
|
154
|
+
|
|
155
|
+
### Runtime Modes
|
|
156
|
+
|
|
157
|
+
| Flag | Description |
|
|
158
|
+
| ----------------- | ------------------------------------------- |
|
|
159
|
+
| `--stdio`, `-s` | Run in stdio mode (for desktop MCP clients) |
|
|
160
|
+
| `--help`, `-h` | Show usage help |
|
|
161
|
+
| `--version`, `-v` | Print server version |
|
|
162
|
+
|
|
163
|
+
When no `--stdio` flag is passed, the server starts in **HTTP mode** (Streamable HTTP on port 3000 by default).
|
|
164
|
+
|
|
165
|
+
### Environment Variables
|
|
166
|
+
|
|
167
|
+
#### Core Settings
|
|
168
|
+
|
|
169
|
+
| Variable | Default | Description |
|
|
170
|
+
| --------------------- | ------------------------- | ------------------------------------------------------ |
|
|
171
|
+
| `HOST` | `127.0.0.1` | HTTP server bind address |
|
|
172
|
+
| `PORT` | `3000` | HTTP server port (1024–65535) |
|
|
173
|
+
| `LOG_LEVEL` | `info` | Log level: `debug`, `info`, `warn`, `error` |
|
|
174
|
+
| `FETCH_TIMEOUT_MS` | `15000` | HTTP fetch timeout in ms (1000–60000) |
|
|
175
|
+
| `CACHE_ENABLED` | `true` | Enable/disable in-memory content cache |
|
|
176
|
+
| `USER_AGENT` | `fetch-url-mcp/{version}` | Custom User-Agent header |
|
|
177
|
+
| `ALLOW_REMOTE` | `false` | Allow remote connections in HTTP mode |
|
|
178
|
+
| `ALLOWED_HOSTS` | _(empty)_ | Comma-separated host/origin allowlist for HTTP mode |
|
|
179
|
+
| `TASKS_MAX_TOTAL` | `5000` | Maximum retained task records across all owners |
|
|
180
|
+
| `TASKS_MAX_PER_OWNER` | `1000` | Maximum retained task records per session/client/token |
|
|
181
|
+
|
|
182
|
+
#### Authentication (HTTP Mode)
|
|
183
|
+
|
|
184
|
+
| Variable | Default | Description |
|
|
185
|
+
| ------------------------- | --------- | --------------------------------------- |
|
|
186
|
+
| `ACCESS_TOKENS` | _(empty)_ | Comma-separated static bearer tokens |
|
|
187
|
+
| `API_KEY` | _(empty)_ | Single API key (added to static tokens) |
|
|
188
|
+
| `OAUTH_ISSUER_URL` | _(empty)_ | OAuth issuer URL (enables OAuth mode) |
|
|
189
|
+
| `OAUTH_AUTHORIZATION_URL` | _(empty)_ | OAuth authorization endpoint |
|
|
190
|
+
| `OAUTH_TOKEN_URL` | _(empty)_ | OAuth token endpoint |
|
|
191
|
+
| `OAUTH_INTROSPECTION_URL` | _(empty)_ | OAuth token introspection endpoint |
|
|
192
|
+
| `OAUTH_REVOCATION_URL` | _(empty)_ | OAuth token revocation endpoint |
|
|
193
|
+
| `OAUTH_REGISTRATION_URL` | _(empty)_ | OAuth dynamic client registration |
|
|
194
|
+
| `OAUTH_REQUIRED_SCOPES` | _(empty)_ | Required OAuth scopes |
|
|
195
|
+
| `OAUTH_CLIENT_ID` | _(empty)_ | OAuth client ID |
|
|
196
|
+
| `OAUTH_CLIENT_SECRET` | _(empty)_ | OAuth client secret |
|
|
197
|
+
|
|
198
|
+
#### Transform & Workers
|
|
199
|
+
|
|
200
|
+
| Variable | Default | Description |
|
|
201
|
+
| ------------------------------------------ | --------- | ----------------------------------------- |
|
|
202
|
+
| `TRANSFORM_WORKER_MODE` | `threads` | Worker mode: `threads` or `process` |
|
|
203
|
+
| `TRANSFORM_WORKER_MAX_OLD_GENERATION_MB` | _(unset)_ | V8 old generation heap limit per worker |
|
|
204
|
+
| `TRANSFORM_WORKER_MAX_YOUNG_GENERATION_MB` | _(unset)_ | V8 young generation heap limit per worker |
|
|
205
|
+
| `TRANSFORM_WORKER_CODE_RANGE_MB` | _(unset)_ | V8 code range limit per worker |
|
|
206
|
+
| `TRANSFORM_WORKER_STACK_MB` | _(unset)_ | Stack size limit per worker |
|
|
207
|
+
|
|
208
|
+
#### Content Tuning
|
|
209
|
+
|
|
210
|
+
| Variable | Default | Description |
|
|
211
|
+
| ------------------------------------- | ----------------- | ------------------------------------------------ |
|
|
212
|
+
| `MAX_INLINE_CONTENT_CHARS` | `0` | Global inline markdown limit (`0` = unlimited) |
|
|
213
|
+
| `FETCH_URL_MCP_EXTRA_NOISE_TOKENS` | _(empty)_ | Additional CSS class/id tokens for noise removal |
|
|
214
|
+
| `FETCH_URL_MCP_EXTRA_NOISE_SELECTORS` | _(empty)_ | Additional CSS selectors for noise removal |
|
|
215
|
+
| `MARKDOWN_HEADING_KEYWORDS` | _(built-in list)_ | Keywords triggering heading promotion |
|
|
216
|
+
| `FETCH_URL_MCP_LOCALE` | _(system)_ | Locale for content processing |
|
|
217
|
+
|
|
218
|
+
#### Server Tuning
|
|
219
|
+
|
|
220
|
+
| Variable | Default | Description |
|
|
221
|
+
| ---------------------------------- | --------------- | ---------------------------------------- |
|
|
222
|
+
| `SERVER_MAX_CONNECTIONS` | `0` (unlimited) | Maximum concurrent HTTP connections |
|
|
223
|
+
| `SERVER_BLOCK_PRIVATE_CONNECTIONS` | `false` | Block connections from private IP ranges |
|
|
224
|
+
|
|
225
|
+
### Hardcoded Defaults
|
|
226
|
+
|
|
227
|
+
| Setting | Value |
|
|
228
|
+
| ------------------------ | ------------------------------- |
|
|
229
|
+
| Max HTML size | 10 MB |
|
|
230
|
+
| Max inline content chars | 0 (unlimited, configurable) |
|
|
231
|
+
| Fetch timeout | 15 s |
|
|
232
|
+
| Transform timeout | 30 s |
|
|
233
|
+
| Tool timeout | Fetch + Transform + 5 s padding |
|
|
234
|
+
| Max redirects | 5 |
|
|
235
|
+
| Cache TTL | 86400 s (24 h) |
|
|
236
|
+
| Cache max keys | 100 |
|
|
237
|
+
| Rate limit | 100 requests / 60 s |
|
|
238
|
+
| Max sessions | 200 |
|
|
239
|
+
| Session TTL | 30 min |
|
|
240
|
+
| Max URL length | 2048 chars |
|
|
241
|
+
| Worker pool max scale | 4 |
|
|
242
|
+
|
|
243
|
+
## Usage
|
|
244
|
+
|
|
245
|
+
### Stdio Mode
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
fetch-url-mcp --stdio
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
The server communicates via JSON-RPC over stdin/stdout. All MCP clients that support stdio transport can connect directly.
|
|
252
|
+
|
|
253
|
+
### HTTP Mode
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
fetch-url-mcp
|
|
257
|
+
# or
|
|
258
|
+
PORT=8080 HOST=0.0.0.0 ALLOW_REMOTE=true fetch-url-mcp
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
The server starts a Streamable HTTP endpoint at `/mcp`. Authenticate with bearer tokens via the `ACCESS_TOKENS` or `API_KEY` environment variables.
|
|
262
|
+
|
|
263
|
+
For `POST /mcp`, clients should send:
|
|
264
|
+
|
|
265
|
+
- `Accept: application/json, text/event-stream`
|
|
266
|
+
- `MCP-Protocol-Version: 2025-11-25` (or `2025-03-26` for legacy clients)
|
|
267
|
+
|
|
268
|
+
## MCP Surface
|
|
269
|
+
|
|
270
|
+
### Tools
|
|
271
|
+
|
|
272
|
+
#### `fetch-url`
|
|
273
|
+
|
|
274
|
+
Fetches a webpage and converts it to clean Markdown format optimized for LLM context.
|
|
275
|
+
|
|
276
|
+
**Useful for:**
|
|
277
|
+
|
|
278
|
+
- Reading documentation, blog posts, or articles
|
|
279
|
+
- Extracting main content while removing navigation and ads
|
|
280
|
+
- Caching content to speed up repeated queries
|
|
281
|
+
|
|
282
|
+
**Limitations:**
|
|
283
|
+
|
|
284
|
+
- Does not execute complex client-side JavaScript interactions
|
|
285
|
+
|
|
286
|
+
##### Parameters
|
|
287
|
+
|
|
288
|
+
| Parameter | Type | Required | Default | Description |
|
|
289
|
+
| ------------------ | -------------- | -------- | ------- | -------------------------------------------------------------------------- |
|
|
290
|
+
| `url` | `string` (URL) | Yes | — | The URL of the webpage to fetch (http/https, max 2048 chars) |
|
|
291
|
+
| `skipNoiseRemoval` | `boolean` | No | `false` | Preserve navigation, footers, and other elements normally filtered |
|
|
292
|
+
| `forceRefresh` | `boolean` | No | `false` | Bypass cache and fetch fresh content |
|
|
293
|
+
| `maxInlineChars` | `number` | No | `0` | Per-call inline markdown limit (`0` = unlimited; global cap still applies) |
|
|
294
|
+
|
|
295
|
+
##### Returns
|
|
296
|
+
|
|
297
|
+
```json
|
|
298
|
+
{
|
|
299
|
+
"url": "https://example.com",
|
|
300
|
+
"resolvedUrl": "https://example.com",
|
|
301
|
+
"finalUrl": "https://example.com",
|
|
302
|
+
"inputUrl": "https://example.com",
|
|
303
|
+
"title": "Example Domain",
|
|
304
|
+
"markdown": "# Example Domain\n\nThis domain is for use in illustrative examples...",
|
|
305
|
+
"truncated": false
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
| Field | Type | Description |
|
|
310
|
+
| ------------- | ---------- | -------------------------------------------------- |
|
|
311
|
+
| `url` | `string` | The canonical URL (pre-raw-transform) |
|
|
312
|
+
| `inputUrl` | `string` | The original URL provided by the caller |
|
|
313
|
+
| `resolvedUrl` | `string` | The normalized/transformed URL that was fetched |
|
|
314
|
+
| `finalUrl` | `string?` | Final response URL after redirects |
|
|
315
|
+
| `title` | `string?` | Extracted page title |
|
|
316
|
+
| `metadata` | `object?` | Extracted metadata (title, description, author...) |
|
|
317
|
+
| `markdown` | `string?` | Extracted content in Markdown format |
|
|
318
|
+
| `fromCache` | `boolean?` | Whether the response was served from cache |
|
|
319
|
+
| `fetchedAt` | `string?` | ISO timestamp for fetch/cache retrieval |
|
|
320
|
+
| `contentSize` | `number?` | Full markdown size before inline truncation |
|
|
321
|
+
| `truncated` | `boolean?` | Whether inline markdown was truncated |
|
|
322
|
+
| `error` | `string?` | Error message if the request failed |
|
|
323
|
+
| `statusCode` | `number?` | HTTP status code for failed requests |
|
|
324
|
+
| `details` | `object?` | Additional error details |
|
|
325
|
+
|
|
326
|
+
##### Annotations
|
|
327
|
+
|
|
328
|
+
| Annotation | Value |
|
|
329
|
+
| ----------------- | ------- |
|
|
330
|
+
| `readOnlyHint` | `true` |
|
|
331
|
+
| `destructiveHint` | `false` |
|
|
332
|
+
| `idempotentHint` | `true` |
|
|
333
|
+
| `openWorldHint` | `true` |
|
|
334
|
+
|
|
335
|
+
##### Async Task Execution
|
|
336
|
+
|
|
337
|
+
The `fetch-url` tool supports optional async task execution. Include a `task` field in the tool call to run the fetch in the background:
|
|
338
|
+
|
|
339
|
+
```json
|
|
340
|
+
{
|
|
341
|
+
"method": "tools/call",
|
|
342
|
+
"params": {
|
|
343
|
+
"name": "fetch-url",
|
|
344
|
+
"arguments": { "url": "https://example.com" },
|
|
345
|
+
"task": { "ttl": 30000 }
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
Then poll `tasks/get` until the task status is `completed` or `failed`, and retrieve the result via `tasks/result`.
|
|
351
|
+
|
|
352
|
+
### Prompts
|
|
353
|
+
|
|
354
|
+
| Name | Description |
|
|
355
|
+
| ---------- | ------------------------------------------------ |
|
|
356
|
+
| `get-help` | Returns server usage guidance and workflow hints |
|
|
357
|
+
|
|
358
|
+
### Resources
|
|
359
|
+
|
|
360
|
+
| URI Pattern | MIME Type | Description |
|
|
361
|
+
| ------------------------------------- | --------------- | ---------------------------------------------------- |
|
|
362
|
+
| `internal://instructions` | `text/markdown` | Server instructions and usage guidance |
|
|
363
|
+
| `internal://cache/{namespace}/{hash}` | `text/markdown` | Cached markdown entries from prior `fetch-url` calls |
|
|
364
|
+
|
|
365
|
+
### Completions
|
|
366
|
+
|
|
367
|
+
- `completion/complete` supports `internal://cache/{namespace}/{hash}` template variables:
|
|
368
|
+
- `namespace`
|
|
369
|
+
- `hash` (optionally filtered by `context.arguments.namespace`)
|
|
370
|
+
|
|
371
|
+
### Tasks
|
|
372
|
+
|
|
373
|
+
The server declares full MCP task support:
|
|
374
|
+
|
|
375
|
+
| Endpoint | Description |
|
|
376
|
+
| -------------- | ------------------------------------ |
|
|
377
|
+
| `tasks/list` | List tasks (scoped to session/owner) |
|
|
378
|
+
| `tasks/get` | Get task status by ID |
|
|
379
|
+
| `tasks/result` | Retrieve completed task result |
|
|
380
|
+
| `tasks/cancel` | Cancel an in-flight task |
|
|
381
|
+
|
|
382
|
+
## HTTP Mode Endpoints
|
|
383
|
+
|
|
384
|
+
| Method | Path | Auth | Description |
|
|
385
|
+
| -------- | ----------------------------------- | ----- | ---------------------------------------- |
|
|
386
|
+
| `GET` | `/health` | No | Health check (minimal payload) |
|
|
387
|
+
| `GET` | `/health?verbose=true` | Yes\* | Detailed diagnostics and runtime metrics |
|
|
388
|
+
| `POST` | `/mcp` | Yes | MCP JSON-RPC (Streamable HTTP) |
|
|
389
|
+
| `GET` | `/mcp` | Yes | SSE stream for server-initiated messages |
|
|
390
|
+
| `DELETE` | `/mcp` | Yes | Terminate MCP session |
|
|
391
|
+
| `GET` | `/mcp/downloads/{namespace}/{hash}` | Yes | Download cached content |
|
|
392
|
+
|
|
393
|
+
\* `verbose=true` can be read without auth only for local-only deployments (`ALLOW_REMOTE=false`).
|
|
394
|
+
|
|
395
|
+
### Session Behavior
|
|
396
|
+
|
|
397
|
+
- Sessions are created on the first `POST /mcp` request with an `initialize` message
|
|
398
|
+
- Session ID is returned in the `mcp-session-id` response header
|
|
399
|
+
- Sessions expire after 30 minutes of inactivity (max 200 concurrent)
|
|
400
|
+
|
|
401
|
+
### Authentication
|
|
402
|
+
|
|
403
|
+
- **Static tokens**: Set `ACCESS_TOKENS` or `API_KEY` environment variables; pass as `Authorization: Bearer <token>`
|
|
404
|
+
- **OAuth**: Configure `OAUTH_*` environment variables to enable OAuth 2.0 token introspection
|
|
405
|
+
|
|
406
|
+
## Client Configuration Examples
|
|
407
|
+
|
|
408
|
+
<details>
|
|
409
|
+
<summary>VS Code / VS Code Insiders</summary>
|
|
410
|
+
|
|
411
|
+
Add to your VS Code settings (`.vscode/mcp.json` or User Settings):
|
|
412
|
+
|
|
413
|
+
```json
|
|
414
|
+
{
|
|
415
|
+
"servers": {
|
|
416
|
+
"fetch-url-mcp": {
|
|
417
|
+
"command": "npx",
|
|
418
|
+
"args": ["-y", "@j0hanz/fetch-url-mcp@latest", "--stdio"]
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
</details>
|
|
425
|
+
|
|
426
|
+
<details>
|
|
427
|
+
<summary>Claude Desktop</summary>
|
|
428
|
+
|
|
429
|
+
Add to `claude_desktop_config.json`:
|
|
430
|
+
|
|
431
|
+
```json
|
|
432
|
+
{
|
|
433
|
+
"mcpServers": {
|
|
434
|
+
"fetch-url-mcp": {
|
|
435
|
+
"command": "npx",
|
|
436
|
+
"args": ["-y", "@j0hanz/fetch-url-mcp@latest", "--stdio"]
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
</details>
|
|
443
|
+
|
|
444
|
+
<details>
|
|
445
|
+
<summary>Cursor</summary>
|
|
446
|
+
|
|
447
|
+
[](https://cursor.com/install-mcp?name=fetch-url-mcp&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkBqMGhhbnovZmV0Y2gtdXJsLW1jcEBsYXRlc3QiLCItLXN0ZGlvIl19)
|
|
448
|
+
|
|
449
|
+
Or manually add to Cursor MCP settings:
|
|
450
|
+
|
|
451
|
+
```json
|
|
452
|
+
{
|
|
453
|
+
"mcpServers": {
|
|
454
|
+
"fetch-url-mcp": {
|
|
455
|
+
"command": "npx",
|
|
456
|
+
"args": ["-y", "@j0hanz/fetch-url-mcp@latest", "--stdio"]
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
</details>
|
|
463
|
+
|
|
464
|
+
<details>
|
|
465
|
+
<summary>Windsurf</summary>
|
|
466
|
+
|
|
467
|
+
Add to your Windsurf MCP configuration:
|
|
468
|
+
|
|
469
|
+
```json
|
|
470
|
+
{
|
|
471
|
+
"mcpServers": {
|
|
472
|
+
"fetch-url-mcp": {
|
|
473
|
+
"command": "npx",
|
|
474
|
+
"args": ["-y", "@j0hanz/fetch-url-mcp@latest", "--stdio"]
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
</details>
|
|
481
|
+
|
|
482
|
+
## Security
|
|
483
|
+
|
|
484
|
+
### SSRF Protection
|
|
485
|
+
|
|
486
|
+
Fetch URL blocks requests to private and internal network addresses:
|
|
487
|
+
|
|
488
|
+
- **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`
|
|
489
|
+
- **Blocked IPv6**: `::1`, `fc00::/7`, `fe80::/10`, IPv4-mapped private addresses (`::ffff:10.*`, etc.)
|
|
490
|
+
- **Cloud metadata**: `169.254.169.254` (AWS), `metadata.google.internal`, `metadata.azure.com`, `100.100.100.200` (Azure IMDS)
|
|
491
|
+
|
|
492
|
+
DNS preflight checks run on every redirect hop to prevent DNS rebinding attacks.
|
|
493
|
+
|
|
494
|
+
### Stdio Transport Safety
|
|
495
|
+
|
|
496
|
+
The server never writes non-protocol data to stdout. All logs and diagnostics go to stderr.
|
|
497
|
+
|
|
498
|
+
### Rate Limiting
|
|
499
|
+
|
|
500
|
+
HTTP mode enforces a rate limit of 100 requests per 60-second window per client.
|
|
501
|
+
|
|
502
|
+
### Content Safety
|
|
503
|
+
|
|
504
|
+
- HTML downloads are capped at 10 MB
|
|
505
|
+
- Worker threads run in isolation with configurable resource limits
|
|
506
|
+
- Auth tokens are stored in-memory only and compared using timing-safe equality
|
|
507
|
+
|
|
508
|
+
## Development Workflow
|
|
509
|
+
|
|
510
|
+
### Install Dependencies
|
|
511
|
+
|
|
512
|
+
```bash
|
|
513
|
+
npm install
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
### Scripts
|
|
517
|
+
|
|
518
|
+
| Script | Command | Description |
|
|
519
|
+
| --------------- | ----------------------- | -------------------------------------------- |
|
|
520
|
+
| `dev` | `npm run dev` | TypeScript watch mode |
|
|
521
|
+
| `dev:run` | `npm run dev:run` | Run compiled output with watch + `.env` |
|
|
522
|
+
| `build` | `npm run build` | Clean, compile, copy assets, make executable |
|
|
523
|
+
| `start` | `npm start` | Run compiled server |
|
|
524
|
+
| `test` | `npm test` | Run test suite (Node.js native test runner) |
|
|
525
|
+
| `test:coverage` | `npm run test:coverage` | Run tests with coverage |
|
|
526
|
+
| `lint` | `npm run lint` | ESLint |
|
|
527
|
+
| `lint:fix` | `npm run lint:fix` | ESLint with auto-fix |
|
|
528
|
+
| `format` | `npm run format` | Prettier |
|
|
529
|
+
| `type-check` | `npm run type-check` | TypeScript type checking |
|
|
530
|
+
| `inspector` | `npm run inspector` | Build and launch MCP Inspector |
|
|
531
|
+
|
|
532
|
+
## Build and Release
|
|
533
|
+
|
|
534
|
+
```bash
|
|
535
|
+
npm run build # Clean → Compile → Copy Assets → chmod
|
|
536
|
+
npm run prepublishOnly # Lint → Type-Check → Build
|
|
537
|
+
npm publish # Publish to npm
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
The `prepare` script runs `npm run build` automatically on `npm install` from source.
|
|
541
|
+
|
|
542
|
+
## Troubleshooting
|
|
543
|
+
|
|
544
|
+
### MCP Inspector
|
|
545
|
+
|
|
546
|
+
Use the built-in inspector to test the server interactively:
|
|
547
|
+
|
|
548
|
+
```bash
|
|
549
|
+
npm run inspector
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
This builds the project and launches `@modelcontextprotocol/inspector` pointing to the compiled server.
|
|
553
|
+
|
|
554
|
+
### Common Issues
|
|
555
|
+
|
|
556
|
+
| Issue | Solution |
|
|
557
|
+
| ------------------------- | ----------------------------------------------------------------------------------------------------------- |
|
|
558
|
+
| `VALIDATION_ERROR` on URL | URL is blocked (private IP/localhost) or malformed. Do not retry. |
|
|
559
|
+
| `queue_full` error | Usually auto-handled by worker fallback to in-process transform; if surfaced, retry or use async task mode. |
|
|
560
|
+
| Garbled output | Binary content (images, PDFs) cannot be converted. Ensure the URL serves HTML. |
|
|
561
|
+
| No output in stdio mode | Ensure `--stdio` flag is passed. Without it, the server starts in HTTP mode. |
|
|
562
|
+
| Auth errors in HTTP mode | Set `ACCESS_TOKENS` or `API_KEY` env var and pass as `Authorization: Bearer <token>`. |
|
|
563
|
+
|
|
564
|
+
### Stdout / Stderr Guidance
|
|
565
|
+
|
|
566
|
+
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.
|
|
567
|
+
|
|
568
|
+
## License
|
|
569
|
+
|
|
570
|
+
[MIT](https://opensource.org/licenses/MIT)
|
package/dist/AGENTS.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
> Purpose: High-signal context and strict guidelines for AI agents working in this repository.
|
|
4
|
+
|
|
5
|
+
## 1) Project Context
|
|
6
|
+
|
|
7
|
+
- **Domain:** MCP (Model Context Protocol) server that fetches web pages and converts HTML to clean, AI-readable Markdown.
|
|
8
|
+
- **Tech Stack (Verified):**
|
|
9
|
+
- **Languages:** TypeScript 5.9+ (`package.json` → `"typescript": "^5.9.3"`), ESM (`"type": "module"`)
|
|
10
|
+
- **Frameworks:** `@modelcontextprotocol/sdk` v1.x (`"^1.26.0"` in `package.json`), Node.js ≥24 (`engines`)
|
|
11
|
+
- **Key Libraries:**
|
|
12
|
+
- `zod` v4 (`"^4.3.6"`) — input/output schema validation
|
|
13
|
+
- `@mozilla/readability` (`"^0.6.0"`) — article extraction
|
|
14
|
+
- `linkedom` (`"^0.18.12"`) — DOM parsing (no browser required)
|
|
15
|
+
- `node-html-markdown` (`"^2.0.0"`) — HTML→Markdown conversion
|
|
16
|
+
- **Architecture:** Single-package MCP server with modular source files (one concern per file). Supports both **stdio** and **Streamable HTTP** transports. Features an in-memory cache, task API, worker pool for transforms, IP blocklist, session management, and OAuth/static-token auth.
|
|
17
|
+
|
|
18
|
+
## 2) Repository Map (High-Level)
|
|
19
|
+
|
|
20
|
+
- `src/` — All production TypeScript source
|
|
21
|
+
- `index.ts` — CLI entrypoint (shebang, arg parsing, transport selection, shutdown)
|
|
22
|
+
- `mcp.ts` — McpServer creation, resource/tool registration, task handlers
|
|
23
|
+
- `tools.ts` — `fetch-url` tool definition, pipeline, error mapping, progress reporting
|
|
24
|
+
- `http-native.ts` — Streamable HTTP server (sessions, auth, health endpoint)
|
|
25
|
+
- `config.ts` — Centralized env-based configuration (all settings)
|
|
26
|
+
- `fetch.ts` — URL normalization, HTTP fetching
|
|
27
|
+
- `transform.ts` / `workers/` — HTML→Markdown transform with worker pool
|
|
28
|
+
- `cache.ts` — In-memory content cache
|
|
29
|
+
- `errors.ts` — `FetchError`, `getErrorMessage`, error helpers
|
|
30
|
+
- `session.ts` — HTTP session store and lifecycle
|
|
31
|
+
- `ip-blocklist.ts` — Private/metadata IP blocking
|
|
32
|
+
- `observability.ts` — Structured logging with request context
|
|
33
|
+
- `tests/` — All test files (`*.test.ts`), run against compiled `dist/`
|
|
34
|
+
- `scripts/` — Build orchestration (`tasks.mjs`), validation scripts
|
|
35
|
+
- `assets/` — Static assets (logo SVG)
|
|
36
|
+
- `.github/workflows/` — CI/CD (publish to npm on release)
|
|
37
|
+
- `.github/instructions/` — Agent instruction files for MCP server conventions
|
|
38
|
+
|
|
39
|
+
> Ignore: `dist/`, `node_modules/`, `.tsbuildinfo`
|
|
40
|
+
|
|
41
|
+
## 3) Operational Commands (Verified)
|
|
42
|
+
|
|
43
|
+
- **Environment:** Node.js ≥24, npm
|
|
44
|
+
- **Install:** `npm ci` (CI from `publish.yml`) or `npm install`
|
|
45
|
+
- **Dev:** `npm run dev` (tsc watch) / `npm run dev:run` (run with .env + watch)
|
|
46
|
+
- **Build:** `npm run build` (clean → compile → validate instructions → copy assets → chmod; via `scripts/tasks.mjs`)
|
|
47
|
+
- **Test:** `npm test` (builds first, then runs `node --test` on `tests/**/*.test.ts` against compiled `dist/`)
|
|
48
|
+
- **Type-check:** `npm run type-check` (tsc --noEmit)
|
|
49
|
+
- **Lint:** `npm run lint` (ESLint) / `npm run lint:fix`
|
|
50
|
+
- **Format:** `npm run format` (Prettier)
|
|
51
|
+
- **Dead code:** `npm run knip` / `npm run knip:fix`
|
|
52
|
+
- **Inspector:** `npm run inspector` (build + launch MCP Inspector on stdio)
|
|
53
|
+
|
|
54
|
+
## 4) Coding Standards (Style & Patterns)
|
|
55
|
+
|
|
56
|
+
- **Naming:** `camelCase` for variables/functions, `PascalCase` for types/classes/enums, `UPPER_CASE` for constants. Enforced via `@typescript-eslint/naming-convention` in `eslint.config.mjs`.
|
|
57
|
+
- **Imports:**
|
|
58
|
+
- **Type-only imports required:** `import type { X }` / `import { type X }` (ESLint `consistent-type-imports` rule: error)
|
|
59
|
+
- **Named exports only:** no default exports
|
|
60
|
+
- `.js` extensions in local imports (NodeNext module resolution)
|
|
61
|
+
- Sorted by `@trivago/prettier-plugin-sort-imports`
|
|
62
|
+
- Unused imports are errors (`eslint-plugin-unused-imports`)
|
|
63
|
+
- **TypeScript Strictness** (all enabled in `tsconfig.json`):
|
|
64
|
+
- `strict`, `noUncheckedIndexedAccess`, `verbatimModuleSyntax`, `isolatedModules`
|
|
65
|
+
- `exactOptionalPropertyTypes`, `noImplicitOverride`, `noImplicitReturns`, `noFallthroughCasesInSwitch`
|
|
66
|
+
- **Explicit return types** required on functions (`explicit-function-return-type`: error)
|
|
67
|
+
- **No `any`:** `@typescript-eslint/no-explicit-any`: error
|
|
68
|
+
- **Schemas:** Use `z.strictObject()` for all Zod schemas; add `.describe()` to every parameter; add bounds (`.min()`/`.max()`)
|
|
69
|
+
- **Tool pattern:** One MCP tool per registration; return both `content` (JSON stringified text block) and `structuredContent`; use `isError: true` on failure (never throw uncaught)
|
|
70
|
+
- **Error handling:** Prefer tool execution errors over protocol errors; centralized via `getErrorMessage()`, `createToolErrorResponse()`, `handleToolError()` in `errors.ts`/`tools.ts`
|
|
71
|
+
- **Logging:** Never write to `stdout` in stdio mode; use `logInfo`/`logError`/`logWarn`/`logDebug` from `observability.ts` (writes to stderr)
|
|
72
|
+
- **Patterns Observed:**
|
|
73
|
+
- Configuration via environment variables, parsed once at import in `config.ts`
|
|
74
|
+
- Worker pool pattern for CPU-bound transforms (`src/workers/`, `src/transform.ts`)
|
|
75
|
+
- Inline content truncation with safe code-fence closing (`tools.ts`)
|
|
76
|
+
- Session-scoped task ownership for async tool execution (`mcp.ts`)
|
|
77
|
+
|
|
78
|
+
## 5) Agent Behavioral Rules (Do Nots)
|
|
79
|
+
|
|
80
|
+
- Do not introduce new dependencies without updating manifests/lockfiles via the package manager.
|
|
81
|
+
- Do not edit `package-lock.json` manually.
|
|
82
|
+
- Do not commit secrets; never print `.env` values; use existing `config.ts` env parsing.
|
|
83
|
+
- Do not change public APIs (tool schemas, MCP resource URIs) without updating docs/tests and noting migration impact.
|
|
84
|
+
- Do not disable or bypass existing ESLint/TypeScript rules without explicit approval.
|
|
85
|
+
- Do not use default exports; always use named exports.
|
|
86
|
+
- Do not use `any`; use `unknown` and narrow with type guards (`type-guards.ts`).
|
|
87
|
+
- Do not write to `stdout` in production code (corrupts JSON-RPC stdio transport); use `process.stderr` or observability helpers.
|
|
88
|
+
- Do not add `.js` extension-less local imports — NodeNext resolution requires `.js` extensions.
|
|
89
|
+
- Do not use Zod v3 APIs (`z.object()` → use `z.strictObject()`).
|
|
90
|
+
- Do not throw uncaught exceptions from tool handlers — return `isError: true` responses.
|
|
91
|
+
|
|
92
|
+
## 6) Testing Strategy (Verified)
|
|
93
|
+
|
|
94
|
+
- **Framework:** `node:test` (built-in Node.js test runner) + `node:assert/strict`
|
|
95
|
+
- **Where tests live:** `tests/` directory (all `*.test.ts` files)
|
|
96
|
+
- **Approach:**
|
|
97
|
+
- Tests run against **compiled output** (`dist/`) — build is a prerequisite
|
|
98
|
+
- Unit tests with `t.mock.method()` for mocking (`globalThis.fetch`, library methods)
|
|
99
|
+
- No external test dependencies (no Jest, Vitest, etc.)
|
|
100
|
+
- Patterns: describe/it blocks, setUp/tearDown via `after()`, config mutations restored in `finally`
|
|
101
|
+
- ~45 test files covering tools, cache, transform, URL handling, HTTP server, sessions, errors, etc.
|
|
102
|
+
- Coverage available via `npm run test:coverage` (`--experimental-test-coverage`)
|
|
103
|
+
|
|
104
|
+
## 7) Common Pitfalls (Verified)
|
|
105
|
+
|
|
106
|
+
- **Tests require build first** — `npm test` runs the build automatically, but if running `node --test` manually, ensure `dist/` is current.
|
|
107
|
+
- **CI uses Node 20 but `engines` requires ≥24** — local dev/tests must use Node ≥24; the publish workflow pins Node 20 for npm compatibility.
|
|
108
|
+
- **Config mutations in tests** — tests that modify `config.*` properties must restore original values in `finally` blocks to avoid leaking state across tests.
|
|
109
|
+
- **Worker pool shutdown** — tests using the transform pipeline should call `shutdownTransformWorkerPool()` in `after()` hooks to prevent hanging processes.
|
|
110
|
+
- **Shebang line** — `src/index.ts` must keep `#!/usr/bin/env node` as the exact first line (no BOM, no blank lines before it).
|
|
111
|
+
|
|
112
|
+
## 8) Evolution Rules
|
|
113
|
+
|
|
114
|
+
- If conventions change, include an `AGENTS.md` update in the same PR.
|
|
115
|
+
- If a command is corrected after failures, record the final verified command here.
|