🚀 AnyCrawl MCP Server — 强大的网络爬取工具,通过模型上下文协议(MCP)为Cursor、Claude和其他LLM客户端提供网页抓取和爬行功能。
ANYCRAWL_API_KEY=YOUR-API-KEY npx -y anycrawl-mcp
npm install -g anycrawl-mcp-server
ANYCRAWL_API_KEY=YOUR-API-KEY anycrawl-mcp
设置所需的环境变量:
export ANYCRAWL_API_KEY="your-api-key-here"
可选设置自定义基础URL:
export ANYCRAWL_BASE_URL="https://api.anycrawl.dev" # 默认值
ANYCRAWL_API_KEY(见上文)。AnyCrawl MCP Server支持以下部署模式:
默认模式是STDIO(无需环境)。设置ANYCRAWL_MODE以切换。
| 模式 | 描述 | 最佳用途 | 传输方式 |
|---|---|---|---|
STDIO | 标准MCP通过标准I/O(默认) | 命令类型MCP客户端,本地工具 | 标准I/O |
MCP | 可流式HTTP(JSON,有状态) | Cursor(可流式HTTP),API集成 | HTTP + JSON |
SSE | 服务器发送事件 | 网络应用,浏览器集成 | HTTP + SSE |
# 开发(本地)
npm run dev # STDIO(默认)
npm run dev:mcp # MCP模式(JSON /mcp)
npm run dev:sse # SSE模式(/sse)
# 生产(构建输出)
npm start # STDIO(默认)
npm run start:mcp
npm run start:sse
# 环境变量示例
ANYCRAWL_MODE=MCP ANYCRAWL_API_KEY=YOUR-KEY npm run dev:mcp
ANYCRAWL_MODE=SSE ANYCRAWL_API_KEY=_KEY npm run dev:sse
此仓库包含一个生产就绪镜像,在同一容器中运行端口3000上的MCP(JSON)和端口3001上的SSE,前面由Nginx代理。Nginx还支持带有API密钥前缀的路径/{API_KEY}/mcp和/{API_KEY}/sse,并通过x-anycrawl-api-key头转发密钥。
docker compose build
docker compose up -d
Docker镜像使用的环境变量:
ANYCRAWL_MODE: MCP_AND_SSE(默认在compose中),或MCP,SSEANYCRAWL_MCP_PORT: 默认3000ANYCRAWL_SSE_PORT: 默认3001CLOUD_SERVICE: true以从/{API_KEY}/...或头中提取API密钥ANYCRAWL_BASE_URL: 默认https://api.anycrawl.dev配置Cursor。注意:需要Cursor v0.45.6+。
对于Cursor v0.48.6及更高版本,在您的MCP服务器设置中添加以下内容:
{
"mcpServers": {
"anycrawl-mcp": {
"command": "npx",
"args": ["-y", "anycrawl-mcp"],
"env": {
"ANYCRAWL_API_KEY": "YOUR-API-KEY"
}
}
}
}
对于Cursor v0.45.6:
env ANYCRAWL_API_KEY=YOUR-API-KEY npx -y anycrawl-mcp
在Windows上,如果遇到问题:
cmd /c "set ANYCRAWL_API_KEY=YOUR-API-KEY && npx -y anycrawl-mcp"
对于手动安装,在VS Code的用户设置(JSON)中添加以下JSON(命令面板 → 首选项:打开用户设置(JSON)):
{
"mcp": {
"inputs": [
{
"type": "promptString",
"id": "apiKey",
"description": "AnyCrawl API密钥",
"password": true
}
],
"servers": {
"anycrawl": {
"command": "npx",
"args": ["-y", "anycrawl-mcp"],
"env": {
"ANYCRAWL_API_KEY": "${input:apiKey}"
}
}
}
}
}
可选地,在工作区的.vscode/mcp.json中放置以下内容以共享配置:
{
"inputs": [
{
"type": "promptString",
"id": "apiKey",
"description": "AnyCrawl API密钥",
"password": true
}
],
"servers": {
"anycrawl": {
"command": "npx",
"args": ["-y", "anycrawl-mcp"],
"env": {
"ANYCRAWL_API_KEY": "${input:apiKey}"
}
}
}
}
在./codeium/windsurf/model_config.json中添加以下内容:
{
"mcpServers": {
"mcp-server-anycrawl": {
"command": "npx",
"args": ["-y", "anycrawl-mcp"],
"env": {
"ANYCRAWL_API_KEY": "YOUR_API_KEY"
}
}
}
}
SSE(服务器发送事件)模式提供了基于web的接口用于MCP通信,适用于web应用程序、测试以及与基于web的LLM客户端的集成。
# 开发模式
ANYCRAWL_API_KEY=YOUR-API-KEY npx -y anycrawl-mcp
# 或使用npm脚本
ANYCRAWL_API_KEY=YOUR-API-KEY npm run dev:sse
可选的服务器设置(显示默认值):
export ANYCRAWL_PORT=3000
export ANYCRAWL_HOST=0.0.0.0
curl -s http://localhost:${ANYCRAWL_PORT:-3000}/health
# 响应:ok
对于其他支持SSE传输的MCP/SSE客户端,使用以下配置:
{
"mcpServers": {
"anycrawl": {
"type": "sse",
"url": "https://mcp.anycrawl.dev/{API_KEY}/sse",
"name": "AnyCrawl MCP服务器",
"description": "网页抓取和爬行工具"
}
}
}
或
{
"mcpServers": {
"AnyCrawl": {
"type": "streamable_http",
"url": "https://mcp.anycrawl.dev/{API_KEY}/mcp"
}
}
}
环境设置:
# 使用API密钥启动SSE服务器
ANYCRAWL_API_KEY=your-api-key-here npm run dev:sse
配置Cursor连接到您的HTTP MCP服务器。
本地HTTP可流式服务器:
{
"mcpServers": {
"anycrawl-http-local": {
"type": "streamable_http",
"url": "http://127.0.0.1:3000/mcp"
}
}
}
云端HTTP可流式服务器:
{
"mcpServers": {
"anycrawl-http-cloud": {
"type": "streamable_http",
"url": "https://mcp.anycrawl.dev/{API_KEY}/mcp"
}
}
}
注意:对于HTTP模式,需在服务器进程环境中设置ANYCRAWL_API_KEY(以及可选的主机/端口)或在URL中设置。使用streamable_http时,Cursor不需要您的API密钥。
anycrawl_scrape)抓取单个URL并以各种格式提取内容。
最佳用途:
参数:
url(必需):要抓取的URLengine(必需):抓取引擎(playwright,cheerio,puppeteer)formats(可选):输出格式(markdown,html,text,screenshot,screenshot@fullPage,rawHtml,json)proxy(可选):代理URLtimeout(可选):超时时间(毫秒,默认:300000)retry(可选):是否在失败时重试(默认:false)wait_for(可选):等待页面加载的时间include_tags(可选):要包含的HTML标签exclude_tags(可选):要排除的HTML标签json_options(可选):JSON提取选项示例:
{
"name": "anycrawl_scrape",
"arguments": {
"url": "https://example.com",
"engine": "cheerio",
"formats": ["markdown", "html"],
"timeout": 30000
}
}
anycrawl_crawl)启动爬行任务以从网站抓取多页。默认情况下,这会等待完成并使用SDK的client.crawl返回聚合结果(默认:每3秒轮询一次,超时60秒)。
最佳用途:
参数:
url(必需):要爬行的基础URLengine(必需):抓取引擎max_depth(可选):最大爬行深度(默认:10)limit(可选):最大页面数(默认:100)strategy(可选):爬行策略(all,same-domain,same-hostname,same-origin)exclude_paths(可选):要排除的URL模式include_paths(可选):要包含的URL模式scrape_options(可选):单个页面抓取选项poll_seconds(可选):等待轮询间隔秒数(默认:3)timeout_ms(可选):整体等待超时毫秒数(默认:60000)示例:
{
"name": "anycrawl_crawl",
"arguments": {
"url": "https://example.com/blog",
"engine": "playwright",
"max_depth": 2,
"limit": 50,
"strategy": "same-domain",
"poll_seconds": 3,
"timeout_ms": 60000
}
}
返回:{ "job_id": "...", "status": "completed", "total": N, "completed": N, "creditsUsed": N, "data": [...] }。
anycrawl_crawl_status)检查爬行任务的状态。
参数:
job_id(必需):爬行任务ID示例:
{
"name": "anycrawl_crawl_status",
"arguments": {
"job_id": "7a2e165d-8f81-4be6-9ef7-23222330a396"
}
}
anycrawl_crawl_results)获取爬行任务的结果。
参数:
job_id(必需):爬行任务IDskip(可选):跳过的结果数量(用于分页)示例:
{
"name": "anycrawl_crawl_results",
"arguments": {
"job_id": "7a2e165d--8f81-4be6-9ef7-23222330a396",
"skip": 0
}
}
anycrawl_cancel_crawl)取消待处理的爬行任务。
参数:
job_id(必需):要取消的爬行任务ID示例:
{
"name": "anycrawl_cancel_crawl",
"arguments": {
"job_id": "7a2e165d-8f81-4be6-9ef7-23222330a396"
}
}
anycrawl_search)使用AnyCrawl搜索引擎搜索网络。
最佳用途:
参数:
query(必需):搜索查询engine(可选):搜索引擎(google)limit(可选):最大结果数(默认:10)offset(可选):跳过的结果数(默认:0)pages(可选):要搜索的页面数lang(可选):语言代码country(可选):国家代码scrape_options(必需):抓取搜索结果的选项safeSearch(可选):安全搜索级别(0=关闭,1=适度,2=严格)示例:
{
"name": "anycrawl_search",
"arguments": {
"query": "最新的人工智能研究论文2024",
"engine": "google",
"limit": 5,
"scrape_options": {
"engine": "cheerio",
"formats": ["markdown"]
}
}
}
干净、结构化的Markdown内容,非常适合LLM消费。
保留所有格式的原始HTML内容。
最小格式化的纯文本内容。
页面的视觉截图。
包括折页下方内容的全页截图。
未处理的HTML内容。
使用自定义模式进行结构化数据提取。
服务器提供全面的错误处理:
服务器包含详细的日志记录:
使用环境变量设置日志级别:
export LOG_LEVEL=debug # debug, info, warn, error
git clone <repository>
cd anycrawl-mcp
npm ci
npm run build
npm test
npm run lint
npm run format
npm test