@c2n/mcp

中文文档
1.0.23发布于 2026/11/08MITTypeScriptES Module近 30 天下载 3168

MCP server exposing the c2n web components (API, examples, presets, theme tokens, variant generation) to AI agents

原始使用文档
文档目录5 节
  1. Use
  2. Verify the connection
  3. Tools
  4. Validate from the command line
  5. Development

@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

ToolPurpose
list_componentsEvery component with tag, package, category, description, installed version
search_componentsFree-text search across names, descriptions, attributes, slots, events, examples, icons
get_componentFull API of one component, CSS variables grouped by part/state with their theme token
get_examplesUsage rows and gallery cards; view: "index" lists every look (summary, screenshot)
search_examplesFind a look across every component's gallery ("glass", "pill", "underline")
get_presetsCurated presets as CSS variable values
get_themeThe --c2-theme--* tokens, install/mapping snippets; per-component mapping with tag
generate_variantCSS class / HTML + style / Lit subclass / JSON from overrides, a preset or a gallery card
validate_markupChecks markup/CSS you wrote: native controls to replace, unknown tags/attributes/slots/events/variables
get_workflow_guideworkflow, 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. npm 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.
  • npm run smoke -w packages/tools/mcp spawns the server over stdio and checks every tool.
  • npm run inspect -w packages/tools/mcp opens the MCP Inspector against the source entry (node src/cli.ts, Node 24 type stripping).

版本与发布记录

@c2n/mcp 共发布 42 个版本,首次发布于 2026/09/15;过去 12 个月发布了 42 个版本。

版本发布日期距今
1.0.23latest2026/11/081 天前
1.0.222026/11/072 天前
1.0.212026/11/054 天前
1.0.202026/11/035 天前
1.0.192026/11/035 天前
1.0.182026/10/2811 天前

关于 @c2n/mcp 的常见问题

@c2n/mcp 是什么?

MCP server exposing the c2n web components (API, examples, presets, theme tokens, variant generation) to AI agents

如何安装 @c2n/mcp?

在项目目录运行 npm install @c2n/mcp,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 c2n-mcp,可以用 npx c2n-mcp 直接运行。

@c2n/mcp 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@c2n/mcp 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@c2n/mcp 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@c2n/mcp 可以商用吗?

@c2n/mcp 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@c2n/mcp 的下载量有多少?

根据 npm 官方下载统计,@c2n/mcp 在 2026/10/09 – 2026/11/07 这 30 天内被下载 3,168 次,日均约 106 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@c2n/mcp 还在维护吗?

最新版本 1.0.23 发布于 2026/11/08(1 天前);至今共发布 42 个版本,其中过去 12 个月发布了 42 个;首次发布于 2026/09/15。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。