opción

Crear, compilar y validar scripts de inicio de WebMCP específicos para cada sitio a partir de una URL de destino y la funcionalidad deseada de la herramienta.

...Expandir todo
0
Tiempo actualizado 30 de septiembre de 2026

WebMCP Gen

Crea herramientas WebMCP específicas para tu sitio web escribiendo un manifiesto, compilándolo en un script de inicio y comprobando que Chrome registre y ejecute las herramientas.

Esta habilidad no llama a ningún agente anidado. Eres responsable de explorar la página, escribir el archivo manifest.json y realizar iteraciones en función del resultado de la validación.

Comprobación de la configuración

Desde el directorio de la habilidad, instala las dependencias si aún no están instaladas:

cd skills/webmcp-gen
pnpm install

Esto instala el paquete Stagehand fijado, además de la cadena de herramientas de TypeScript (tsx, typescript, @types/node) utilizada para ejecutar el archivo stagehand-example.ts generado.

Flujo de trabajo

  1. Elige un slug de artefacto que contenga exactamente una barra:
/

Ejemplo:

example.com/page-context
  1. Genera la estructura del artefacto:
node scripts/scaffold.mjs example.com/page-context --url https://example.com
  1. Explora la página de destino con la CLI de navegación:
browse open https://example.com --local
browse snapshot
browse get title
browse get url
browse get text body
browse get html body

Es preferible utilizar «browse snapshot», el texto de la página y la inspección del DOM en lugar de capturas de pantalla, a menos que el diseño visual sea importante. Utiliza «browse stop» cuando hayas terminado la exploración.

  1. Edita «artifacts///manifest.json». El manifiesto es la fuente de referencia.

  2. Compilar:

node scripts/compile.mjs artifacts/example.com/page-context
  1. Genera un ejemplo de Stagehand ejecutable (stagehand-example.ts) y ejecútalo con tsx:
node scripts/generate-stagehand-example.mjs artifacts/example.com/page-context
npx tsx artifacts/example.com/page-context/stagehand-example.ts
  1. Validar:
node scripts/validate.mjs artifacts/example.com/page-context
  1. Si la validación falla, revisa eval.json y eval-report.md, corrige manifest.json y, a continuación, vuelve a compilar y validar.

Contrato del manifiesto

{
  "domain": "example.com",
  "task": "page-context",
  "url": "https://example.com",
  "generatedAt": "2026-06-04T00:00:00.000Z",
  "tools": [
    {
      "name": "example_com_page_context",
      "description": "Devuelve el contexto de la página.",
      "inputSchema": {
        "type": "object",
        "properties": {},
        "required": []
      },
      "implementation": {
        "kind": "dom",
        "source": "return { success: true, title: document.title, url: location.href };"
      },
      "fixtureInput": {}
    }
  ]
}

Normas de redacción

  • implementation.source se inserta dentro de async (input) => { ... }; escribe sentencias de JavaScript, no una envoltura de función completa.
  • Devuelve un objeto serializable en JSON.
  • El código WebMCP se ejecuta dentro de la página del navegador. Utiliza las API nativas del navegador: document, location, navigator y fetch de mismo origen.
  • No utilices Playwright, Puppeteer, Stagehand, ayudantes de XPath ni comandos de agente/navegador dentro de ` implementation.source`.
  • document.querySelector y querySelectorAll solo deben recibir selectores CSS válidos del navegador.
  • Para encontrar texto visible, utiliza Array.from(document.querySelectorAll(...)).find((el) => (el.textContent || "").includes("...")).
  • No incluyas claves de API, tokens de portador, cookies, secretos de localStorage ni credenciales de usuario.
  • No utilices eval ni new Function.
  • Evita las acciones destructivas a menos que el usuario las haya solicitado explícitamente.
  • Realiza implementaciones defensivas: comprueba si faltan elementos y devuelve respuestas estructuradas del tipo { success: false, error: "..." }.
  • Los scripts de inicialización generados registran las herramientas de WebMCP únicamente en el marco superior.

Estructura de salida

artifacts///
  manifest.json
  webmcp.init.js
  stagehand-example.ts
  eval.json
  eval-report.md

Para convertir el ejemplo en un proyecto independiente, crea una aplicación Stagehand con npx create-browser-app e incorpora en ella el archivo webmcp.init.js generado (cárgalo con page.addInitScript({ path: "webmcp.init.js" })).

Ver en 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" })`).

Instalar webmcp-gen

Descarga y descomprime los archivos de habilidades en tu directorio .claude/skills/.

Descargar ZIP

Clona el repositorio y copia los archivos de la habilidad a tu proyecto.

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

Copiar Copiar
Configuración rápida: Copia la carpeta de la habilidad en .claude/skills/ Claude detectará y utilizará automáticamente la habilidad
Repositorio browserbase/skills

Habilidades relacionadas

algorithmic-art
Tiempo actualizado 27 de agosto de 2026
systematic-debugging
Tiempo actualizado 3 de septiembre de 2026
tech-debt-tracker
Tiempo actualizado 29 de agosto de 2026
continual-learning
Tiempo actualizado 10 de septiembre de 2026
OR