30秒快速回答: 官方 MCP Registry(
registry.modelcontextprotocol.io)是一个只存元数据、不托管代码的目录。发布分四步:先把可运行包发到 npm / PyPI / NuGet / 容器仓库,再用mcp-publisher init生成server.json,mcp-publisher login github拿到io.github.你的用户名/*命名空间,最后mcp-publisher publish上传清单。核心价值一句话:发一次清单,让所有 MCP 客户端和下游目录都能找到你的 Server。
一、Registry 是什么,以及它不是什么
最常见的误解,是把 Registry 当成应用商店:以为传上去就能被用户一键装走。实际不是这样。Registry 存的是一份 server.json 清单——你的 Server 叫什么、装哪个包、跑什么传输协议、需要哪些环境变量。真正的代码仍然躺在 npm、PyPI、NuGet 或你自己的域名后面。
这个分工决定了发布顺序:先发包,再发清单。npm 上还不存在的包,清单校验必然失败。
| 环节 | 存什么 | 校验什么 | 谁来读 |
|---|---|---|---|
| 包仓库(npm/PyPI) | 代码与可执行入口 | 包名、版本、mcpName | 客户端真正下载运行 |
| MCP Registry | server.json 元数据 | 命名空间身份 + 包所有权 | 客户端搜索、下游目录同步 |
| 你的 README | 使用说明 | 无 | 人类用户 |
Registry 目前仍处于预览阶段,官方明确提示正式版前可能有破坏性变更或数据重置,所以它适合作为「被发现」的渠道,不适合当作唯一的分发依赖。
二、两条路线:packages 还是 remotes
server.json 里二选一,或两者都给:
- packages:面向本地 stdio 运行的 Server,通过包仓库分发。
- remotes:面向已经在公网跑着的远程 Server,只登记一个 URL,跳过打包环节。
一个 npm 分发的本地 Server 清单长这样:
{
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
"name": "io.github.yourname/weather-server",
"title": "Weather Server",
"description": "按城市查询实时天气与未来七天预报。",
"version": "1.0.0",
"repository": { "url": "https://github.com/yourname/weather-server", "source": "github" },
"packages": [
{
"registryType": "npm",
"identifier": "@yourname/weather-server",
"version": "1.0.0",
"transport": { "type": "stdio" },
"environmentVariables": [
{ "name": "WEATHER_API_KEY", "description": "天气服务 API Key", "isRequired": true, "isSecret": true }
]
}
]
}
如果 Server 只提供远程服务,把 packages 换成 remotes 即可,传输类型建议用 streamable-http,sse 已属旧式写法:
"remotes": [{ "type": "streamable-http", "url": "https://mcp.yourdomain.com/v1" }]
三个高频踩坑点:description 上限 100 字符,超了直接校验失败;version 每次发布必须唯一,同一个版本不能重复发布,只想改描述也得升版本号;环境变量只列真正需要的,没有就删掉占位项。
三、命名空间:你在证明自己是谁
name 不是随便起的,它必须是反向域名格式,而且格式由你的登录方式决定。
| 登录方式 | name 格式 | 示例 | 要证明的东西 |
|---|---|---|---|
| GitHub OAuth / OIDC | io.github.用户名/* |
io.github.alice/weather-server |
你就是这个 GitHub 账号 |
| 域名验证 | com.你的域名/* |
com.acme/tool |
你控制这个域名(DNS TXT 或 .well-known) |
个人开发者和开源项目选 GitHub 路线,零配置成本;企业品牌 Server 走域名路线,本身就是一层「官方出品」的背书。
包所有权是另一道校验。npm 包要在 package.json 里写上与服务名一致的 mcpName:
{
"name": "@yourname/weather-server",
"version": "1.0.0",
"mcpName": "io.github.yourname/weather-server"
}
Registry 会去 npm 拉取这个字段,对不上就拒绝发布。PyPI 与 NuGet 走的是另一套约定:在包 README 里写一行 mcp-name: io.github.yourname/weather-server。
四、四步发布:从 init 到 publish
# 1. 安装 CLI(macOS / Linux)
brew install mcp-publisher
# 2. 在项目根目录生成 server.json 模板
mcp-publisher init
# 3. 登录 GitHub,拿到命名空间(会打印 device code)
mcp-publisher login github
# 4. 先干跑自检,再正式发布
mcp-publisher publish --dry-run
mcp-publisher publish
--dry-run 不要省。它会在提交前拦下 schema 错误、命名空间不匹配、版本不一致这三类最常见问题,报错信息也比直接 publish 清晰得多。
发布完成后验一下:
curl "https://registry.modelcontextprotocol.io/v0.1/servers?search=io.github.yourname/weather-server"
凭据默认存在用户目录的 ~/.mcp_publisher_token,部分版本还会在项目内写出 .mcpregistry_github_token 与 .mcpregistry_registry_token——这两个文件必须进 .gitignore,否则一次误提交就把令牌送出去了。
五、CI 自动发布与报错对照
官方支持 GitHub OIDC 认证,意味着流水线里可以不放任何长期密钥,只需给 job 加 id-token: write 权限:
permissions:
contents: read
id-token: write
jobs:
mcp-registry:
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v4
- run: curl -L "https://github.com/modelcontextprotocol/registry/releases/latest/download/mcp-publisher_linux_amd64.tar.gz" | tar xz mcp-publisher
- run: ./mcp-publisher login github-oidc
- run: ./mcp-publisher publish
continue-on-error: true 是刻意的:Registry 还在预览期,不值得让一次目录故障拖垮你的正式发布。注意 OIDC 场景下,你在组织里的成员身份需要设为公开,否则映射不到 io.github.组织名/* 命名空间。
| 报错 | 原因 | 处理 |
|---|---|---|
| Invalid name format | name 不符合命名空间规则 | 改成 io.github.用户名/服务名 |
| Package not found | 包还没发到公共仓库 | 先 npm publish --access public |
| Version mismatch | package.json 与 server.json 版本不一致 | 三处版本对齐 |
| Authentication failed | 令牌过期 | 重新 mcp-publisher login github |
| 描述校验失败 | description 超过 100 字符 | 压到一句话 |
六、总结
- Registry 是清单目录,不是代码仓库,顺序永远是先发包再发清单。
- 本地 Server 用
packages,远程 Server 用remotes,transport 优先streamable-http。 - 命名空间由登录方式决定:GitHub 给
io.github.用户名/*,自有域名给com.域名/*。 - npm 靠
mcpName、PyPI/NuGet 靠 README 的mcp-name行做所有权校验。 - 发布后改任何东西都要升版本号,并且记得把令牌文件加进 .gitignore。
延伸阅读: 还不知道怎么把 Server 写出来,先看本站《什么是 MCP 协议?一文读懂 AI 的 USB 接口标准》与《怎么搭建 MCP Server?从零构建 AI 工具的 USB-C 接口》;企业内网接入看《什么是 MCP Gateway?》;想让 Server 带上可复用技能,读《什么是 Agent Skills?怎么用 SKILL.md 给 AI 搭一套可复用技能库》。