smart-webfetch-mcp

smart-webfetch-mcp

Context-aware web fetching for LLMs, providing 7 tools to check page size, fetch with truncation, extract code/sections/links/tables, and paginate large documents.

Category
访问服务器

README

Smart WebFetch MCP Server

PyPI version PyPI downloads Python version License: MIT

Context-aware web fetching for LLMs. Prevents context window flooding by checking page size before fetching and providing surgical extraction tools.

The Problem

Standard web fetch tools dump entire pages into the context window, often:

  • Exceeding token limits
  • Wasting context on navigation, footers, ads
  • Flooding the model with irrelevant content

The Solution

Smart WebFetch provides 7 tools for intelligent web fetching:

Tool Purpose
web_preflight Check page size before fetching
web_smart_fetch Fetch with automatic truncation
web_fetch_code Extract only code blocks
web_fetch_section Fetch specific heading/section
web_fetch_chunked Paginated fetching for large docs
web_fetch_links Extract all links from a page
web_fetch_tables Extract tables as markdown

Installation

# Install from PyPI
pip install smart-webfetch-mcp

# Or with uvx (recommended for MCP)
uvx smart-webfetch-mcp

Configuration

Claude Code

claude mcp add --transport stdio smart-webfetch -- uvx smart-webfetch-mcp

OpenCode

Add to your opencode.json:

{
  "mcp": {
    "smart-webfetch": {
      "type": "local",
      "command": ["uvx", "smart-webfetch-mcp"],
      "enabled": true
    }
  }
}

Claude Desktop

Add to claude_desktop_config.json:

{
  "mcpServers": {
    "smart-webfetch": {
      "command": "uvx",
      "args": ["smart-webfetch-mcp"]
    }
  }
}

Usage Examples

Check before fetching

Use web_preflight to check https://docs.python.org/3/library/asyncio.html

Response:

{
  "url": "https://docs.python.org/3/library/asyncio.html",
  "estimated_tokens": 45000,
  "safe_for_context": false,
  "recommendation": "Very large page (~45,000 tokens). Use web_fetch_section or web_fetch_chunked."
}

Fetch with automatic truncation

Use web_smart_fetch on https://example.com/docs with max_tokens=4000

Extract only code examples

Use web_fetch_code on https://docs.python.org/3/library/asyncio-task.html

Get specific section

Use web_fetch_section on https://docs.python.org/3/library/asyncio.html 
with heading="Running an asyncio Program"

Paginated reading

Use web_fetch_chunked on https://large-docs.com/api with chunk=0, chunk_size=4000

Then continue with chunk=1, chunk=2, etc.

Tool Reference

web_preflight

Check page metadata before fetching.

Parameters:

  • url (required): URL to check

Returns:

  • estimated_tokens: Approximate token count
  • content_type: MIME type
  • is_html: Whether content is HTML
  • title: Page title (if HTML)
  • safe_for_context: Boolean (true if < 8000 tokens)
  • recommendation: Human-readable advice

web_smart_fetch

Fetch with automatic truncation for large pages.

Parameters:

  • url (required): URL to fetch
  • max_tokens (optional, default 8000): Maximum tokens to return
  • strategy (optional, default "auto"): "auto" finds natural break points, "truncate" hard cuts

Returns: Markdown content with metadata header

web_fetch_code

Extract only code blocks from a page.

Parameters:

  • url (required): URL to extract code from

Returns: Code blocks with language annotations and context

web_fetch_section

Fetch content under a specific heading.

Parameters:

  • url (required): URL to fetch from
  • heading (required): Heading text to find (case-insensitive)

Returns: Section content or list of available sections if not found

web_fetch_chunked

Fetch large documents in chunks.

Parameters:

  • url (required): URL to fetch
  • chunk (optional, default 0): Chunk index (0-based)
  • chunk_size (optional, default 4000): Tokens per chunk

Returns: Chunk content with navigation metadata

web_fetch_links

Extract all links from a page.

Parameters:

  • url (required): URL to extract links from
  • filter_pattern (optional): Regex to filter link URLs
  • external_only (optional, default false): Only return external links

Returns: Markdown list of links with text and URL

web_fetch_tables

Extract tables from a page as markdown.

Parameters:

  • url (required): URL to extract tables from
  • table_index (optional): Specific table index (0-based), returns all if not specified

Returns: Markdown formatted tables

Development

# Clone and install dev dependencies
git clone https://github.com/mathisto/smart-webfetch-mcp
cd smart-webfetch-mcp
pip install -e ".[dev]"

# Run tests
pytest

# Format code
ruff format .
ruff check --fix .

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选