网页爬取服务

Firecrawl MCP Server是一个集成了Firecrawl的模型上下文协议服务器,提供网页爬取、搜索、内容提取和深度研究等功能,适用于数据采集和分析场景。

  • by Yu-Xiao-Sheng
  • 本地部署
  • 更新于
在 GitHub 查看 yu-xiao-sheng/firecrawl-mcp-server

使用说明

Firecrawl MCP服务器

一种模型上下文协议(MCP)服务器实现,与 火爬 用于网络抓取功能。

非常感谢 @弗克内塔, @cawstudios 为了初步实施!

特性

  • 抓取、爬行、搜索、提取、深入研究和批量抓取支持
  • 使用JS渲染进行Web抓取
  • URL发现和爬网
  • 具有内容提取功能的网络搜索
  • 具有指数回退的自动重试
    • 内置速率限制的高效批处理
  • 云API信用使用监控
  • 综合测井系统
  • 支持云和自托管FireCrawl实例
  • 移动/桌面视口支持
  • 具有标签包含/排除功能的智能内容过滤

安装

使用npx运行

env FIRECRAWL_API_KEY=fc-YOUR_API_KEY npx -y firecrawl-mcp

手动安装

npm install -g firecrawl-mcp

在游标上运行

配置光标🖥️ 注意:需要游标版本0.45.6+

要在游标中配置FireCrawl MCP,请执行以下操作:

  1. 打开光标设置
  2. 转到功能>MCP服务器
  3. 点击“+添加新MCP服务器”
  4. 输入以下内容:
    • 名称:“firecrawl mcp”(或您喜欢的名字)
    • 类型:“命令”
    • 命令: env FIRECRAWL_API_KEY=your-api-key npx -y firecrawl-mcp

如果您正在使用Windows并遇到问题,请尝试 cmd /c "set FIRECRAWL_API_KEY=your-api-key && npx -y firecrawl-mcp"

替换 your-api-key 使用您的FireCrawl API密钥。

添加后,刷新MCP服务器列表以查看新工具。Composer代理将在适当的时候自动使用FireCrawl MCP,但您可以通过描述您的网络抓取需求来明确请求它。通过Command+L(Mac)访问Composer,选择提交按钮旁边的“Agent”,然后输入您的查询。

在风帆上跑步

将此添加到您的 ./codeium/windsurf/model_config.json:

{
  "mcpServers": {
    "mcp-server-firecrawl": {
      "command": "npx",
      "args": ["-y", "firecrawl-mcp"],
      "env": {
        "FIRECRAWL_API_KEY": "YOUR_API_KEY_HERE"
      }
    }
  }
}

通过Smithery安装(传统)

通过以下方式自动安装克劳德桌面版的FireCrawl 铁匠铺:

npx -y @smithery/cli install @mendableai/mcp-server-firecrawl --client claude

配置

环境变量

云API必需

  • FIRECRAWL_API_KEY:您的FireCrawl API密钥
    • 使用云API时需要(默认)
    • 在使用自托管实例时可选 FIRECRAWL_API_URL
  • FIRECRAWL_API_URL (可选):自托管实例的自定义API端点
    • 例子: https://firecrawl.your-domain.com
    • 如果未提供,将使用云API(需要API密钥)

可选配置

重试配置
  • FIRECRAWL_RETRY_MAX_ATTEMPTS:最大重试次数(默认值:3)
  • FIRECRAWL_RETRY_INITIAL_DELAY:首次重试前的初始延迟(毫秒)(默认值:1000)
  • FIRECRAWL_RETRY_MAX_DELAY:重试之间的最大延迟(毫秒)(默认值:10000)
  • FIRECRAWL_RETRY_BACKOFF_FACTOR:指数退避倍数(默认值:2)
信贷使用监控
  • FIRECRAWL_CREDIT_WARNING_THRESHOLD:信用使用警告阈值(默认值:1000)
  • FIRECRAWL_CREDIT_CRITICAL_THRESHOLD:信用使用临界阈值(默认值:100)

配置示例

对于带有自定义重试和信用监控的云API使用:

# Required for cloud API
export FIRECRAWL_API_KEY=your-api-key

# Optional retry configuration
export FIRECRAWL_RETRY_MAX_ATTEMPTS=5        # Increase max retry attempts
export FIRECRAWL_RETRY_INITIAL_DELAY=2000    # Start with 2s delay
export FIRECRAWL_RETRY_MAX_DELAY=30000       # Maximum 30s delay
export FIRECRAWL_RETRY_BACKOFF_FACTOR=3      # More aggressive backoff

# Optional credit monitoring
export FIRECRAWL_CREDIT_WARNING_THRESHOLD=2000    # Warning at 2000 credits
export FIRECRAWL_CREDIT_CRITICAL_THRESHOLD=500    # Critical at 500 credits

对于自托管实例:

# Required for self-hosted
export FIRECRAWL_API_URL=https://firecrawl.your-domain.com

# Optional authentication for self-hosted
export FIRECRAWL_API_KEY=your-api-key  # If your instance requires auth

# Custom retry configuration
export FIRECRAWL_RETRY_MAX_ATTEMPTS=10
export FIRECRAWL_RETRY_INITIAL_DELAY=500     # Start with faster retries

使用Claude Desktop

将此添加到您的 claude_desktop_config.json:

{
  "mcpServers": {
    "mcp-server-firecrawl": {
      "command": "npx",
      "args": ["-y", "firecrawl-mcp"],
      "env": {
        "FIRECRAWL_API_KEY": "YOUR_API_KEY_HERE",

        "FIRECRAWL_RETRY_MAX_ATTEMPTS": "5",
        "FIRECRAWL_RETRY_INITIAL_DELAY": "2000",
        "FIRECRAWL_RETRY_MAX_DELAY": "30000",
        "FIRECRAWL_RETRY_BACKOFF_FACTOR": "3",

        "FIRECRAWL_CREDIT_WARNING_THRESHOLD": "2000",
        "FIRECRAWL_CREDIT_CRITICAL_THRESHOLD": "500"
      }
    }
  }
}

系统配置

服务器包括几个可配置的参数,可以通过环境变量进行设置。以下是未配置的默认值:

const CONFIG = {
  retry: {
    maxAttempts: 3, // Number of retry attempts for rate-limited requests
    initialDelay: 1000, // Initial delay before first retry (in milliseconds)
    maxDelay: 10000, // Maximum delay between retries (in milliseconds)
    backoffFactor: 2, // Multiplier for exponential backoff
  },
  credit: {
    warningThreshold: 1000, // Warn when credit usage reaches this level
    criticalThreshold: 100, // Critical alert when credit usage reaches this level
  },
};

这些配置控制:

  1. 重试行为

    • 由于速率限制,自动重试失败的请求
    • 使用指数退避来避免压倒API
    • 示例:在默认设置下,将尝试在以下位置重试:
      • 第一次重试:1秒延迟
      • 第二次重试:延迟2秒
      • 第三次重试:延迟4秒(上限为maxDelay)
  2. 信贷使用监控

    • 跟踪云API使用的API信用消费
    • 在指定阈值时提供警告
    • 有助于防止意外的服务中断
    • 示例:使用默认设置:
      • 剩余1000学分时发出警告
      • 剩余100学分时出现严重警报

速率限制和批处理

服务器利用FireCrawl的内置速率限制和批处理功能:

  • 具有指数回退的自动速率限制处理
  • 批量操作的高效并行处理
  • 智能请求排队和限制
  • 暂时性错误的自动重试

可用工具

1.报废工具(firecrawl_scrape)

使用高级选项从单个URL中抓取内容。

{
  "name": "firecrawl_scrape",
  "arguments": {
    "url": "https://example.com",
    "formats": ["markdown"],
    "onlyMainContent": true,
    "waitFor": 1000,
    "timeout": 30000,
    "mobile": false,
    "includeTags": ["article", "main"],
    "excludeTags": ["nav", "footer"],
    "skipTlsVerification": false
  }
}

2.批量报废工具(firecrawl_batch_scrape)

通过内置的速率限制和并行处理,高效地抓取多个URL。

{
  "name": "firecrawl_batch_scrape",
  "arguments": {
    "urls": ["https://example1.com", "https://example2.com"],
    "options": {
      "formats": ["markdown"],
      "onlyMainContent": true
    }
  }
}

响应包括用于状态检查的操作ID:

{
  "content": [
    {
      "type": "text",
      "text": "Batch operation queued with ID: batch_1. Use firecrawl_check_batch_status to check progress."
    }
  ],
  "isError": false
}

3.检查批次状态(firecrawl_check_batch_status)

检查批处理操作的状态。

{
  "name": "firecrawl_check_batch_status",
  "arguments": {
    "id": "batch_1"
  }
}

4.搜索工具(firecrawl_search)

搜索网络,并可选择从搜索结果中提取内容。

{
  "name": "firecrawl_search",
  "arguments": {
    "query": "your search query",
    "limit": 5,
    "lang": "en",
    "country": "us",
    "scrapeOptions": {
      "formats": ["markdown"],
      "onlyMainContent": true
    }
  }
}

5.爬行工具(firecrawl_crawl)

使用高级选项启动异步爬网。

{
  "name": "firecrawl_crawl",
  "arguments": {
    "url": "https://example.com",
    "maxDepth": 2,
    "limit": 100,
    "allowExternalLinks": false,
    "deduplicateSimilarURLs": true
  }
}

6.提取工具(firecrawl_extract)

使用LLM功能从网页中提取结构化信息。支持云AI和自托管LLM提取。

{
  "name": "firecrawl_extract",
  "arguments": {
    "urls": ["https://example.com/page1", "https://example.com/page2"],
    "prompt": "Extract product information including name, price, and description",
    "systemPrompt": "You are a helpful assistant that extracts product information",
    "schema": {
      "type": "object",
      "properties": {
        "name": { "type": "string" },
        "price": { "type": "number" },
        "description": { "type": "string" }
      },
      "required": ["name", "price"]
    },
    "allowExternalLinks": false,
    "enableWebSearch": false,
    "includeSubdomains": false
  }
}

示例响应:

{
  "content": [
    {
      "type": "text",
      "text": {
        "name": "Example Product",
        "price": 99.99,
        "description": "This is an example product description"
      }
    }
  ],
  "isError": false
}

提取工具选项:

  • urls:从中提取信息的URL数组
  • prompt:LLM提取的自定义提示
  • systemPrompt:引导LLM的系统提示
  • schema:用于结构化数据提取的JSON模式
  • allowExternalLinks:允许从外部链接中提取
  • enableWebSearch:启用网络搜索以获取其他上下文
  • includeSubdomains:在提取中包含子域

使用自托管实例时,提取将使用您配置的LLM。对于云API,它使用FireCrawl的托管LLM服务。

7.深度研究工具(firecrawl_depth_Research)

使用智能爬行、搜索和LLM分析对查询进行深层网络研究。

{
  "name": "firecrawl_deep_research",
  "arguments": {
    "query": "how does carbon capture technology work?",
    "maxDepth": 3,
    "timeLimit": 120,
    "maxUrls": 50
  }
}

论据:

  • query(string,必填):要探索的研究问题或主题。
  • maxDepth(数字,可选):爬行/搜索的最大递归深度(默认值:3)。
  • timeLimit(数字,可选):研究会话的时间限制(秒)(默认值:120)。
  • maxUrls(number,可选):要分析的最大URL数(默认值:50)。

退货:

  • LLM基于研究生成的最终分析。(数据.最终分析)
  • 可能还包括研究过程中使用的结构化活动和来源。

8.生成LLMs.txt工具(firecrawl_Generate_lilmtxt)

为给定域生成标准化的llms.txt(以及可选的llms full.txt)文件。此文件定义了大型语言模型应如何与站点交互。

{
  "name": "firecrawl_generate_llmstxt",
  "arguments": {
    "url": "https://example.com",
    "maxUrls": 20,
    "showFullText": true
  }
}

论据:

  • url(string,必填):要分析的网站的基本url。
  • maxUrls(number,可选):要包含的最大URL数(默认值:10)。
  • showFullText(布尔值,可选):是否在响应中包含llms-full.txt内容。

退货:

  • 生成llms.txt文件内容和可选的llms-full.txt(data.llmstxt和/或data.llmsfulltxt)

记录系统

服务器包括全面的日志记录:

  • 运行状态和进度
  • 性能指标
  • 信贷使用监控
  • 速率限制跟踪
  • 错误条件

日志消息示例:

[INFO] FireCrawl MCP Server initialized successfully
[INFO] Starting scrape for URL: https://example.com
[INFO] Batch operation queued with ID: batch_1
[WARNING] Credit usage has reached warning threshold
[ERROR] Rate limit exceeded, retrying in 2s...

错误处理

服务器提供强大的错误处理:

  • 暂时性错误的自动重试
  • 带回退的速率限制处理
  • 详细的错误消息
  • 信用额度使用警告
  • 网络弹性

错误响应示例:

{
  "content": [
    {
      "type": "text",
      "text": "Error: Rate limit exceeded. Retrying in 2 seconds..."
    }
  ],
  "isError": true
}

发展

# Install dependencies
npm install

# Build
npm run build

# Run tests
npm test

贡献

  1. 复刻仓库
  2. 创建功能分支
  3. 运行测试: npm test
  4. 提交拉取请求

许可证

MIT许可证-有关详细信息,请参阅许可证文件