> ## Documentation Index
> Fetch the complete documentation index at: https://docs.firecrawl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Agent Development Kit（ADK）

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

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

<div id="overview">
  ## 概览
</div>

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

<div id="features">
  ## 功能
</div>

* 高效完成任意网站的网页抓取、爬取与内容发现
* 高级搜索与智能内容提取
* 深度研究
* 灵活部署 (云端或自托管)
* 针对现代 Web 环境优化，支持 HTTP 流式传输

<div id="prerequisites">
  ## 前置条件
</div>

* 从 [firecrawl.dev](https://firecrawl.dev) 获取 Firecrawl 的 API 密钥
* 安装 Google SDK

<div id="setup">
  ## 设置
</div>

<CodeGroup>
  ```python 远程 MCP 服务器 theme={null}
  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=f"https://mcp.firecrawl.dev/{FIRECRAWL_API_KEY}/v2/mcp",
              ),
          )
      ],
  )
  ```

  ```python 本地 MCP 服务器 theme={null}
  from google.adk.agents.llm_agent import Agent
  from google.adk.tools.mcp_tool.mcp_session_manager import StdioConnectionParams
  from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset
  from mcp import StdioServerParameters

  root_agent = Agent(
      model='gemini-2.5-pro',
      name='firecrawl_agent',
      description='使用 Firecrawl 抓取网站的智能助手',
      instruction='帮助用户搜索网站内容',
      tools=[
          MCPToolset(
              connection_params=StdioConnectionParams(
                  server_params = StdioServerParameters(
                      command='npx',
                      args=[
                          "-y",
                          "firecrawl-mcp",
                      ],
                      env={
                          "FIRECRAWL_API_KEY": "YOUR-API-KEY",
                      }
                  ),
                  timeout=30,
              ),
          )
      ],
  )
  ```
</CodeGroup>

<div id="available-tools">
  ## 可用工具
</div>

| 工具         | 名称                             | 描述                   |
| ---------- | ------------------------------ | -------------------- |
| Scrape 工具  | `firecrawl_scrape`             | 使用高级选项抓取单个 URL 的内容   |
| Map 工具     | `firecrawl_map`                | 映射网站以发现站点上所有已索引的 URL |
| Search 工具  | `firecrawl_search`             | 搜索全网，并可选地从搜索结果中提取内容  |
| Crawl 工具   | `firecrawl_crawl`              | 使用高级选项启动异步爬取         |
| 爬取状态检查     | `firecrawl_check_crawl_status` | 查看爬取任务状态             |
| Extract 工具 | `firecrawl_extract`            | 利用 LLM 从网页提取结构化信息    |

<div id="configuration">
  ## 配置
</div>

<div id="required-configuration">
  ### 必需配置
</div>

**FIRECRAWL\_API\_KEY**：你的 Firecrawl API 密钥

* 使用云端 API（默认）时为必需
* 在配合 FIRECRAWL\_API\_URL 的自托管实例中为可选

<div id="optional-configuration">
  ### 可选配置
</div>

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

* `FIRECRAWL_API_URL`：自定义 API 端点
* 示例：`https://firecrawl.your-domain.com`
* 如未配置，将使用云端 API

<div id="example-web-research-agent">
  ## 示例：网页研究代理
</div>

```python theme={null}
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='通过抓取和分析网页内容来研究主题的 AI 智能体',
    instruction='''你是一个研究助手。当收到主题或问题时:
    1. 使用搜索工具查找相关网站
    2. 抓取最相关的页面获取详细信息
    3. 必要时提取结构化数据
    4. 提供全面、来源可靠的答案''',
    tools=[
        MCPToolset(
            connection_params=StreamableHTTPServerParams(
                url=f"https://mcp.firecrawl.dev/{FIRECRAWL_API_KEY}/v2/mcp",
            ),
        )
    ],
)

# 使用智能体
response = research_agent.run("Python 3.13 有哪些最新特性?")
print(response)
```

<div id="best-practices">
  ## 最佳实践
</div>

1. **为任务选择合适的工具**：
   * 当你需要先找到相关页面时，使用 `firecrawl_search`
   * 抓取单个页面时，使用 `firecrawl_scrape`
   * 需要发现并抓取整站时，使用 `firecrawl_crawl`
   * 当你已经有一份简短的已知 URL 列表时，重复调用 `firecrawl_scrape`

2. **监控使用情况**：使用你的 Firecrawl Dashboard 和 API 响应来跟踪额度使用情况。

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

4. **优化性能**：当代理需要发现相关 URL 时，在抓取前先使用 `firecrawl_map`。

***

<div id="related-resources">
  ## 相关资源
</div>

<CardGroup cols={2}>
  <Card title="使用 Google Agent Development Kit（ADK）与 Firecrawl 构建 AI 代理的完整指南" href="https://www.firecrawl.dev/blog/google-adk-multi-agent-tutorial">
    了解如何基于 Google 的 ADK 框架，结合 Firecrawl 的网页抓取能力，构建强大的多代理 AI 系统。
  </Card>

  <Card title="MCP 服务器文档" href="https://docs.firecrawl.dev/mcp-server">
    进一步了解 Firecrawl 的模型上下文协议（MCP）服务器的集成方式与功能。
  </Card>

  <Card title="Google ADK 官方文档" href="https://google.github.io/adk-docs/">
    查阅 Google Agent Development Kit 官方文档，获取完整指南与 API 参考。
  </Card>
</CardGroup>
