validate-ui-mcp

v0.3.6
@keboola/validate-ui-mcp Checked 3 days ago Published 1 month ago

Local stdio MCP server — the UI-authoring counterpart to the hosted keboola/mcp-server — exposing discover (discover_design), scaffold (scaffold_app)…

A local stdio MCP server that exposes Keboola's rendered-UI validator (@keboola/validate-ui) and its scorer (@keboola/ui-gen-bench) as agent-callable tools. Point a UI-generating agent at it and it can validate and score its own output in a closed loop. keboola/mcp-server is a deployed platform service. This tool boots a headless browser (chromium) against a locally-served build — a hosted server has no browser and no access to the agent's working tree, so it can't. This MCP therefore runs in-process on the agent's machine and speaks stdio. It is deliberately kept out of the hosted server.

Summary extracted from the README.

@keboola/validate-ui-mcp

A local stdio MCP server that exposes Keboola's rendered-UI validator (@keboola/validate-ui) and its scorer (@keboola/ui-gen-bench) as agent-callable tools. Point a UI-generating agent at it and it can validate and score its own output in a closed loop.

Why this is a local MCP, not the hosted keboola/mcp-server

keboola/mcp-server is a deployed platform service. This tool boots a headless browser (chromium) against a locally-served build — a hosted server has no browser and no access to the agent's working tree, so it can't. This MCP therefore runs in-process on the agent's machine and speaks stdio. It is deliberately kept out of the hosted server.

Tools

Tool Input Output
validate_ui { url: string, brief?: string } AggregateVerdict — { url, pass, verdicts: [{ axis, pass, findings }] }
score_ui { url: string, brief?: string } { verdict: AggregateVerdict, score: BenchScore } — score.total is 0-100
serve_and_score { distDir: string, route?: string, brief?: string } { verdict, score } — serves the dir, scores route (default /), then closes

Every tool returns MCP content with a single JSON text block. On failure it returns an MCP error result (isError: true) carrying the message — the server never crashes on a bad run.

brief-conformance is the only axis that calls an LLM: it needs ANTHROPIC_API_KEY in the environment and skips (non-fatal) without it, so the other axes still score.

The generate → validate → fix loop

1. Generate / edit a UI module.
2. Serve it (or build a `dist`).
3. Call score_ui({ url, brief })            // or serve_and_score({ distDir, route, brief })
4. Read score.total and, for each verdict where pass === false, its findings.
5. Fix the findings.
6. Repeat from 3 until score.total clears your bar (e.g. >= 80).

score.total is a single tunable number to gate on; the failing axes' findings tell you what to fix. Use validate_ui alone when you only want the raw verdict without a numeric gate.

Registering it in an MCP client

Build the package once (corepack pnpm --filter @keboola/validate-ui-mcp build), install a chromium for Playwright (pnpm exec playwright install chromium), then register the validate-ui-mcp bin as a stdio server. Example client config:

{
  "mcpServers": {
    "validate-ui": {
      "command": "node",
      "args": ["/absolute/path/to/packages/validate-ui-mcp/dist/bin.js"],
      "env": {
        "ANTHROPIC_API_KEY": "sk-ant-..."
      }
    }
  }
}

env.ANTHROPIC_API_KEY is optional — omit it and brief-conformance simply skips. The package is published, so npx @keboola/validate-ui-mcp works outside this repo.

In-repo the entry is not named directly. The repo's own .mcp.json points at scripts/validate-ui-mcp.mjs:

  • dist/ is gitignored, so a fresh clone and every new worktree start without it.
  • A client launches its MCP servers before anything has run a build, so naming dist/bin.js there fails with ERR_MODULE_NOT_FOUND and surfaces only as Connection closed.
  • The launcher builds the package (turbo-cached: ~0.15s warm, ~3s cold) and hands over to the real entry in the same process.
  • It builds on every start, not only when dist/bin.js is missing. A checkout leaves an ignored dist/ where it was, so an entry that exists says nothing about the source it was built from.
  • A build that fails is fatal only when there is no entry to fall back to. Otherwise the launcher starts what it has and says on stderr that it may be stale — losing the server for a whole session is the worse outcome.

scripts/validate-ui-mcp.test.mjs covers those cases; pnpm test:scripts runs it.