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

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

> 为 OpenCode 添加 Firecrawl 的网页抓取与搜索功能

通过 MCP 为 [OpenCode](https://opencode.ai) 添加 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-opencode">
  ### 2. 将 Firecrawl 添加到 OpenCode
</div>

OpenCode 会从 `~/.config/opencode/config.json` (全局) 或项目中的 `./opencode.json` 读取配置。添加：

```json theme={null}
{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "firecrawl": {
      "type": "local",
      "command": ["npx", "-y", "firecrawl-mcp"],
      "environment": {
        "FIRECRAWL_API_KEY": "fc-YOUR-API-KEY"
      }
    }
  }
}
```

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

<div id="3-start-opencode">
  ### 3. 启动 OpenCode
</div>

```bash theme={null}
opencode
```

OpenCode 会在启动时加载 MCP 服务器。请确认已接入 Firecrawl：

```
/mcp
```

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

```
进行网页搜索，查找 "Bun 2.0 changelog" 并总结排名靠前的结果。
```

```
抓取 https://docs.firecrawl.dev/introduction and list the code examples.
```

```
爬取 https://example.com/blog and save each post as markdown.
```

<div id="remote-hosted-url-no-nodejs-required">
  ## Remote Hosted URL (无需 Node.js)
</div>

```json theme={null}
{
  "mcp": {
    "firecrawl": {
      "type": "remote",
      "url": "https://mcp.firecrawl.dev/fc-YOUR-API-KEY/v2/mcp"
    }
  }
}
```

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

* **服务器未连接** — 运行 `opencode doctor` 检查 MCP 加载错误。
* **`npx` 权限被拒绝** — 安装 Node.js 18+，并确保 shell 已正确识别该安装 (`which npx`) 。
