适用于Crawl4AI(开源且适合LLM的网络爬虫)的生产就绪型Model Context Protocol (MCP) 服务器集成。该项目提供了在Claude Desktop和Claude Code中无缝访问高级网络爬取和内容提取功能的能力。
# 拉取并运行Crawl4AI
docker run -d -p 11235:11235 --name crawl4ai --shm-size=1g unclecode/crawl4ai:latest
# 添加到Claude Desktop配置
{
"mcpServers": {
"c4ai-sse": {
"command": "sse",
"args": ["http://localhost:11235/mcp/sse"]
}
}
}
就这样! 现在您可以在Claude中访问7种强大的网络爬取工具。
| 工具 | 描述 | 最佳用途 |
|---|---|---|
md | 从网页中提取干净的Markdown | 博客文章、文章、文档 |
html | 提取原始HTML内容 | 网络开发、DOM分析 |
screenshot | 捕获高分辨率截图 | 视觉验证、归档 |
pdf | 从网页生成PDF | 文档归档、离线阅读 |
execute_js | 在页面上执行JavaScript | 动态内容、自定义提取 |
crawl | 批量处理多个URL | 高容量抓取、比较 |
ask | 查询Crawl4AI内置的知识库 | 库文档、API参考 |
从对7种工具的全面测试:
# 基本安装
docker run -d \
-p 11235:11235 \
--name crawl4ai \
--shm-size=1g \
unclecode/crawl4ai:latest
version: '3.8'
services:
crawl4ai:
image: unclecode/crawl4ai:latest
container_name: crawl4ai
ports:
- "11235:11235"
shm_size: '1gb'
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:11235/"]
interval: 30s
timeout: 10s
retries: 3
apiVersion: apps/v1
kind: Deployment
metadata:
name: crawl4ai
spec:
replicas: 1
selector:
matchLabels:
app: crawl4ai
template:
metadata:
labels:
app: crawl4ai
spec:
containers:
- name: crawl4ai
image: unclecode/crawl4ai:latest
ports:
- containerPort: 11235
resources:
requests:
memory: "1Gi"
cpu: "500m"
limits:
memory: "2Gi"
cpu: "1"
curl -X POST http://localhost:11235/md \
-H "Content-Type: application/json" \
-d '{
"url": "https://en.wikipedia.org/wiki/Web_scraping",
"f": "fit"
}'
curl -X POST http://localhost:11235/screenshot \
-H "Content-Type: application/json" \
-d '{
"url": "https://github.com",
"screenshot_wait_for": 3
}'
curl -X POST http://localhost:11235/execute_js \
-H "Content-Type: application/json" \
-d '{
"url": "https://news.ycombinator.com",
"scripts": [
"Array.from(document.querySelectorAll(\".titleline a\")).slice(0, 5).map(a => ({title: a.textContent, url: a.href}))"
]
}'
curl -X POST http://localhost:11235/crawl \
-H "Content-Type: application/json" \
-d '{
"urls": [
"https://example.com",
"https://httpbin.org/html",
"https://jsonplaceholder.typicode.com"
]
}'
{
"url": "https://example.com",
"browser_config": {
"viewport_width": 1920,
"viewport_height": 1080,
"user_agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36",
"headless": true
}
}
{
"url": "https://example.com",
"f": "fit", // "raw", "fit", "bm25", "llm"
"q": null, // bm25/llm过滤查询
"c": "0" // 内容过滤级别
}
// 提取结构化数据
{
title: document.title,
headings: Array.from(document.querySelectorAll('h1,h2,h3')).map(h => h.textContent),
links: Array.from(document.querySelectorAll('a')).slice(0, 10).map(a => ({
text: a.textContent.trim(),
url: a.href
}))
}
docker service create \
--name crawl4ai \
--replicas 3 \
--publish 11235:11235 \
--mount type=volume,source=crawl4ai-cache,target=/app/cache \
unclecode/crawl4ai:latest
AWS ECS,Google Cloud Run,Azure Container Instances - 请参阅部署指南获取完整说明。
# docker-compose.monitoring.yml
services:
crawl4ai:
image: unclecode/crawl4ai:latest
environment:
- METRICS_ENABLED=true
- LOG_LEVEL=INFO
prometheus:
image: prom/prometheus
ports:
- "9090:9090"
# 基本健康检查
curl http://localhost:11235/
# 架构验证
curl http://localhost:11235/mcp/schema | jq '.tools | length'
# 性能监控
docker stats crawl4ai
docker run -d \
--memory=4g \
--memory-swap=4g \
--shm-size=2g \
--name crawl4ai \
unclecode/crawl4ai:latest
docker run -d \
--cpus="2.0" \
--cpuset-cpus="0,1" \
--name crawl4ai \
unclecode/crawl4ai:latest
{
"browser_config": {
"text_mode": true,
"light_mode": true,
"extra_args": [
"--disable-images",
"--disable-javascript",
"--disable-plugins"
]
}
}
# 运行全面测试
./test-crawl4ai.sh
# 预期结果:
# 1. 健康检查:✓ 通过
# 2. 架构检查:✓ 通过
# 3. MD工具检查:✓ 通过
# 4. 截图工具检查:✓ 通过
# 5. JavaScript工具检查:✓ 通过
# 分别测试每个工具
curl -X POST http://localhost:11235/md -H "Content-Type: application/json" -d '{"url": "https://example.com", "f": "fit"}'
curl -X POST http://localhost:11235/screenshot -H "Content-Type: application/json" -d '{"url": "https://example.com"}'
curl -X POST http://localhost:11235/execute_js -H "Content-Type: application/json" -d '{"url": "https://example.com", "scripts": ["document.title"]}'
# 日志
LOG_LEVEL=INFO # DEBUG, INFO, WARNING, ERROR
MAX_WORKERS=4 # 最大并发工作者数
TIMEOUT=30 # 默认请求超时
# 特性
CACHE_ENABLED=true # 启用缓存
SCREENSHOT_ENABLED=true # 启用截图
PDF_ENABLED=true # 启用PDF生成
# 安全
RATE_LIMIT=100 # 每分钟请求数
MAX_URL_LENGTH=2048 # 最大URL长度
{
"mcpServers": {
"c4ai-sse": {
"command": "sse",
"args": ["http://localhost:11235/mcp/sse"],
"env": {
"LOG_LEVEL": "INFO",
"TIMEOUT": "30"
}
}
}
}
def comprehensive_analysis(url):
# 步骤1:提取内容
md_result = call_tool("md", {"url": url, "f": "fit"})
# 步骤2:分析结构
js_result = call_tool("execute_js", {
"url": url,
"scripts": ["({wordCount: document.body.textContent.split(' ').length})"]
})
# 步骤3:视觉验证
screenshot_result = call_tool("screenshot", {"url": url})
return combine_results(md_result, js_result, screenshot_result)
def monitor_competitors(urls):
# 批量处理所有竞争对手
batch_result = call_tool("crawl", {"urls": urls})
# 提取定价和产品信息
for result in batch_result["results"]:
if result["success"]:
analyze_competitor_data(result)
| 问题 | 解决方案 |
|---|---|
| 端口已被占用 | 使用-p 8080:11235替代端口 |
| 容器无法启动 | 查看docker logs crawl4ai中的错误 |
| MCP连接失败 | 使用curl http://localhost:11235/mcp/sse验证端点 |
| 内存使用过高 | 添加--memory=4g --shm-size=2g限制 |
| 请求超时 | 在工具参数中增加超时 |
# 容器状态
docker ps | grep crawl4ai
docker inspect crawl4ai --format='{{.State.Health.Status}}'
# 网络连通性
curl -I http://localhost:11235/
telnet localhost 11235
# 资源使用
docker stats crawl4ai
这是一个针对开源Crawl4AI库的部署和集成项目。对于Crawl4AI核心开发:
对于MCP集成问题或部署改进,请在此仓库中打开一个issue。
此项目遵循底层Crawl4AI项目的许可证。请参阅官方Crawl4AI仓库以获取许可信息。
/docs目录中的综合指南🎉 准备开始爬取了吗? 请按照上面的快速开始指南操作,或深入阅读安装及设置指南以获取详细说明。
最后更新日期:2025年8月4日
版本:1.0.0