Fetch the public web in agent-ready formats.

A lightweight, agent-friendly MCP server (mcp-fetch-server) and local CLI (mcp-fetch) for HTML, Markdown, Readability articles, plain text, JSON, and YouTube transcripts—with custom headers, HTTP/SOCKS proxies, pagination, and built-in SSRF protection. Supports Node.js >= 22 LTS and Bun.

Fetch MCP pixel-art banner showing a classic globe transferring documents to a terminal
01

Quickstart

Run mcp-fetch-server over stdio or stateless MCP 2025-11-25 Streamable HTTP, or run the same fetcher directly from your shell via mcp-fetch.

mcp.json
{
  "mcpServers": {
    "fetch": {
      "command": "npx",
      "args": ["mcp-fetch-server"]
    }
  }
}
# Start stateless MCP 2025-11-25 Streamable HTTP on http://127.0.0.1:3000/mcp
npx mcp-fetch-server --http --host 127.0.0.1 --port 3000
# Run directly with npx or install globally with: npm install -g mcp-fetch-server
npx -p mcp-fetch-server mcp-fetch readable https://example.com
npx -p mcp-fetch-server mcp-fetch transcript 'https://www.youtube.com/watch?v=jNQXAC9IVRw' --lang en
02

MCP Clients

Works out of the box with Claude, Gemini, OpenAI, Cursor, and MCP Inspector.

mcp.json (with limits & proxy)
{
  "mcpServers": {
    "fetch": {
      "command": "npx",
      "args": ["mcp-fetch-server"],
      "env": {
        "DEFAULT_LIMIT": "50000",
        "MAX_RESPONSE_BYTES": "10485760",
        "HTTPS_PROXY": "socks5://127.0.0.1:1080"
      }
    }
  }
}
# Terminal 1 — launch Streamable HTTP server
npx mcp-fetch-server --http --port 3000

# Terminal 2 — connect with stock MCP Inspector
npx @modelcontextprotocol/inspector --url http://127.0.0.1:3000/mcp
# Register Fetch MCP in Claude Code
claude mcp add fetch -- npx mcp-fetch-server
03

MCP Tools & Formats

Six read-only tools for pulling public URLs in the exact format your agent needs.

fetch_readable Extracts main article content via Mozilla Readability, converts to Markdown, and prepends # <title> when present. markdown
fetch_markdown Fetches a public URL, strips <script> and <style> elements, and converts the document to Markdown via Turndown. markdown
fetch_text Strips <script>, <style>, and HTML tags, returning whitespace-normalized plain text. text/plain
fetch_json Fetches a JSON endpoint, validates via JSON.parse, and returns compact JSON (failing explicitly on invalid JSON). json
fetch_html Retrieves a public URL and returns its unmodified UTF-8 HTML body. text/html
fetch_transcript Fetches YouTube captions (tries local yt-dlp with manual & auto-generated subtitles first, falling back to direct watch-page + XML extraction). Accepts optional lang (default "en") and lists available codes when missing. transcript

Common Tool Parameters

url Public http: or https: URL to fetch. string · req
headers Optional custom request headers (Record<string, string>); CR/LF and invalid header characters are rejected. object · opt
max_length Maximum characters to return (defaults to DEFAULT_LIMIT / 5000; 0 = unlimited). Returns sliced text only with no footer. number · opt
start_index Zero-based starting character index for pagination (default 0; returns "" if at or past output length). number · opt
lang fetch_transcript only. Caption language code (default "en"; matches exact code first, then regional prefix like en → en-US). string · opt
04

Local CLI

Use mcp-fetch <command> <url> [flags] directly from terminals or scripts. Subcommands mirror the MCP tools: html, markdown, readable, text, json, and transcript. Errors write to stderr and exit 1.

--header <K:V> Custom request header (repeatable; case-insensitive last value wins). all commands
--max-length <N> Maximum characters to return (0 = unlimited). all commands
--start-index <N> Start content from this character offset. all commands
--proxy <URL> Explicit proxy override (http, https, socks4, socks4a, socks5, socks5h, or host:port; bypasses NO_PROXY). CLI only
--lang <code> Caption language code (default en). Rejected with a validation error on non-transcript subcommands. transcript
--help / --version Print usage summary or package version (2.0.1). meta
CLI examples
# Extract readable article Markdown without boilerplate
mcp-fetch readable https://example.com/blog/post

# Fetch YouTube transcript (quote URLs containing '?' in zsh)
mcp-fetch transcript 'https://www.youtube.com/watch?v=jNQXAC9IVRw' --lang en

# Pass custom headers and window bounds
mcp-fetch html https://example.com --header "Accept-Language: en-US" --max-length 10000

# Route through a SOCKS5 proxy
mcp-fetch json https://api.example.com/data --proxy socks5://127.0.0.1:1080
05

Streamable HTTP

Launch mcp-fetch-server --http to expose stateless MCP 2025-11-25 Streamable HTTP on POST /mcp. Requests validate both Host and Origin headers against the bound address (returning 403 on mismatch). Unknown paths (including legacy /sse) return 404, and non-POST methods return 405.

--http Enable stateless Streamable HTTP mode instead of default stdio. default: off
--host <addr> Bind address for the HTTP listener (requires --http). 127.0.0.1
--port <n> Listen port 1–65535 (requires --http). 3000
06

Proxies & Operator Limits

mcp-fetch-server parses DEFAULT_LIMIT and MAX_RESPONSE_BYTES at startup and exits 1 immediately if invalid. Proxy routing is re-evaluated on every redirect hop and supports HTTP, HTTPS, SOCKS4/4a/5/5h, and bare host:port.

DEFAULT_LIMIT Default character limit for responses (non-negative integer; 0 = unlimited; fails explicitly if invalid). 5000
MAX_RESPONSE_BYTES Maximum raw wire and decompressed response size in bytes (positive integer; also enforced on yt-dlp subtitle files). 10 MB
HTTPS_PROXY Proxy URL for https:// targets (HTTPS_PROXY → https_proxy → HTTP_PROXY → http_proxy → ALL_PROXY → all_proxy). https:
HTTP_PROXY / ALL_PROXY Proxy URL for http:// targets and fallback for all HTTP(S) traffic (including yt-dlp --proxy). http/all
NO_PROXY / no_proxy Comma-separated hosts, .domain / *.domain suffixes, :port entries, [ipv6]:port, or * bypassing Operator env proxies (non-empty NO_PROXY takes precedence). bypass
07

SSRF & Security Model

SECURITY MODEL

Fail-closed by default.

Every request, redirect hop, DNS lookup, decompression stream, and MCP tool call fails closed—blocked IPs, invalid limits, bad proxies, and unexpected arguments error explicitly instead of falling back.

Read Invariants ↗
SSRF Blocking Restricts all URLs and up to 10 redirect hops to http:/https:; blocks localhost, *.localhost, and all IANA-reserved IPv4/IPv6 ranges (including IPv4-mapped IPv6 and multicast). fail-closed
DNS Pinning Direct connections validate all resolved DNS records and pin them straight to sockets to prevent DNS rebinding; proxied connections delegate hostname DNS to the proxy. no TOCTOU
YouTube Isolation Restricts transcript tools to allowlisted YouTube domains, validates lang strictly, passes -- end-of-options sentinel to yt-dlp, and never swallows SSRF/validation errors into fallback. allowlist
Header Hygiene Strips Authorization, Cookie, and Proxy-Authorization across cross-origin redirects and cross-origin YouTube caption track URLs; rejects CR/LF injection. cross-origin
Resource Caps Enforces MAX_RESPONSE_BYTES across declared Content-Length, raw wire bytes, decompressed gzip/deflate/br streams, and yt-dlp files; rejects binary Content-Types; 30s single-attempt timeout. 10 MB / 30s
Trust Boundary An Agent calling an MCP tool can never supply or override proxy routing — only Operator environment variables configure MCP proxies. Operator-only
Secret Redaction Proxy usernames and passwords are always redacted from error messages, CLI stderr, MCP tool results, and recorded test cassettes. redacted
08

v2.0 Migration Guide

Version 2.0.0 is a clean breaking release aligning tool names, CLI flags, MCP 2025-11-25 compliance, and explicit error semantics.

MCP Tools fetch_txt → fetch_text; fetch_youtube_transcript → fetch_transcript. renamed
CLI Subcommands txt → text; youtube → transcript. Added repeatable --header; --lang is now rejected on non-transcript commands. renamed
Strict Arguments Unexpected MCP tool properties (including any caller-supplied proxy) return isError: true instead of being ignored. strict
Config & Captions Invalid DEFAULT_LIMIT, MAX_RESPONSE_BYTES, or proxy URLs fail fast instead of silently falling back; missing YouTube caption languages fail listing available codes. explicit
Runtime Floor Requires Node.js >= 22 LTS or Bun (Node 18 & 20 are EOL). Node 22+
09

More Projects

Other MCP servers and agent-friendly command-line tools I build and maintain.