智能WebFetch MCP服务器
](https://pypi.org/project/smart-webfetch-mcp/) ](https://pypi.org/project/smart-webfetch-mcp/) ](https://pypi.org/project/smart-webfetch-mcp/) 
LLM的上下文感知web获取。通过在获取和提供手术提取工具之前检查页面大小来防止上下文窗口泛滥。
问题
标准的web获取工具会将整个页面转储到上下文窗口中,通常是:
- 超过令牌限制
- 在导航、页脚、广告上浪费上下文
- 用不相关的内容淹没模型
解决方案
Smart WebFetch提供了7个用于智能web获取的工具:
| 工具 | 目的 |
|---|---|
web_preflight | 提取前检查页面大小 |
web_smart_fetch | 使用自动截断进行提取 |
web_fetch_code | 仅提取代码块 |
web_fetch_section | 获取特定标题/章节 |
web_fetch_chunked | 分页获取大型文档 |
web_fetch_links | 从页面中提取所有链接 |
web_fetch_tables | 提取表格作为标记 |
安装
# Install from PyPI
pip install smart-webfetch-mcp
# Or with uvx (recommended for MCP)
uvx smart-webfetch-mcp配置
克劳德代码
claude mcp add --transport stdio smart-webfetch -- uvx smart-webfetch-mcpOpenCode
添加到您的 opencode.json:
{
"mcp": {
"smart-webfetch": {
"type": "local",
"command": ["uvx", "smart-webfetch-mcp"],
"enabled": true
}
}
}克劳德桌面版
添加到 claude_desktop_config.json:
{
"mcpServers": {
"smart-webfetch": {
"command": "uvx",
"args": ["smart-webfetch-mcp"]
}
}
}使用示例
取货前检查
Use web_preflight to check https://docs.python.org/3/library/asyncio.html答复:
{
"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."
}使用自动截断进行提取
Use web_smart_fetch on https://example.com/docs with max_tokens=4000仅提取代码示例
Use web_fetch_code on https://docs.python.org/3/library/asyncio-task.html获取特定部分
Use web_fetch_section on https://docs.python.org/3/library/asyncio.html
with heading="Running an asyncio Program"分页阅读
Use web_fetch_chunked on https://large-docs.com/api with chunk=0, chunk_size=4000然后继续 chunk=1, chunk=2等等。
工具参考
web_飞行
在获取之前检查页面元数据。
参数:
url(必填):要检查的URL
退货:
estimated_tokens:近似令牌计数content_type:MIME类型is_html:内容是否为HTMLtitle:页面标题(如果是HTML)safe_for_context:布尔值(如果\<8000个标记,则为true)recommendation:人类可读的建议
web_smart_fetch
使用自动截断功能获取大页面。
参数:
url(必填):要获取的URLmax_tokens(可选,默认8000):返回的最大令牌数strategy(可选,默认“自动”):“自动”查找自然断点,“截断”硬剪切
退货: 带元数据标题的Markdown内容
web_fetch_code
仅从页面中提取代码块。
参数:
url(必填):从中提取代码的URL
退货: 带有语言注释和上下文的代码块
web_fetch_section
获取特定标题下的内容。
参数:
url(必填):要从中获取的URLheading(必填):要查找的标题文本(不区分大小写)
退货: 未找到章节内容或可用章节列表
web_fetch_chunked
将大型文档分块提取。
参数:
url(必填):要获取的URLchunk(可选,默认为0):块索引(从0开始)chunk_size(可选,默认4000):每个区块的令牌数
退货: 使用导航元数据对内容进行分块
web_fetch_links
从页面中提取所有链接。
参数:
url(必填):从中提取链接的URLfilter_pattern(可选):用于过滤链接URL的正则表达式external_only(可选,默认为false):仅返回外部链接
退货: 带有文本和URL的Markdown链接列表
web_fetch_tables
从页面中提取表格作为markdown。
参数:
url(必需):从中提取表的URLtable_index(可选):特定表索引(从0开始),如果未指定,则返回全部
退货: Markdown格式的表格
发展
# 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 .许可证
麻省理工学院
