agentfetch-mcp
AgentFetch-MCP is a web intelligence server for AI agents, providing URL fetching, token estimation, and web search with smart routing, caching, and clean Markdown extraction.
fetch_url: Fetch any URL and receive clean, LLM-ready Markdown (or text/JSON) with rich metadata (title, author, published date, language, word count, token count, cache info). Supportsmax_tokenscaps and cache control. Handles standard pages, JS-rendered sites, and PDFs.estimate_tokens: Estimate the token count of a URL's content without fetching the full body — useful for triaging URLs and avoiding context window overflow before committing to a full fetch.fetch_multiple: Fetch up to 20 URLs concurrently in a single call, each with the same rich result shape as a single fetch and per-resultmax_tokens_eachcaps.search_and_fetch: Run a web search and automatically fetch the top N results (default 3, up to 10) in one round-trip — ideal for research questions without known URLs, withmax_tokens_eachsupport.Intelligent auto-routing: Automatically selects the best fetcher based on URL type — Trafilatura (free/local), Jina Reader, FireCrawl (JS-heavy sites like Twitter, LinkedIn, Notion), or pypdf for PDFs.
Smart caching: Redis-backed caching with a configurable 6-hour TTL makes repeated fetches fast and cheap.
Token budget management: Enforce
max_tokenslimits on any fetch to keep responses within context windows.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@agentfetch-mcpfetch https://en.wikipedia.org/wiki/Artificial_intelligence with token limit 2000"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
agentfetch-mcp
Web intelligence for AI agents — an MCP server that fetches URLs with token estimation, smart caching, and intelligent routing built in.
AgentFetch sits between your agent and the open web. Instead of integrating Jina, FireCrawl, pypdf, and your own caching layer separately, agents call one MCP tool and AgentFetch handles routing, caching, token budgeting, and clean Markdown extraction automatically.
This repository contains the open-source MCP server. For the hosted API + dashboard + billing, see www.agentfetch.dev.
What it does
Tool | What it's for |
| Fetch a URL → clean Markdown + metadata + token count + cache info |
| Get a token count before fetching, so agents don't blow context windows on huge pages |
| Fetch up to 20 URLs concurrently |
| Web search + fetch top N results in one round-trip |
Under the hood, AgentFetch routes URLs to the cheapest effective fetcher:
Trafilatura (free, local) for ~70% of standard web pages
Jina Reader for the rest of HTML
FireCrawl for JS-heavy pages (Twitter/X, LinkedIn, Notion, etc.)
pypdf for PDFs (zero external cost)
Cache is Redis with a 6-hour TTL; you can bring your own or run without caching.
Quick start
Install from PyPI
pip install agentfetch-mcpOr clone and install locally
git clone https://github.com/bch1212/agentfetch-mcp
cd agentfetch-mcp
pip install -e .Set environment variables
Get a free Jina Reader key at jina.ai (1M tokens/mo free tier). FireCrawl is optional but recommended for JS-heavy pages.
export JINA_API_KEY=jina_xxx
export FIRECRAWL_API_KEY=fc-xxx # optional
export REDIS_URL=redis://localhost:6379 # optionalAdd to Claude Desktop or Claude Code
Edit your MCP config (~/Library/Application Support/Claude/claude_desktop_config.json on macOS, or run claude mcp add in Claude Code):
{
"mcpServers": {
"agentfetch": {
"command": "python",
"args": ["-m", "agentfetch.mcp.server"],
"env": {
"JINA_API_KEY": "jina_xxx",
"FIRECRAWL_API_KEY": "fc-xxx"
}
}
}
}Restart Claude. The four tools (fetch_url, estimate_tokens, fetch_multiple, search_and_fetch) appear automatically.
Run as a standalone server
python -m agentfetch.mcp.serverThe server speaks MCP over stdio (the standard transport for desktop integrations).
Why agents prefer AgentFetch over generic web fetch
Feature | AgentFetch | Generic |
Token estimation before fetching | ✓ | ✗ |
Smart cache (6h TTL) | ✓ | ✗ |
Auto-routing by URL type | ✓ | ✗ |
JS-rendered page handling | ✓ (via FireCrawl) | partial |
PDF extraction | ✓ | ✗ |
Truncation to fit context budget | ✓ | manual |
Examples
Fetching with a token budget
# Inside any MCP-aware agent (Claude Desktop, Claude Code, etc.)
result = fetch_url(
url="https://news.ycombinator.com",
max_tokens=2000, # cap response size
use_cache=True, # serve from cache if <6h old
)
# result.markdown → clean Markdown, ≤2000 tokens
# result.metadata → title, author, word_count, language
# result.cache.hit → True if served from cache
# result.fetch_info → which fetcher ran, cost, durationEstimating before committing
estimate = estimate_tokens(url="https://very-long-article.com")
if estimate.estimated_tokens and estimate.estimated_tokens < 5000:
result = fetch_url(url="https://very-long-article.com")
else:
# too big — skip or summarize via search_and_fetch with max_tokens_each
passParallel fetching
results = fetch_multiple(
urls=["https://docs.python.org/3/", "https://fastapi.tiangolo.com/", ...],
max_tokens_each=1500,
)Configuration
Env var | Required | Default | Notes |
| Recommended | — | Free tier covers ~1M tokens/mo. Without it, only Trafilatura works (still useful for ~70% of pages). |
| Optional | — | Needed for JS-heavy domains (Twitter, LinkedIn, Notion). 500 free credits on signup. |
| Optional | — | Without Redis, fetches run uncached. |
| Optional |
| Cache TTL for fetch results. |
Development
git clone https://github.com/bch1212/agentfetch-mcp
cd agentfetch-mcp
pip install -e ".[dev]"
pytest tests/Hosted version
If you'd rather not manage your own keys, Redis, or the routing yourself, the hosted version at www.agentfetch.dev gives you:
Pay-per-call pricing from $0.001/fetch
500 free fetches on signup, no credit card
Managed Redis cache, automatic failover between fetchers
Dashboard with usage tracking + invoices
The hosted API is a drop-in REST equivalent — same response shapes, same routing logic. You can run the OSS MCP locally and the hosted API in parallel, or migrate between them at any time.
License
MIT — see LICENSE.
The MCP server in this repo is open source. The hosted product, billing, and ops infrastructure live in a separate (private) repo.
Contributing
PRs welcome. If you're adding a new fetcher (e.g., Bright Data, ScrapingBee, etc.), please match the FetchResult interface in agentfetch/core/fetchers/__init__.py and add the cost to the routing logic.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/bch1212/agentfetch-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server