c2n Web Components

v1.0.32
io.github.code2nguyen/c2n Checked 4 hours ago Published 8 days ago

Exact APIs, examples, theme tokens and markup validation for the c2n (c2-*) Lit web components.

Model Context Protocol server that exposes the c2n web components to AI agents: component APIs (attributes, slots, events, native CSS parts, CSS variables with their theme tokens), usage and gallery examples, curated presets, the @c2n/theme tokens, variant code generation and the application workflow guides. Everything is bundled in data/registry.json, so it works offline in any project. The server uses stdio and can be launched by any MCP host: Google Antigravity project .agents/mcp_config.json uses the same mcpServers command/args structure as the Claude example.

Summary extracted from the README.

@c2n/mcp

Model Context Protocol server that exposes the c2n web components to AI agents: component APIs (attributes, slots, events, native CSS parts, CSS variables with their theme tokens), usage and gallery examples, curated presets, the @c2n/theme tokens, variant code generation and the application workflow guides. Everything is bundled in data/registry.json, so it works offline in any project.

c2n Web Components MCP server

Use

The server uses stdio and can be launched by any MCP host:

npx -y @c2n/mcp

Claude Code project .mcp.json:

{ "mcpServers": { "c2n": { "type": "stdio", "command": "npx", "args": ["-y", "@c2n/mcp"] } } }

Codex project .codex/config.toml:

[mcp_servers.c2n]
command = "npx"
args = ["-y", "@c2n/mcp"]

Google Antigravity project .agents/mcp_config.json uses the same mcpServers command/args structure as the Claude example. The @c2n/skill package can install the skill and merge these configurations automatically.

Run the server from a project directory: it reports which @c2n/* packages are installed and serves the bundled API when the installed version differs. The registry is packaged locally, so tool calls do not require network access after installation.

Use c2n-mcp --version to inspect the installed server version and c2n-mcp --help for CLI usage.

The MCP server supplies structured component facts; it does not install component packages or edit an application by itself. Pair it with @c2n/skill when you also want the agent to follow c2n's application, theming and variant conventions. See the AI tools guide for the complete setup and example prompts.

Verify the connection

Restart the agent after adding its MCP configuration, then ask it to use the c2n MCP server to list components or inspect c2-button. A connected client should expose the tools below and report @c2n/* packages installed in the current project. If the server cannot start, run npx -y @c2n/mcp --version in that project to distinguish an npm/runtime problem from an MCP client configuration problem.

Tools

Tool Purpose
list_components Every component with tag, package, category, description, installed version
search_components Free-text search across names, descriptions, attributes, slots, events, examples, icons
get_component Full API of one component, CSS variables grouped by part/state with their theme token; a long answer is shortened to fit and names the include that returns the rest
get_examples Usage rows and gallery cards; view: "index" lists every look (summary, screenshot)
search_examples Find a look across every component's gallery ("glass", "pill", "underline")
get_presets Curated presets as CSS variable values
get_theme The --c2-theme--* tokens, install/mapping snippets; per-component mapping with tag
generate_variant CSS class / HTML + style / Lit subclass / JSON from overrides, a preset or a gallery card
validate_markup Checks markup/CSS you wrote: native controls to replace, unknown tags/attributes/slots/events/variables
report_issue Drafts a GitHub issue for a component problem (version, framework, checked repro, existing issues) and a pre-filled form link; never submits
get_workflow_guide workflow, theming, variant-components, frameworks

Gallery cards are served with a generated summary of what they change and CSS whose colours follow the --c2-theme--* tokens wherever a literal equals a token's value (var(--c2-theme--color-outline, #d4d4d8)), so a copied card follows the application's theme and dark mode. Each card also links light and dark PNG captures hosted with the docs site (gallery-shots/<component>/<slug>.<theme>.png, written by apps/ui/scripts/gallery-shots.mjs in the Pages deploy).

Validate from the command line

validate_markup is also a CLI, for CI and editor hooks. It reads HTML, JSX/TSX, Vue, Svelte, Astro, Angular and Lit templates and CSS, and checks them against the API of the @c2n/* packages the project has installed:

npx -y @c2n/mcp validate src            # exit 1 on errors
npx -y @c2n/mcp validate src --strict   # warnings fail too (native controls, box styling on a c2 host)
npx -y @c2n/mcp validate --hook         # Claude Code PostToolUse hook: reads the payload on stdin

It reports native <button>/<input>/<select>/<textarea>/<dialog>/<details>/<progress> elements that a c2-* element replaces, unknown c2-* tags, attributes, slots and --c2-* variables (with "did you mean"), events a c2-* element does not fire (with its event list), a static camelCase attribute the element ignores (rowKey for row-key), and box styling on a c2-* host (border, padding, background, box-shadow, outline; a radius alone is fine). A line holding c2n-ignore, or the line after a comment holding it, is skipped. In hook mode the findings go to stderr with exit code 2, which Claude Code hands back to the agent; npx -y @c2n/skill install registers that hook in .claude/settings.json.

Resources: c2n://components, c2n://components/{tag}, c2n://theme, c2n://guide/{topic}.

Development

  • data/registry.json is an ignored build artifact. pnpm run build:tools (repo root) regenerates it from the component manifests, docs content, presets and theme, then compiles dist/ and refreshes the committed skill fallback.
  • dev, inspect, smoke and npm pack automatically build the registry when needed.
  • pnpm --dir packages/tools/mcp run smoke spawns the server over stdio and checks every tool.
  • pnpm --dir packages/tools/mcp run inspect opens the MCP Inspector against the source entry (node src/cli.ts, Node 24 type stripping).

AI readiness score

pnpm run mcp:readiness (repo root, after pnpm run build) answers one question with a number: given a user requirement, can an AI independently find the correct c2n component, understand its API, generate valid code and use it correctly? The project skill .claude/skills/ai-readiness is how an agent runs it and fixes what it finds.

  • Component readiness (scripts/readiness/score.ts): every component in the registry, scored 0–100 from deterministic checks on what an agent receives (the registry, the manifests, the framework declarations), weighted over six dimensions: identity and purpose 15, API documentation 25, usage examples 20, composition knowledge 15, framework integration 15, validation 10. A check that does not apply is left out of its dimension rather than passed.
  • Discovery (scripts/readiness/tasks.json): 85 requirements written as an app developer would, each with the components that answer it, run through search_components; scored as the mean reciprocal rank, with hit@1 and hit@3. When an agent picks the wrong component in real use, add the requirement there.
  • Lab requirements (scripts/readiness/lab.ts): the requirements the component lab's builds met with c2n components (lab/specs for the words, lab/reports for the components the build used), searched the same way and reported next to discovery, but not in the headline: they were written for a product, so a miss shows a word developers use that the docs do not. Every run measures them; a run with no changed component still records them when their result differs from the committed one (a lab spec, report or build, or a docs input such as component-previews.ts, can move it).
  • Agent run (pnpm --dir packages/tools/mcp run readiness:agent [--all --tasks a,b --model id --concurrency n], opt-in): starts Claude Code headless per requirement in an empty directory with only this MCP server, asks it to write index.html, and grades it — an expected tag used (40), no validate_markup error (30), the task's attributes and slots used (30). By default it runs the fixed agentSet of tasks.json (28 requirements, about $10), so runs stay comparable; it is not in CI.

The headline is component readiness 70% and discovery 30%, or 50/20 plus the agent run's 30% when one exists.

Call log. With C2N_MCP_LOG=<file> in its environment the server appends one JSON line per tool call (src/call-log.ts): the tool, its arguments (validate_markup's code by length only), the component ids a search returned, the component a tag resolved to and what validate_markup reported (severity and rule). Calls are appended only while that file exists, so creating it arms the log and deleting it disarms it; only the arguments that say what was asked (query, tag, options) are logged as written, a filename by its extension, and any other text (code, CSS, issue text) by its length and a list or record by its number of entries, and a logging failure never fails a call. Two limits: a call the SDK rejects before its handler runs (arguments that fail the schema) is not logged, and while armed the results of search_components, search_examples, list_components and validate_markup are computed a second time for the log, after the answer is sent (an embedding app calls flushLogs() from src/call-log.ts when it stops, as the CLI does; list_components with installedOnly re-reads what is installed then, so an install running during the call can make its logged hits differ). This repository's .mcp.json sets it to lab/.armed/mcp-calls.jsonl (ignored), which lab/scripts/readiness.mjs turns into a lab build report's AI readiness section.

Runs and results. By default a run scores only the components new or modified since the last one (their package outside test/, docs page or gallery, committed or not) and compares each with its last score; --full scores every component, and a change to the scoring itself makes the run full on its own. The registry is rebuilt first. Results are committed in readiness/: baseline.json (the last run, one line per component, with the commit it measured), report.md (the last full run), changes.md (the last changed-only run) and agent.json (the last agent run). --fail-on-regression exits 1 when a scored component lost points; --min <score> when the library score is below it.