webmcp-gen
browserbase/skills
Создание, компиляция и проверка скриптов инициализации WebMCP для конкретного сайта на основе целевого URL-адреса и требуемых возможностей инструмента.
...Расширить всеWebMCP Gen
Создавайте инструменты WebMCP для конкретных веб-сайтов, написав манифест, скомпилировав его в скрипт инициализации и убедившись, что Chrome регистрирует и запускает эти инструменты.
Данный навык не вызывает вложенный агент. Вы несете ответственность за обход страницы, написание файла manifest.json и выполнение итераций на основе результатов проверки.
Проверка настроек
Из каталога навыка установите зависимости, если они ещё не установлены:
cd skills/webmcp-gen
pnpm install
Это установит закреплённый пакет Stagehand, а также набор инструментов TypeScript (tsx,
typescript, @types/node), используемый для запуска сгенерированного файла stagehand-example.ts.
Рабочий процесс
- Выберите слэг артефакта, содержащий ровно один косой черту:
/
Пример:
example.com/page-context
- Создайте каркас артефакта:
node scripts/scaffold.mjs example.com/page-context --url https://example.com
- Просмотр целевой страницы с помощью командной строки
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, page text и проверку DOM вместо скриншотов. По завершении изучения используйте команду browse stop.
Отредактируйте файлы в
каталоге artifacts/:. Манифест является основным источником достоверной информации., и 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": "Возвращает контекст страницы.",
"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с одним источником. - Не используйте Playwright, Puppeteer, Stagehand, вспомогательные функции XPath или команды агента/браузера внутри `
implementation.source`. 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///
manifest.json
webmcp.init.js
stagehand-example.ts
eval.json
eval-report.md
Чтобы превратить этот пример в самостоятельный проект, создайте каркас приложения Stagehand с помощью
npx create-browser-app и поместите в него сгенерированный файл webmcp.init.js (загрузите его
с помощью 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
Скачайте файлы навыков и распакуйте их в каталог .claude/skills/.
Скачать ZIPКлонируйте репозиторий и скопируйте файлы навыка в свой проект.
git clone https://github.com/browserbase/skills/tree/main/skills/webmcp-gen # Copy SKILL.md to your .claude/skills/ directory
Копировать





Дом
