Skip to main content
Glama
bch1212

agentfetch-mcp

by bch1212

agentfetch-mcp

为 AI 智能体提供网络智能 — 一个内置了 URL 获取、令牌估算、智能缓存和智能路由功能的 MCP 服务器。

License: MIT Python 3.11+

AgentFetch 位于您的智能体与开放网络之间。智能体无需分别集成 Jina、FireCrawl、pypdf 和您自己的缓存层,只需调用一个 MCP 工具,AgentFetch 即可自动处理路由、缓存、令牌预算和整洁的 Markdown 提取。

本仓库包含开源的 MCP 服务器。如需托管 API + 仪表板 + 计费功能,请访问 www.agentfetch.dev。

功能说明

工具

用途

fetch_url

获取 URL → 整洁的 Markdown + 元数据 + 令牌计数 + 缓存信息

estimate_tokens

在获取 之前 获取令牌计数,防止智能体因页面过大而耗尽上下文窗口

fetch_multiple

并发获取最多 20 个 URL

search_and_fetch

网络搜索 + 在一次往返中获取前 N 个结果

在底层,AgentFetch 会将 URL 路由到性价比最高的有效抓取工具:

  • Trafilatura(免费,本地)用于约 70% 的标准网页

  • Jina Reader 用于其余的 HTML 页面

  • FireCrawl 用于 JS 密集型页面(Twitter/X、LinkedIn、Notion 等)

  • pypdf 用于 PDF(零外部成本)

缓存使用 Redis,TTL 为 6 小时;您可以自带 Redis 或在无缓存模式下运行。

Related MCP server: weblens-mcp

快速开始

从 PyPI 安装

pip install agentfetch-mcp

或克隆并本地安装

git clone https://github.com/bch1212/agentfetch-mcp
cd agentfetch-mcp
pip install -e .

设置环境变量

在 jina.ai 获取免费的 Jina Reader 密钥(免费层级每月 100 万令牌)。FireCrawl 是可选的,但建议用于 JS 密集型页面。

export JINA_API_KEY=jina_xxx
export FIRECRAWL_API_KEY=fc-xxx       # optional
export REDIS_URL=redis://localhost:6379  # optional

添加到 Claude Desktop 或 Claude Code

编辑您的 MCP 配置(macOS 上为 ~/Library/Application Support/Claude/claude_desktop_config.json,或在 Claude Code 中运行 claude mcp add):

{
  "mcpServers": {
    "agentfetch": {
      "command": "python",
      "args": ["-m", "agentfetch.mcp.server"],
      "env": {
        "JINA_API_KEY": "jina_xxx",
        "FIRECRAWL_API_KEY": "fc-xxx"
      }
    }
  }
}

重启 Claude。四个工具(fetch_url、estimate_tokens、fetch_multiple、search_and_fetch)将自动出现。

作为独立服务器运行

python -m agentfetch.mcp.server

该服务器通过 stdio(桌面集成的标准传输方式)进行 MCP 通信。

为什么智能体更喜欢 AgentFetch 而非通用的 web_fetch

特性

AgentFetch

通用 web_fetch

获取前令牌估算

✓

✗

智能缓存 (6h TTL)

✓

✗

按 URL 类型自动路由

✓

✗

JS 渲染页面处理

✓ (通过 FireCrawl)

部分

PDF 提取

✓

✗

截断以适应上下文预算

✓

手动

示例

在令牌预算内获取

# 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

在提交前进行估算

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

并行获取

results = fetch_multiple(
    urls=["https://docs.python.org/3/", "https://fastapi.tiangolo.com/", ...],
    max_tokens_each=1500,
)

配置

环境变量

必需

默认值

说明

JINA_API_KEY

推荐

—

免费层级每月涵盖约 100 万令牌。没有它,仅 Trafilatura 可用(仍适用于约 70% 的页面)。

FIRECRAWL_API_KEY

可选

—

JS 密集型域名(Twitter、LinkedIn、Notion)所需。注册即送 500 免费额度。

REDIS_URL

可选

—

若无 Redis,获取操作将不缓存。

CACHE_TTL_SECONDS

可选

21600 (6h)

获取结果的缓存 TTL。

开发

git clone https://github.com/bch1212/agentfetch-mcp
cd agentfetch-mcp
pip install -e ".[dev]"
pytest tests/

托管版本

如果您不想自己管理密钥、Redis 或路由,托管版本 www.agentfetch.dev 为您提供:

  • 按调用付费,单次获取低至 $0.001

  • 注册即送 500 次免费获取,无需信用卡

  • 托管的 Redis 缓存,抓取工具间自动故障转移

  • 带有使用情况跟踪和发票的仪表板

托管 API 是即插即用的 REST 等效服务 — 相同的响应格式,相同的路由逻辑。您可以本地运行 OSS MCP 并并行使用托管 API,或随时在两者之间迁移。

许可证

MIT — 参见 LICENSE。

本仓库中的 MCP 服务器是开源的。托管产品、计费和运维基础设施位于单独的(私有)仓库中。

贡献

欢迎提交 PR。如果您要添加新的抓取工具(例如 Bright Data、ScrapingBee 等),请匹配 agentfetch/core/fetchers/__init__.py 中的 FetchResult 接口,并将成本添加到路由逻辑中。

Available Tools

4 tools
estimate_tokensA

Estimate token count of a URL's content WITHOUT fetching the body.

WHEN TO USE:

  • You're considering fetching a URL but unsure if it fits your remaining context window. This call is ~10x cheaper than a full fetch.

  • You want to triage a list of candidate URLs before deciding which to actually retrieve.

IMPORTANT: Many servers omit Content-Length on dynamic / chunked responses. When that happens, this tool returns confident=false and estimated_tokens=null. In that case, call fetch_url with a max_tokens cap instead of trusting the estimate.

Args: url: The URL to estimate.

Returns: { "url": str, "success": bool, "estimated_tokens": int | null, "byte_size": int | null, "content_type": str, "confident": bool, "note": str }

ParametersJSON Schema
NameRequiredDescriptionDefault
urlYes

TDQS

A4.9/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations exist, but the description fully discloses behavior: no body fetch, 10x cheaper, fallback when Content-Length missing, and return structure with confident flag.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Well-structured with sections, but includes a full return example that is slightly verbose yet informative.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a one-parameter tool, the description covers purpose, usage, fallback, and return format completely, compensating for lack of output schema.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema has 0% coverage, but the description includes an 'Args' section explaining the url parameter, adding meaning beyond the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool estimates token count without fetching the body, and distinguishes from sibling tools like fetch_url by emphasizing it does not fetch the body.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly provides when-to-use (unsure about context window, triaging URLs) and when-not-to-use (if confident=false, use fetch_url with max_tokens).

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

fetch_multipleA

Fetch up to 20 URLs concurrently. Each result is the same shape as fetch_url.

WHEN TO USE:

  • You have a list of URLs (search results, links from a doc, sitemap) and want them retrieved in parallel rather than one at a time.

Args: urls: 1–20 URLs. Larger batches: split into multiple calls. max_tokens_each: Per-result cap. Apply this to keep total response inside your context budget — total ≈ len(urls) * max_tokens_each. use_cache: True for cache-aware fetching (default).

Returns: {"count": int, "results": [, ...]}

ParametersJSON Schema
NameRequiredDescriptionDefault
urlsYes
max_tokens_eachNo
use_cacheNo

TDQS

A4.3/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Describes concurrency and per-result token cap, but no annotations present. Lacks details on error handling, rate limits, or caching behavior beyond defaults.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Well-structured into purpose, when-to-use, args, and returns. No redundant sentences, every line contributes.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Covers purpose, usage, parameters, return shape, and concurrency limit. Could include error behavior or more details on caching, but overall sufficient for a fetch tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Provides clear explanations for all three parameters: url limit and splitting, max_tokens_each token budget guidance, and use_cache caching behavior. Adds significant value over schema-only info.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Clearly states 'Fetch up to 20 URLs concurrently' with a specific verb and resource. Distinguishes from sibling tools by highlighting concurrency and batch limit.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Includes 'WHEN TO USE' section explicitly describing scenarios. Mentions splitting large batches but does not explicitly state when not to use or name alternatives like fetch_url.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

fetch_urlA

Fetch any URL and return clean, LLM-ready Markdown with token count, metadata, and 6h caching.

WHEN TO USE:

  • You have a specific URL whose content you need.

  • You want to cap response size to stay inside your context window.

  • You want repeat fetches to be cheap (cache hits ≈ $0.0001).

  • The URL might be JS-rendered, a PDF, or behind a paywall — this tool auto-routes to the right fetcher (Trafilatura → Jina → FireCrawl → PDF).

WHEN NOT TO USE:

  • You don't know which URL to fetch — use search_and_fetch instead.

  • You have many URLs to fetch — use fetch_multiple instead.

Args: url: The URL to fetch. max_tokens: Hard cap on response size. Default unlimited. Pass this if you're tight on context budget — cheaper than over-fetching. format: "markdown" (default — recommended), "text", or "json". use_cache: True returns a cached copy if one exists (≤6h old). Pass False only when freshness matters (live news, prices).

Returns: { "url": str, "success": bool, "markdown": str, "metadata": {title, author, published_date, domain, word_count, token_count, reading_time_seconds, content_type, language}, "cache": {hit, cached_at, expires_at}, "fetch_info": {fetcher_used, fetch_time_ms, cost_credits}, "error": str | None }

ParametersJSON Schema
NameRequiredDescriptionDefault
urlYes
max_tokensNo
formatNomarkdown
use_cacheNo

TDQS

A4.9/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations exist, so the description fully bears the transparency burden. It discloses caching (6h), auto-routing to multiple fetchers, cost estimates, and return structure including error handling. This far exceeds minimal requirements.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with sections, bullet points, and a return format sample. While fairly long, every sentence adds value—usage guidance, parameter details, and return schema. Minor conciseness loss from repetition of 'WHEN TO USE' structure.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Despite no output schema and no annotations, the description compensates fully: explains return structure in detail, caching behavior, fetcher selection logic, cost implications, and context window management (max_tokens). An agent has everything needed to invoke correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must add context for all parameters. It explains url (implicit), max_tokens (hard cap, default unlimited, context budget advice), format (default markdown, recommended), and use_cache (default true, when to pass false). Each parameter gets meaningful guidance beyond the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with 'Fetch any URL and return clean, LLM-ready Markdown' clearly stating the verb+resource+output quality. It explicitly distinguishes from siblings 'search_and_fetch' and 'fetch_multiple' in the WHEN NOT TO USE section.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The WHEN TO USE and WHEN NOT TO USE sections provide explicit scenarios (e.g., specific URL, JS-rendered, PDF, paywall) and name alternative tools. This gives clear guidance on when to invoke this tool versus its siblings.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

search_and_fetchA

Web search + fetch top results in one call.

WHEN TO USE:

  • You have a research question, not specific URLs. E.g. "what's the latest on X", "find docs for Y library", "recent news about Z".

  • You'd otherwise have to call a search tool, parse results, then call fetch — this collapses that into one round-trip.

Args: query: Search query (2–500 chars). num_results: Top N to fetch (1–10, default 3). max_tokens_each: Per-result cap (default 2000).

Returns: {"query": str, "count": int, "results": [, ...]}

ParametersJSON Schema
NameRequiredDescriptionDefault
queryYes
num_resultsNo
max_tokens_eachNo

TDQS

A4.4/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description effectively discloses the combined search-and-fetch behavior and the return format. However, it lacks details on error handling or failure scenarios for individual result fetches.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with a header and 'WHEN TO USE' section, making it easy to parse. It is concise yet informative, though the parameter descriptions could be integrated more succinctly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description adequately covers the tool's purpose, usage, parameters, and return format. Given no output schema, the return shape is documented. Missing details on partial failures or edge cases, but overall sufficient for this combined tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Despite zero schema coverage, the description fully compensates by specifying constraints (query 2-500 chars, num_results 1-10, max_tokens_each default 2000) and explaining each parameter's role, adding substantial meaning beyond the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states 'Web search + fetch top results in one call,' which precisely defines the tool's combined action. It distinguishes itself from siblings like fetch_url and fetch_multiple by highlighting the aggregation of search and fetch into one step.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description includes a 'WHEN TO USE' section that explicitly recommends the tool for research questions rather than specific URLs. It contrasts with the alternative of using separate search and fetch tools, providing clear guidance on when to prefer this tool.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 4 tool updatesv1.0.0
    • First observedestimate_tokens
    • First observedfetch_multiple
    • First observedfetch_url
    • First observedsearch_and_fetch

TDQS

A4.6/5.0

Scored across 4 tools

Disambiguation5/5

Each tool has a clearly distinct purpose: estimate_tokens is for token estimation without body fetch, fetch_url for single URL fetch, fetch_multiple for batch fetch, search_and_fetch for combined search and fetch. No overlap in functionality.

Naming Consistency5/5

All tool names use consistent snake_case with a verb_noun pattern. The verbs are clear (estimate, fetch, fetch, search_and_fetch) and the nouns differentiate the actions (tokens, url, multiple, and_fetch).

Tool Count5/5

With 4 tools, the set is concise and well-scoped for a web fetching and searching service. Each tool addresses a core need: estimating, single fetch, batch fetch, and combined search+fetch.

Completeness4/5

The tool set covers the primary workflows of fetching URLs and searching. A possible gap is the lack of a search-only tool that returns just snippets without fetching, but given the server's focus on fetching, the current set is largely complete.

Maintenance

ActivityInactive
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • A
    license
    A
    quality
    B
    maintenance
    Fast, token-efficient web content extraction tool that converts websites to clean Markdown for AI agents, featuring smart caching, content extraction with Mozilla Readability, and polite crawling capabilities.
    1
    503 npm
    161
    MIT
  • A
    license
    A
    quality
    D
    maintenance
    Enables AI agents to fetch and render web pages (including JavaScript-heavy SPAs) with headless Chromium, extract readable content with Mozilla Readability, capture navigation links, download images, and return a clean markdown file path.
    1
    11 npm
    ISC
  • A
    license
    Not graded
    quality
    D
    maintenance
    Provides AI agents with reliable web fetching capabilities, handling retries, caching, and anti-bot bypass automatically.
    MIT