webmcp-gen
browserbase/skills
Erstellen, kompilieren und validieren Sie standortspezifische WebMCP-Init-Skripte anhand einer Ziel-URL und der gewünschten Tool-Funktionalität.
...Alle erweiternWebMCP Gen
Erstellen Sie websitespezifische WebMCP-Tools, indem Sie ein Manifest schreiben, es zu einem Init-Skript kompilieren und überprüfen, ob Chrome die Tools registriert und aufruft.
Diese Funktion ruft keinen verschachtelten Agenten auf. Sie sind dafür verantwortlich, die Seite zu erkunden, die Datei „manifest.json“ zu erstellen und basierend auf den Validierungsergebnissen iterativ vorzugehen.
Einrichtungsprüfung
Installieren Sie im Skill-Verzeichnis die Abhängigkeiten, falls diese noch nicht installiert sind:
cd skills/webmcp-gen
pnpm install
Dadurch werden das angeheftete Stagehand-Paket sowie die TypeScript-Toolchain (tsx,
typescript, @types/node) installiert, die zur Ausführung der generierten Datei „stagehand-example.ts“ benötigt wird.
Arbeitsablauf
- Wählen Sie einen Artefakt-Slug mit genau einem Schrägstrich aus:
/
Beispiel:
example.com/page-context
- Erstellen Sie das Scaffold für das Artefakt:
node scripts/scaffold.mjs example.com/page-context --url https://example.com
- Die Zielseite mit der
„browse“-CLI erkunden:
browse open https://example.com --local
browse snapshot
browse get title
browse get url
browse get text body
browse get html body
Verwenden Sie „browse snapshot“, „page text“ und die DOM-Inspektion statt Screenshots, es sei denn, das visuelle Layout ist entscheidend. Verwenden Sie „browse stop“, wenn die Erkundung abgeschlossen ist.
Bearbeiten Sie die
Dateien „artifacts/“. Das Manifest ist die maßgebliche Quelle.“ und „ /manifest.json Kompilieren:
node scripts/compile.mjs artifacts/example.com/page-context
- Erstellen Sie ein ausführbares Stagehand-Beispiel (
stagehand-example.ts) und führen Sie es mittsxaus:
node scripts/generate-stagehand-example.mjs artifacts/example.com/page-context
npx tsx artifacts/example.com/page-context/stagehand-example.ts
- Validieren:
node scripts/validate.mjs artifacts/example.com/page-context
- Falls die Validierung fehlschlägt, überprüfen Sie
„eval.json“und„eval-report.md“, passen Sie„manifest.json“an und führen Sie anschließend erneut eine Kompilierung und Validierung durch.
Manifest-Vertrag
{
"domain": "example.com",
"task": "page-context",
"url": "https://example.com",
"generatedAt": "2026-06-04T00:00:00.000Z",
"tools": [
{
"name": "example_com_page_context",
"description": "Gibt den Seitenkontext zurück.",
"inputSchema": {
"type": "object",
"properties": {},
"required": []
},
"implementation": {
"kind": "dom",
"source": "return { success: true, title: document.title, url: location.href };"
},
"fixtureInput": {}
}
]
}
Regeln für die Erstellung
`implementation.source`wird innerhalb von`async (input) => { ... };` eingefügt; schreiben Sie JavaScript-Anweisungen, keinen vollständigen Funktions-Wrapper.- Geben Sie ein JSON-serialisierbares Objekt zurück.
- WebMCP-Code wird innerhalb der Browserseite ausgeführt. Verwenden Sie browser-native APIs:
`document`,`location`,`navigator` und `same-originfetch`. - Verwenden Sie innerhalb von `
implementation.source` keine Playwright-, Puppeteer-, Stagehand- oder XPath-Helfer sowie keine Agent-/Browser-Befehle. „document.querySelector“und„querySelectorAll“dürfen nur gültige Browser-CSS-Selektoren als Argumente erhalten.- Um sichtbaren Text zu finden, verwende
`Array.from(document.querySelectorAll(...)).find((el) => (el.textContent || "").includes("...")). - Fügen Sie keine API-Schlüssel, Bearer-Token, Cookies, „localStorage“-Geheimnisse oder Benutzeranmeldedaten ein.
- Verwenden Sie weder `
eval` noch `new Function`. - Vermeiden Sie destruktive Aktionen, es sei denn, der Benutzer hat ausdrücklich darum gebeten.
- Gestalten Sie die Implementierungen defensiv: Prüfen Sie auf fehlende Elemente und geben Sie strukturierte Antworten
vom Typ { success: false, error: "..." }zurück. - Generierte Init-Skripte registrieren WebMCP-Tools nur im obersten Frame.
Ausgabe-Layout
artifacts///
manifest.json
webmcp.init.js
stagehand-example.ts
eval.json
eval-report.md
Um das Beispiel in ein eigenständiges Projekt umzuwandeln, erstellen Sie mit
npx create-browser-app das Grundgerüst einer Stagehand-App und fügen Sie die generierte Datei webmcp.init.js dort ein (laden Sie sie
mit page.addInitScript({ path: "webmcp.init.js" })).
---
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 installieren
Laden Sie die Skill-Dateien herunter und entpacken Sie sie in Ihr Verzeichnis „.claude/skills/“.
ZIP herunterladenKlonen Sie das Repository und kopieren Sie die Skill-Dateien in Ihr Projekt.
git clone https://github.com/browserbase/skills/tree/main/skills/webmcp-gen # Copy SKILL.md to your .claude/skills/ directory
Kopieren





Heim
