选项

根据目标 URL 和所需的工具功能,创建、编译并验证针对特定站点的 WebMCP 初始化脚本。

...展开全部
0
更新时间 2026-09-30

WebMCP Gen

通过编写清单文件、将其编译为初始化脚本,并验证 Chrome 是否已注册并调用这些工具,从而开发适用于特定网站的 WebMCP 工具。

该技能不会调用嵌套代理。您需要负责浏览页面、编写manifest.json 文件,并根据验证结果进行迭代。

设置检查

在技能目录下,若尚未安装依赖项,请执行以下操作:

cd skills/webmcp-genpnpm install

这将安装已固定的 Stagehand 包,以及用于运行生成的stagehand-example.ts 文件的 TypeScript 工具链(tsx、 typescript、@types/node)。

工作流

  1. 选择一个仅包含一个斜杠的工件 slug:
/

示例:

example.com/page-context
  1. 生成构建产物:
node scripts/scaffold.mjs example.com/page-context --url https://example.com
  1. 使用browse命令行工具浏览目标页面:
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` 停止。

  1. 编辑artifacts///manifest.json。清单文件是权威数据源。

  2. 编译:

node scripts/compile.mjs artifacts/example.com/page-context
  1. 生成可运行的 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
  1. 验证:
node scripts/validate.mjs artifacts/example.com/page-context
  1. 如果验证失败,请检查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": "返回页面上下文。",
      "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 辅助函数或代理/浏览器命令。
  • document.querySelector和querySelectorAll必须仅接收有效的浏览器 CSS 选择器。
  • 要查找可见文本,请使用Array.from(document.querySelectorAll(...)).find((el) => (el.textContent || "").includes("..."))。
  • 请勿包含 API 密钥、承运者令牌、Cookie、localStorage 密钥或用户凭据。
  • 请勿使用eval或new Function。
  • 除非用户明确要求,否则应避免执行破坏性操作。
  • 实现时应采取防御性措施:检查是否缺少元素,并返回结构化的{ success: false, error: "..." }响应。
  • 生成的初始化脚本仅在顶层框架中注册 WebMCP 工具。

输出布局

artifacts///
  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" }) 加载该文件)。

在 GitHub 上查看
---
name: webmcp-gen
description: Create, compile, and validate site-specific WebMCP init scripts from a target URL and desired tool capability.
license: MIT
---

# WebMCP Gen

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 `manifest.json`, and iterating based on validation output.

## Setup check

From the skill directory, install dependencies if they are not already installed:

```bash
cd skills/webmcp-gen
pnpm install
```

This installs the pinned Stagehand package plus the TypeScript toolchain (`tsx`,
`typescript`, `@types/node`) used to run the generated `stagehand-example.ts`.

## Workflow

1. Pick an artifact slug with exactly one slash:

```text
<domain>/<task>
```

Example:

```text
example.com/page-context
```

2. Scaffold the artifact:

```bash
node scripts/scaffold.mjs example.com/page-context --url https://example.com
```

3. Explore the target page with the `browse` CLI:

```bash
browse open https://example.com --local
browse snapshot
browse get title
browse get url
browse get text body
browse get html body
```

Prefer `browse snapshot`, page text, and DOM inspection over screenshots unless visual layout matters. Use `browse stop` when exploration is complete.

4. Edit `artifacts/<domain>/<task>/manifest.json`. The manifest is the source of truth.

5. Compile:

```bash
node scripts/compile.mjs artifacts/example.com/page-context
```

6. Generate a runnable Stagehand example (`stagehand-example.ts`) and run it with `tsx`:

```bash
node scripts/generate-stagehand-example.mjs artifacts/example.com/page-context
npx tsx artifacts/example.com/page-context/stagehand-example.ts
```

7. Validate:

```bash
node scripts/validate.mjs artifacts/example.com/page-context
```

8. If validation fails, inspect `eval.json` and `eval-report.md`, patch `manifest.json`, then compile and validate again.

## 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": {}
    }
  ]
}
```

## Authoring rules

- `implementation.source` is inserted inside `async (input) => { ... }`; write JavaScript statements, not a full function wrapper.
- Return a JSON-serializable object.
- WebMCP code runs inside the browser page. Use browser-native APIs: `document`, `location`, `navigator`, and same-origin `fetch`.
- Do not use Playwright, Puppeteer, Stagehand, XPath helpers, or agent/browser commands inside `implementation.source`.
- `document.querySelector` and `querySelectorAll` must receive valid browser CSS selectors only.
- 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 `eval` or `new Function`.
- Avoid destructive actions unless the user explicitly asked for them.
- Make implementations defensive: check for missing elements and return structured `{ success: false, error: "..." }` responses.
- Generated init scripts register WebMCP tools only in the top frame.

## Output layout

```text
artifacts/<domain>/<task>/
  manifest.json
  webmcp.init.js
  stagehand-example.ts
  eval.json
  eval-report.md
```

To turn the example into a standalone project, scaffold a Stagehand app with
`npx create-browser-app` and drop the generated `webmcp.init.js` into it (load it
with `page.addInitScript({ path: "webmcp.init.js" })`).

安装 webmcp-gen

下载技能文件并将其解压到 .claude/skills/ 目录中。

下载ZIP

克隆仓库并复制技能文件到您的项目中。

git clone https://github.com/browserbase/skills/tree/main/skills/webmcp-gen # Copy SKILL.md to your .claude/skills/ directory

复制 复制
快速设置: 将技能文件夹复制到 .claude/skills/ Claude 会自动检测并使用该技能

相关技能

algorithmic-art
更新时间 2026-08-27
systematic-debugging
更新时间 2026-09-03
tech-debt-tracker
更新时间 2026-08-29
continual-learning
更新时间 2026-09-10
OR