本页内容
VS Code 中 GitHub Copilot 的 agent 模式可以读取你的仓库、运行终端命令并编辑文件——但它无法可靠地获取实时网页。加上 CrawlForge MCP,Copilot 就获得了从 fetch_url 到 deep_research 的 20 个 scraping 工具。
本指南将分步带你在 GitHub Copilot agent 中启用 web scraping,并附上可运行的 TypeScript 示例以及常见坑的排查方法。
目录
- 问题:Copilot 受限的网页访问
- 前置条件
- 步骤 1:安装 CrawlForge MCP
- 步骤 2:启用 Copilot agent 模式
- 步骤 3:注册 MCP server
- 步骤 4:确认工具可用
- 步骤 5:你的第一次 scrape
- 完整示例:从实时文档生成 REST 客户端
- 进阶:多工具工作流
- 故障排查
- FAQ
问题:Copilot 受限的网页访问
Copilot Chat 有一个 @web 参与者,但它会把你的查询重写为 Bing 搜索——没有原始页面访问、没有结构化提取、没有反爬绕过。在 agent 模式下,Copilot 可以运行 shell 命令,所以你确实可以通过一次工具调用把 curl | pandoc 串起来,但那会漏掉 JavaScript 渲染的页面,并在几分钟内触发反爬系统。
MCP 解决了这个问题。自 VS Code 1.102 在 2025 年年中正式发布 MCP 支持以来,Copilot agent 可以调用你注册的任何 MCP server。CrawlForge 以 MCP 形式暴露了 20 个 scraping 工具,因此 scraping 成为一等的 agent 操作。
前置条件
- VS Code 1.102+ --
code --version - GitHub Copilot 订阅(Individual、Business 或 Enterprise)并启用 agent 模式
- Node.js 18+
- CrawlForge 账户 -- 在 crawlforge.dev/signup 免费注册
步骤 1:安装 CrawlForge MCP
步骤 2:启用 Copilot agent 模式
- 打开 VS Code 设置(
Cmd+,/Ctrl+,)。 - 搜索
chat.agent.enabled并将其打开。 - 打开 Copilot Chat(
Ctrl+Alt+I/Cmd+Ctrl+I),把模式下拉框从 “Ask” 切换为 “Agent”。
正是 agent 模式启用了 MCP 工具调用。在 “Ask” 或 “Edit” 模式下,Copilot 会忽略已注册的 MCP server。
步骤 3:注册 MCP server
VS Code 在两个作用域支持 MCP:
- Workspace -- 仓库根目录下的
.vscode/mcp.json(通过 git 在团队间共享) - User -- 通过 “MCP: Add Server” 命令面板编辑(个人)
对于团队 scraping,使用 workspace 配置:
然后在你的 shell 中导出该 key(不要把它提交到仓库):
或者使用 ${input:apiKey},VS Code 会按 workspace 提示你输入一次。
步骤 4:确认工具可用
- 打开 Copilot Chat。
- 点击聊天标题栏中的工具图标。
- 确认
crawlforge已列出,含 20 个工具。取消勾选任何你想隐藏的工具。
如果列表为空,请跳到故障排查。
步骤 5:你的第一次 scrape
在 Copilot Chat(agent 模式)中粘贴:
#crawlforge Fetch https://news.ycombinator.com and list the top 5 story titles with their URLs.
#crawlforge 提示会把 Copilot 引向正确的工具。Copilot 调用 fetch_url(1 credit),收到 HTML,解析标题,并将它们就地返回。
完整示例:从实时文档生成 REST 客户端
下面是一个具体的工作流:从实时文档自动生成一个带类型的 Stripe 客户端。
向 Copilot agent 发出 prompt:
#crawlforge Use extract_content on https://docs.stripe.com/api/charges/create.
Then in src/clients/stripe-charges.ts, write a typed function createCharge(params)
that calls the Stripe API with the exact fields documented on that page.
Add a Zod schema for params.
Copilot 发出这次 MCP 调用:
Copilot 读取该 markdown 并写出:
成本:2 credits(一次 extract_content 调用)。对每个 Stripe 端点重复这一过程,你就得到一个完全从实时文档派生出来的带类型客户端。
进阶:多工具工作流
Copilot agent 擅长串联工具。示例 prompt:
#crawlforge 1) search_web for "OpenTelemetry Node.js auto-instrumentation 2026"
2) extract_content from the top 3 results
3) Summarize the differences into docs/otel-options.md with a decision matrix.
Copilot 依次运行这三次 MCP 调用,把结果向前传递,并写出 markdown。总成本:约 11 credits(5 + 2 + 2 + 2)。
credits 速查
| 任务 | 工具 | Credits |
|---|---|---|
| 静态 HTML 获取 | fetch_url | 1 |
| 干净的文章正文 | extract_content | 2 |
| CSS 选择器字段 | scrape_structured | 2 |
| 发现 URL | map_site | 2 |
| 网页搜索 | search_web | 5 |
| 反爬绕过 | stealth_mode | 5 |
| 深度研究 | deep_research | 10 |
故障排查
工具列表为空 -- agent 模式已关闭。在设置中启用 chat.agent.enabled 并把聊天模式切换为 “Agent”。
“Spawn ENOENT: crawlforge-mcp-server” -- VS Code 找不到可执行文件。在 .vscode/mcp.json 中使用绝对路径:"command": "/usr/local/bin/crawlforge-mcp-server"。
Copilot 忽略 MCP server -- 在你的 prompt 前加上 #crawlforge,或显式指定一个工具:“Use fetch_url to...”。Copilot 有时会默认选用内置工具。
401 Unauthorized -- 环境变量没有传到服务器。在启动 VS Code 的同一个 shell 里检查 echo $CRAWLFORGE_API_KEY。在 macOS 上,从图形界面启动的 VS Code 不会继承 shell 环境——请从终端用 code . 启动。
workspace 的 MCP 配置未加载 -- VS Code 不会自动信任 .vscode/mcp.json。打开该文件,点击 “Trust” 通知,然后重新加载窗口。
下一步
- 阅读 20 个工具总览,了解完整工具集
- 研读 MCP 协议讲解,理解 VS Code 如何与服务器通信
- 查看 入门文档 了解 REST API
- 如果你正在评估 scraping 厂商,可与 Firecrawl 替代方案对比
在 crawlforge.dev/signup 用 1,000 个 credits 免费开始。