webmcp-gen
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWebMCP Gen
WebMCP 生成工具
Author website-specific WebMCP tools by writing a manifest, compiling it to an init script, and validating that Chrome registers and invokes the tools.
This skill does not call a nested agent. You are responsible for exploring the page, writing , and iterating based on validation output.
manifest.json通过编写清单文件、将其编译为初始化脚本,并验证Chrome是否能注册和调用这些工具,来编写特定网站的WebMCP工具。
该技能不会调用嵌套Agent。你需要负责探索页面、编写,并根据验证输出进行迭代优化。
manifest.jsonSetup check
环境检查
From the skill directory, install dependencies if they are not already installed:
bash
cd skills/webmcp-gen
pnpm installThis installs the pinned Stagehand package plus the TypeScript toolchain (,
, ) used to run the generated .
tsxtypescript@types/nodestagehand-example.ts如果尚未安装依赖项,请从技能目录执行以下命令进行安装:
bash
cd skills/webmcp-gen
pnpm install此命令会安装指定版本的Stagehand包,以及运行生成的所需的TypeScript工具链(、、)。
stagehand-example.tstsxtypescript@types/nodeWorkflow
工作流程
- Pick an artifact slug with exactly one slash:
text
<domain>/<task>Example:
text
example.com/page-context- Scaffold the artifact:
bash
node scripts/scaffold.mjs example.com/page-context --url https://example.com- Explore the target page with the CLI:
browse
bash
browse open https://example.com --local
browse snapshot
browse get title
browse get url
browse get text body
browse get html bodyPrefer , page text, and DOM inspection over screenshots unless visual layout matters. Use when exploration is complete.
browse snapshotbrowse stop-
Edit. The manifest is the source of truth.
artifacts/<domain>/<task>/manifest.json -
Compile:
bash
node scripts/compile.mjs artifacts/example.com/page-context- Generate a runnable Stagehand example () and run it with
stagehand-example.ts:tsx
bash
node scripts/generate-stagehand-example.mjs artifacts/example.com/page-context
npx tsx artifacts/example.com/page-context/stagehand-example.ts- Validate:
bash
node scripts/validate.mjs artifacts/example.com/page-context- If validation fails, inspect and
eval.json, patcheval-report.md, then compile and validate again.manifest.json
- 选择一个包含且仅包含一个斜杠的产物标识:
text
<domain>/<task>示例:
text
example.com/page-context- 生成产物脚手架:
bash
node scripts/scaffold.mjs example.com/page-context --url https://example.com- 使用命令行工具探索目标页面:
browse
bash
browse open https://example.com --local
browse snapshot
browse get title
browse get url
browse get text body
browse get html body除非视觉布局很重要,否则优先使用、页面文本和DOM检查,而非截图。探索完成后使用命令结束。
browse snapshotbrowse stop-
编辑。该清单文件是核心数据源。
artifacts/<domain>/<task>/manifest.json -
编译:
bash
node scripts/compile.mjs artifacts/example.com/page-context- 生成可运行的Stagehand示例文件(),并使用
stagehand-example.ts运行:tsx
bash
node scripts/generate-stagehand-example.mjs artifacts/example.com/page-context
npx tsx artifacts/example.com/page-context/stagehand-example.ts- 验证:
bash
node scripts/validate.mjs artifacts/example.com/page-context- 如果验证失败,请检查和
eval.json,修改eval-report.md后重新编译并验证。manifest.json
Manifest contract
清单文件规范
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": {}
}
]
}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": {}
}
]
}Authoring rules
编写规则
- is inserted inside
implementation.source; write JavaScript statements, not a full function wrapper.async (input) => { ... } - Return a JSON-serializable object.
- WebMCP code runs inside the browser page. Use browser-native APIs: ,
document,location, and same-originnavigator.fetch - Do not use Playwright, Puppeteer, Stagehand, XPath helpers, or agent/browser commands inside .
implementation.source - and
document.querySelectormust receive valid browser CSS selectors only.querySelectorAll - To find visible text, use .
Array.from(document.querySelectorAll(...)).find((el) => (el.textContent || "").includes("...")) - Do not include API keys, bearer tokens, cookies, localStorage secrets, or user credentials.
- Do not use or
eval.new Function - Avoid destructive actions unless the user explicitly asked for them.
- Make implementations defensive: check for missing elements and return structured responses.
{ success: false, error: "..." } - Generated init scripts register WebMCP tools only in the top frame.
- 的内容会被插入到
implementation.source内部;只需编写JavaScript语句,无需完整的函数包装。async (input) => { ... } - 返回一个可JSON序列化的对象。
- WebMCP代码在浏览器页面内运行。请使用浏览器原生API:、
document、location以及同源navigator。fetch - 请勿在中使用Playwright、Puppeteer、Stagehand、XPath辅助工具或Agent/浏览器命令。
implementation.source - 和
document.querySelector必须仅接收有效的浏览器CSS选择器。querySelectorAll - 如需查找可见文本,请使用。
Array.from(document.querySelectorAll(...)).find((el) => (el.textContent || "").includes("...")) - 请勿包含API密钥、Bearer令牌、Cookie、localStorage机密或用户凭证。
- 请勿使用或
eval。new Function - 除非用户明确要求,否则避免执行破坏性操作。
- 实现需具备防御性:检查缺失元素,并返回结构化的响应。
{ success: false, error: "..." } - 生成的初始化脚本仅在顶层框架中注册WebMCP工具。
Output layout
输出目录结构
text
artifacts/<domain>/<task>/
manifest.json
webmcp.init.js
stagehand-example.ts
eval.json
eval-report.mdTo turn the example into a standalone project, scaffold a Stagehand app with
and drop the generated into it (load it
with ).
npx create-browser-appwebmcp.init.jspage.addInitScript({ path: "webmcp.init.js" })text
artifacts/<domain>/<task>/
manifest.json
webmcp.init.js
stagehand-example.ts
eval.json
eval-report.md如需将示例转换为独立项目,请使用生成Stagehand应用脚手架,然后将生成的放入其中(通过加载)。
npx create-browser-appwebmcp.init.jspage.addInitScript({ path: "webmcp.init.js" })