Skip to content
Firecrawl Docs
Firecrawl Docs
LLM SDKs 和框架

Agent Development Kit(ADK)

通过模型上下文协议(MCP)将 Firecrawl 集成到 Google 的 ADK 中,打造高级智能体工作流

通过模型上下文协议(MCP)将 Firecrawl 集成到 Google 的 Agent Development Kit(ADK),以构建具备网页抓取能力的强大 AI 智能体。

Firecrawl 提供一个 MCP 服务器,可与 Google 的 ADK 无缝集成,使你的智能体能够高效地对任意网站进行抓取、爬取,并提取结构化数据。该集成同时支持云端与自托管的 Firecrawl 实例,并通过可流式传输的 HTTP 实现最佳性能。

  • 高效完成任意网站的网页抓取、爬取与内容发现
  • 高级搜索与智能内容提取
  • 深度研究
  • 灵活部署 (云端或自托管)
  • 针对现代 Web 环境优化,支持 HTTP 流式传输
  • firecrawl.dev 获取 Firecrawl 的 API 密钥
  • 安装 Google SDK
from google.adk.agents.llm_agent import Agent
from google.adk.tools.mcp_tool.mcp_session_manager import StreamableHTTPServerParams
from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset

FIRECRAWL_API_KEY = "YOUR-API-KEY"

root_agent = Agent(
    model="gemini-2.5-pro",
    name="firecrawl_agent",
    description='使用 Firecrawl 抓取网站的智能助手',
    instruction='帮助用户搜索网站内容',
    tools=[
        MCPToolset(
            connection_params=StreamableHTTPServerParams(
                url="https://mcp.firecrawl.dev/v2/mcp",
                headers={"Authorization": f"Bearer {FIRECRAWL_API_KEY}"},
            ),
        )
    ],
)
工具名称描述
Scrape 工具firecrawl_scrape使用高级选项抓取单个 URL 的内容
Map 工具firecrawl_map映射网站以发现站点上所有已索引的 URL
Search 工具firecrawl_search搜索全网,并可选地从搜索结果中提取内容
Crawl 工具firecrawl_crawl使用高级选项启动异步爬取
爬取状态检查firecrawl_check_crawl_status查看爬取任务状态
Extract 工具firecrawl_extract利用 LLM 从网页提取结构化信息

FIRECRAWL_API_KEY:你的 Firecrawl API 密钥

  • 使用云端 API(默认)时为必需
  • 在配合 FIRECRAWL_API_URL 的自托管实例中为可选

Firecrawl API URL (用于自托管实例)

  • FIRECRAWL_API_URL:自定义 API 端点
  • 示例:https://firecrawl.your-domain.com
  • 如未配置,将使用云端 API
from google.adk.agents.llm_agent import Agent
from google.adk.tools.mcp_tool.mcp_session_manager import StreamableHTTPServerParams
from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset

FIRECRAWL_API_KEY = "YOUR-API-KEY"

# 创建研究代理
research_agent = Agent(
    model="gemini-2.5-pro",
    name="research_agent",
    description='An AI agent that researches topics by scraping and analyzing web content',
    instruction='''You are a research assistant. When given a topic or question:
    1. Use the search tool to find relevant websites
    2. Scrape the most relevant pages for detailed information
    3. Extract structured data when needed
    4. Provide comprehensive, well-sourced answers''',
    tools=[
        MCPToolset(
            connection_params=StreamableHTTPServerParams(
                url="https://mcp.firecrawl.dev/v2/mcp",
                headers={"Authorization": f"Bearer {FIRECRAWL_API_KEY}"},
            ),
        )
    ],
)

# 使用代理
response = research_agent.run("What are the latest features in Python 3.13?")
print(response)
  1. 为任务选择合适的工具

    • 当你需要先找到相关页面时,使用 firecrawl_search
    • 抓取单个页面时,使用 firecrawl_scrape
    • 需要发现并抓取整站时,使用 firecrawl_crawl
    • 当你已经有一份简短的已知 URL 列表时,重复调用 firecrawl_scrape
  2. 监控使用情况:使用你的 Firecrawl Dashboard 和 API 响应来跟踪额度使用情况。

  3. 妥善处理错误:向用户显示 MCP/API 错误,并且仅在你的代理工作流能够安全执行时才进行重试。

  4. 优化性能:当代理需要发现相关 URL 时,在抓取前先使用 firecrawl_map


Was this page helpful?Suggest editsRaise issue