MCP server for fetching web URLs with token estimation, smart caching, and intelligent routing. Built for AI agents.
Project description
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_url |
Fetch a URL → clean Markdown + metadata + token count + cache info |
estimate_tokens |
Get a token count before fetching, so agents don't blow context windows on huge pages |
fetch_multiple |
Fetch up to 20 URLs concurrently |
search_and_fetch |
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-mcp
Or 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 # optional
Add 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.server
The server speaks MCP over stdio (the standard transport for desktop integrations).
Why agents prefer AgentFetch over generic web fetch
| Feature | AgentFetch | Generic web_fetch |
|---|---|---|
| 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, duration
Estimating 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
pass
Parallel fetching
results = fetch_multiple(
urls=["https://docs.python.org/3/", "https://fastapi.tiangolo.com/", ...],
max_tokens_each=1500,
)
Configuration
| Env var | Required | Default | Notes |
|---|---|---|---|
JINA_API_KEY |
Recommended | — | Free tier covers ~1M tokens/mo. Without it, only Trafilatura works (still useful for ~70% of pages). |
FIRECRAWL_API_KEY |
Optional | — | Needed for JS-heavy domains (Twitter, LinkedIn, Notion). 500 free credits on signup. |
REDIS_URL |
Optional | — | Without Redis, fetches run uncached. |
CACHE_TTL_SECONDS |
Optional | 21600 (6h) |
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agentfetch_mcp-1.0.1.tar.gz.
File metadata
- Download URL: agentfetch_mcp-1.0.1.tar.gz
- Upload date:
- Size: 23.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
507a42876958a345f6bd71df40965d6ec32d9ebfbb252e64ee9f9e7865842ad5
|
|
| MD5 |
97b4857d7538639439d922fbbac7c3f6
|
|
| BLAKE2b-256 |
2796620f6f1bd166a2b6387cc5e736c065265962327560b3aedca60f79af1db3
|
File details
Details for the file agentfetch_mcp-1.0.1-py3-none-any.whl.
File metadata
- Download URL: agentfetch_mcp-1.0.1-py3-none-any.whl
- Upload date:
- Size: 28.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3cc099ec8ed78e468f881d773d388a573176a756d2061f97b967996550896795
|
|
| MD5 |
fe93df489cb39e7919d414ecea5bc751
|
|
| BLAKE2b-256 |
db1de467397a0780f6c1a5b1038c71cbb7aba03e2cf3ff3529c65b3ae260d0d4
|