webmcp-gen

作者: browserbase

根据目标URL和所需工具能力,创建、编译并验证特定站点的WebMCP初始化脚本。当用户想要编写WebMCP工具时使用…

npx skills add https://github.com/browserbase/skills --skill webmcp-gen

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:

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:
<domain>/<task>

Example:

example.com/page-context
  1. Scaffold the artifact:
node scripts/scaffold.mjs example.com/page-context --url https://example.com
  1. Explore the target page with the browse CLI:
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.

  1. Edit artifacts/<domain>/<task>/manifest.json. The manifest is the source of truth.

  2. Compile:

node scripts/compile.mjs artifacts/example.com/page-context
  1. Generate a runnable Stagehand example (stagehand-example.ts) and run it with tsx:
node scripts/generate-stagehand-example.mjs artifacts/example.com/page-context
npx tsx artifacts/example.com/page-context/stagehand-example.ts
  1. Validate:
node scripts/validate.mjs artifacts/example.com/page-context
  1. If validation fails, inspect eval.json and eval-report.md, patch manifest.json, then compile and validate again.

Manifest contract

{
  "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

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

来自 browserbase 的更多技能

browser-automation
browserbase
使用MCP工具自动化网页浏览器交互。当用户要求浏览网站、导航网页、从网站提取数据、截图时使用……
official
functions
browserbase
使用官方 Browserbase Functions CLI 指导无服务器浏览器自动化的部署。当用户希望部署自动化以在……上运行时使用。
official
browse
browserbase
使用browse CLI进行Browserbase浏览器自动化、Browserbase云API、Browserbase函数、模板、网页抓取/搜索、诊断以及Browse.sh…
official
browser
browserbase
使用 Browserbase browse CLI 自动化浏览器交互。当任务需要导航网站、读取页面状态、点击元素、填写内容时使用。
official
agent-experience
browserbase
通过仅使用一个简短的任务提示和真实的……,投放多个Claude子代理来审计产品、SDK、文档站点或SKILL.md的开发者体验。
official
autobrowse
browserbase
通过自动研究循环实现自我改进的浏览器自动化。迭代执行浏览任务、读取追踪记录并优化导航技能…
official
browse
browserbase
使用 browse CLI 创建和部署浏览器自动化功能的完整指南
official
browser
browserbase
使用本地Chrome或远程Browserbase进行浏览器自动化,适用于受保护网站、机器人检测和验证码场景。两种模式:本地Chrome(默认,无需配置)或远程Browserbase(反机器人隐身、自动验证码破解、住宅代理、会话持久化)。核心命令涵盖导航、页面检查、交互(点击、输入、填充、选择、拖拽)以及通过CLI进行会话管理。使用browse snapshot读取无障碍树并获取元素引用以实现可靠交互;保留...
official