webmcp-gen
browserbase/skills
Crie, compile e valide scripts de inicialização do WebMCP específicos para cada site a partir de uma URL de destino e da funcionalidade desejada da ferramenta.
...Expandir tudoWebMCP Gen
Crie ferramentas WebMCP específicas para o site do autor escrevendo um manifesto, compilando-o em um script de inicialização e verificando se o Chrome registra e executa as ferramentas.
Esta habilidade não chama um agente aninhado. Você é responsável por explorar a página, escrever o arquivo manifest.json e iterar com base no resultado da validação.
Verificação de configuração
No diretório da habilidade, instale as dependências, caso ainda não estejam instaladas:
cd skills/webmcp-gen
pnpm install
Isso instala o pacote Stagehand fixado, além da cadeia de ferramentas do TypeScript (tsx,
typescript, @types/node) usada para executar o arquivo stagehand-example.ts gerado.
Fluxo de trabalho
- Escolha um slug de artefato com exatamente uma barra:
/
Exemplo:
example.com/page-context
- Crie a estrutura do artefato:
node scripts/scaffold.mjs example.com/page-context --url https://example.com
- Explorar a página de destino com a CLI
`browse`:
browse open https://example.com --local
browse snapshot
browse get title
browse get url
browse get text body
browse get html body
Dê preferência ao `browse snapshot`, ao texto da página e à inspeção do DOM em vez de capturas de tela, a menos que o layout visual seja importante. Use `browse stop` quando a exploração estiver concluída.
Edite os arquivos
em `artifacts/`: ``. O manifesto é a fonte de verdade.`, ` ` e `manifest.json Compilar:
node scripts/compile.mjs artifacts/example.com/page-context
- Gere um exemplo executável do Stagehand (
stagehand-example.ts) e execute-o como tsx:
node scripts/generate-stagehand-example.mjs artifacts/example.com/page-context
npx tsx artifacts/example.com/page-context/stagehand-example.ts
- Validar:
node scripts/validate.mjs artifacts/example.com/page-context
- Se a validação falhar, verifique os arquivos `
eval.json` e`eval-report.md`, corrijao `manifest.json` e, em seguida, compile e valide novamente.
Contrato do manifesto
{
"domain": "example.com",
"task": "page-context",
"url": "https://example.com",
"generatedAt": "2026-06-04T00:00:00.000Z",
"tools": [
{
"name": "example_com_page_context",
"description": "Retorna o contexto da página.",
"inputSchema": {
"type": "object",
"properties": {},
"required": []
},
"implementation": {
"kind": "dom",
"source": "return { success: true, title: document.title, url: location.href };"
},
"fixtureInput": {}
}
]
}
Regras de criação
implementation.sourceé inserido dentro deasync (input) => { ... }; escreva instruções em JavaScript, não um wrapper de função completo.- Retorne um objeto serializável em JSON.
- O código WebMCP é executado dentro da página do navegador. Use APIs nativas do navegador:
document,location,navigatorefetchde mesma origem. - Não use Playwright, Puppeteer, Stagehand, auxiliares XPath ou comandos de agente/navegador dentro de `
implementation.source`. document.querySelectorequerySelectorAlldevem receber apenas seletores CSS válidos do navegador.- Para localizar texto visível, use
Array.from(document.querySelectorAll(...)).find((el) => (el.textContent || "").includes("...")). - Não inclua chaves de API, tokens de portador, cookies, segredos do localStorage ou credenciais de usuário.
- Não use
evalnemnew Function. - Evite ações destrutivas, a menos que o usuário as tenha solicitado explicitamente.
- Faça implementações defensivas: verifique se há elementos ausentes e retorne respostas estruturadas
como { success: false, error: "..." }. - Os scripts de inicialização gerados registram as ferramentas do WebMCP apenas no quadro superior.
Layout de saída
artifacts///
manifest.json
webmcp.init.js
stagehand-example.ts
eval.json
eval-report.md
Para transformar o exemplo em um projeto independente, crie uma estrutura para um aplicativo Stagehand com
npx create-browser-app e insira o arquivo webmcp.init.js gerado nele (carregue-o
com 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" })`).
Todos os arquivos
8 arquivosInstalar webmcp-gen
Baixe e descompacte os arquivos de habilidades no diretório .claude/skills/.
Baixar ZIPClone o repositório e copie os arquivos da habilidade para o seu projeto.
git clone https://github.com/browserbase/skills/tree/main/skills/webmcp-gen # Copy SKILL.md to your .claude/skills/ directory
Copiar





Lar
