shadcn MCP 服务器 可与任何 shadcn 兼容的注册表开箱即用。你无需采取任何特殊操作即可为你的注册表启用 MCP 支持。
🌐 The shadcn MCP server works out of the box with any shadcn-compatible registry. You do not need to do anything special to enable MCP support for your registry.
先决条件
🌐 Prerequisites
MCP 服务器通过请求你的注册表索引来工作。确保你的注册表根目录下有一个名为 registry 的注册表项文件。
🌐 The MCP server works by requesting your registry index. Make sure you have a registry item file at the root of your registry named registry.
例如,如果你的注册表托管在 https://acme.com/r/[name].json,那么如果你使用的是 JSON 文件扩展名,你应该在 https://acme.com/r/registry.json 或 https://acme.com/r/registry 有一个文件。
🌐 For example, if your registry is hosted at https://acme.com/r/[name].json, you should have a file at https://acme.com/r/registry.json or https://acme.com/r/registry if you're using a JSON file extension.
此文件必须是符合 注册表模式 的有效 JSON 文件。
🌐 This file must be a valid JSON file that conforms to the registry schema.
配置MCP
🌐 Configuring MCP
请让你的注册表使用者在他们的 components.json 文件中配置你的注册表并安装 shadcn MCP 服务器:
🌐 Ask your registry consumers to configure your registry in their components.json file and install the shadcn MCP server:
在你的 components.json 文件中配置你的注册表:
{
"registries": {
"@acme": "https://acme.com/r/{name}.json"
}
}在你的项目中运行以下命令:
pnpm dlx shadcn@latest mcp init --client claude
重启 Claude 代码 并尝试以下提示:
- 显示我在 acme 注册表中的组件
- 使用 acme 注册表中的项目创建一个登录页面
注意: 你可以在 Claude Code 中使用 /mcp 命令来调试 MCP 服务器。
你可以在 MCP 文档 中阅读有关 MCP 服务器的更多信息。
🌐 You can read more about the MCP server in the MCP documentation.
最佳实践
🌐 Best Practices
以下是一些适用于 MCP 兼容注册表的最佳做法:
🌐 Here are some best practices for MCP-compatible registries:
- 清晰描述:添加简明、信息丰富的描述,帮助 AI 助手理解注册表项的用途及使用方法。
- 正确的依赖:准确列出所有
dependencies,以便 MCP 可以自动安装它们。 - 注册表依赖:使用
registryDependencies来表示项目之间的关系。 - 一致命名:对组件名称使用 kebab-case,并在你的注册表中保持一致性。