> ## 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.

# 在 Codex CLI 中通过 MCP 使用网页搜索与抓取

> 为 OpenAI Codex CLI 添加 Firecrawl 的网页抓取与搜索功能

通过 MCP，为 [OpenAI Codex CLI](https://github.com/openai/codex) 添加 Firecrawl 的搜索、抓取、爬取和浏览器工具。

<div id="quick-setup">
  ## 快速开始
</div>

<div id="1-get-your-api-key">
  ### 1. 获取 API 密钥
</div>

前往 [firecrawl.dev/app](https://www.firecrawl.dev/app) 注册并复制你的 API 密钥。

<div id="2-add-firecrawl-to-codex">
  ### 2. 将 Firecrawl 添加到 Codex
</div>

Codex 会从 `~/.codex/config.toml` 读取 MCP 服务器配置。添加 Firecrawl 服务器：

```toml theme={null}
[mcp_servers.firecrawl]
command = "npx"
args = ["-y", "firecrawl-mcp"]

[mcp_servers.firecrawl.env]
FIRECRAWL_API_KEY = "fc-YOUR-API-KEY"
```

将 `fc-YOUR-API-KEY` 替换为你的 Firecrawl API 密钥。

<div id="3-start-codex">
  ### 3. 启动 Codex
</div>

```bash theme={null}
codex
```

Codex 启动时会检测到 Firecrawl 工具。请确认它们已成功加载：

```bash theme={null}
/mcp
```

你应该会看到已列出的 `firecrawl`，以及 `firecrawl_search`、`firecrawl_scrape`、`firecrawl_crawl` 和 `firecrawl_extract` 等工具。

<div id="quick-demo">
  ## 快速演示
</div>

试试以下 prompt：

```
Search the web for the latest Next.js App Router release notes and summarize.
```

```
Scrape https://docs.firecrawl.dev and list the top-level sections.
```

```
Crawl https://example.com and save the markdown for every page under /blog.
```

<div id="remote-hosted-url-no-nodejs-required">
  ## 远程托管的 URL (无需 Node.js)
</div>

如果你不想在本地运行 `npx`：

```toml theme={null}
[mcp_servers.firecrawl]
url = "https://mcp.firecrawl.dev/fc-YOUR-API-KEY/v2/mcp"
```

<div id="troubleshooting">
  ## 故障排查
</div>

* **Codex 无法识别这些工具** — 运行 `codex --version`，确认你使用的是支持 MCP 的版本；编辑 `config.toml` 后，请重启 CLI。
* **`spawn npx ENOENT`** — 安装 Node.js 18+，并确保 `npx` 已加入你的 `PATH`；或者改用上方的远程托管 URL。
* **401 / 密钥无效** — 前往 [firecrawl.dev/app/api-keys](https://www.firecrawl.dev/app/api-keys) 重新生成 API 密钥。
