关于 webmcp-gen
webmcp-gen 是用于为特定网站编写 WebMCP 工具的技能,面向构建浏览器页面工具的开发者。它以 manifest 为来源,生成初始化脚本,并通过 Chrome 验证工具注册与调用。
主要功能
- 01从 manifest 编译初始化脚本
- 02使用 browse CLI 探查网页
- 03生成 Stagehand 示例
- 04验证工具注册与调用
- 05依据验证报告修订 manifest
适用场景
- 01为网站页面定义可调用的 WebMCP 工具
- 02检查 Chrome 是否注册并执行工具
MCP 相关
该技能生成注册 WebMCP 工具的初始化脚本,并验证 Chrome 中的注册和调用。
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ browserbase/ skills --skill webmcp-gen安装后在 Claude Code 中输入/webmcp-gen确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
.gitignoreLICENSE.txtpackage.jsonpnpm-lock.yamlscripts/compile.mjsgenerate-stagehand-example.mjsscaffold.mjsvalidate.mjs详细介绍
WebMCP Gen
通过编写清单、将其编译为初始化脚本,并验证 Chrome 是否注册和调用工具,为特定网站编写 WebMCP 工具。
此技能不会调用嵌套 Agent。你需要负责探索页面、编写 manifest.json,并根据验证输出反复调整。
设置检查
在技能目录中,如果尚未安装依赖,请安装:
cd skills/webmcp-gen
pnpm install
这会安装固定版本的 Stagehand 软件包,以及用于运行生成的 stagehand-example.ts 的 TypeScript 工具链(tsx、
typescript、@types/node)。
工作流
- 选择一个恰好包含一个斜杠的制品 slug:
<domain>/<task>
示例:
example.com/page-context
- 创建制品脚手架:
node scripts/scaffold.mjs example.com/page-context --url https://example.com
- 使用
browseCLI 探索目标页面:
browse open https://example.com --local
browse snapshot
browse get title
browse get url
browse get text body
browse get html body
除非布局的视觉效果很重要,否则优先使用 browse snapshot、页面文本和 DOM 检查,而不是截图。探索完成后,使用 browse stop。
-
编辑
artifacts/<domain>/<task>/manifest.json。清单是唯一可信来源。 -
编译:
node scripts/compile.mjs artifacts/example.com/page-context
- 生成可运行的 Stagehand 示例(
stagehand-example.ts),并使用tsx运行:
node scripts/generate-stagehand-example.mjs artifacts/example.com/page-context
npx tsx artifacts/example.com/page-context/stagehand-example.ts
- 验证:
node scripts/validate.mjs artifacts/example.com/page-context
- 如果验证失败,请检查
eval.json和eval-report.md,修补manifest.json,然后再次编译并验证。
清单规范
{
"domain": "example.com",
"task": "page-context",
"url": "https://example.com",
"generatedAt": "2026-06-04T00:00:00.000Z",
"tools": [
{
"name": "example_com_page_context",
"description": "Returns page context.",
"inputSchema": {
"type": "object",
"properties": {},
"required": []
},
"implementation": {
"kind": "dom",
"source": "return { success: true, title: document.title, url: location.href };"
},
"fixtureInput": {}
}
]
}
编写规则
implementation.source会插入到async (input) => { ... }内;请编写 JavaScript 语句,不要编写完整的函数封装。- 返回可序列化为 JSON 的对象。
- WebMCP 代码在浏览器页面内运行。请使用浏览器原生 API:
document、location、navigator和同源fetch。 - 不要在
implementation.source中使用 Playwright、Puppeteer、Stagehand、XPath 辅助工具或 Agent/浏览器命令。 document.querySelector和querySelectorAll只能接收有效的浏览器 CSS 选择器。- 如需查找可见文本,请使用
Array.from(document.querySelectorAll(...)).find((el) => (el.textContent || "").includes("..."))。 - 不要包含 API 密钥、Bearer 令牌、Cookie、localStorage 机密或用户凭据。
- 不要使用
eval或new Function。 - 除非用户明确要求,否则请避免执行破坏性操作。
- 编写实现时应采取防御性措施:检查元素是否缺失,并返回结构化的
{ success: false, error: "..." }响应。 - 生成的初始化脚本只会在顶层框架中注册 WebMCP 工具。
输出布局
artifacts/<domain>/<task>/
manifest.json
webmcp.init.js
stagehand-example.ts
eval.json
eval-report.md
如需将示例转换为独立项目,请使用
npx create-browser-app 创建 Stagehand 应用,并将生成的 webmcp.init.js 放入其中(使用 page.addInitScript({ path: "webmcp.init.js" }) 加载)。
评论
支持 Markdown