選項

根據目標 URL 和所需的工具功能,建立、編譯並驗證針對特定網站的 WebMCP 初始化腳本。

...展開全部
0
更新時間 2026-09-30

WebMCP Gen

透過撰寫清單檔案、將其編譯為初始化腳本,並驗證 Chrome 是否已註冊並呼叫該工具,來建立專屬網站的 WebMCP 工具。

此技能不會呼叫嵌套的代理程式。您需負責探索頁面、撰寫manifest.json,並根據驗證結果進行迭代。

設定檢查

請從技能目錄中,若尚未安裝,請安裝以下依賴項:

cd skills/webmcp-genpnpm install

此操作將安裝已固定(pinned)的 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,然後重新編譯並再次驗證。

Manifest 合約

{
  "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 會自動偵測並使用該技能
儲存庫 browserbase/skills

相關技能

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