Skip to main content
MCP 注册表目前处于预览阶段。正式可用前可能发生破坏性变更或数据重置。如果遇到问题,请在 GitHub 上反馈。
本教程将演示如何使用官方 mcp-publisher CLI 工具,将用 TypeScript 编写的 MCP 服务器发布到 MCP 注册表。

前置条件

  • Node.js — 本教程假定 MCP 服务器使用 TypeScript 编写。
  • npm 账号 — MCP 注册表只托管元数据,不托管构件。在发布到 MCP 注册表前,我们会先将 MCP 服务器包发布到 npm,因此你需要一个 npm 账号。
  • GitHub 账号 — MCP 注册表支持多种认证方式。为简化流程,本教程会使用基于 GitHub 的认证,因此你需要一个 GitHub 账号。
如果你还没有用 TypeScript 编写的 MCP 服务器,可以从 modelcontextprotocol/quickstart-resources 仓库复制 weather-server-typescript 服务器,跟随本教程操作:
git clone --depth 1 git@github.com:modelcontextprotocol/quickstart-resources.git
cp -r quickstart-resources/weather-server-typescript .
rm -rf quickstart-resources
cd weather-server-typescript
然后编辑 package.json,替换为你自己的信息:
package.json
 {
-  "name": "mcp-quickstart-ts",
-  "version": "1.0.0",
+  "name": "@my-username/mcp-weather-server",
+  "version": "1.0.1",
   "main": "index.js",
package.json
   "license": "ISC",
-  "description": "",
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/my-username/mcp-weather-server.git"
+  },
+  "description": "An MCP server for weather information.",
   "devDependencies": {

第 1 步:向包中添加验证信息

MCP 注册表会验证服务器底层包是否与其元数据匹配。对于 npm 包,需要在 package.json 中添加 mcpName 属性:
package.json
 {
   "name": "@my-username/mcp-weather-server",
   "version": "1.0.1",
+  "mcpName": "io.github.my-username/weather",
   "main": "index.js",
mcpName 的值将作为该服务器在 MCP 注册表中的名称。 由于本教程会使用基于 GitHub 的认证,mcpName 必须io.github.my-username/ 开头。

第 2 步:发布包

MCP 注册表只托管元数据,不托管构件,因此必须先将包发布到 npm,再将服务器发布到 MCP 注册表。 确保已构建分发文件:
# 进入项目目录
cd weather-server-typescript

# 安装依赖
npm install

# 构建分发文件
npm run build
然后按照 npm 的发布指南操作。通常需要运行以下命令:
# 如有需要,登录 npm
npm adduser

# 发布包
npm publish --access public
可以访问该包的 npm URL 来确认发布成功,例如 https://www.npmjs.com/package/@my-username/mcp-weather-server。

第 3 步:安装 mcp-publisher

使用预构建二进制文件或 Homebrew 安装 mcp-publisher CLI 工具:
curl -L "https://github.com/modelcontextprotocol/registry/releases/latest/download/mcp-publisher_$(uname -s | tr '[:upper:]' '[:lower:]')_$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/').tar.gz" | tar xz mcp-publisher && sudo mv mcp-publisher /usr/local/bin/
运行以下命令确认 mcp-publisher 已正确安装:
mcp-publisher --help
你应该会看到类似输出:
Output
MCP Registry Publisher Tool

Usage:
  mcp-publisher <command> [arguments]

Commands:
  init          Create a server.json file template
  login         Authenticate with the registry
  logout        Clear saved authentication
  publish       Publish server.json to the registry

第 4 步:创建 server.json

mcp-publisher init 命令可以生成一个 server.json 模板文件,其中包含从项目中推导出的一些信息。 在服务器项目目录中运行 mcp-publisher init
mcp-publisher init
打开生成的 server.json 文件,你应该会看到类似内容:
server.json
{
  "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
  "name": "io.github.my-username/weather",
  "description": "An MCP server for weather information.",
  "repository": {
    "url": "https://github.com/my-username/mcp-weather-server",
    "source": "github"
  },
  "version": "1.0.0",
  "packages": [
    {
      "registryType": "npm",
      "identifier": "@my-username/mcp-weather-server",
      "version": "1.0.0",
      "transport": {
        "type": "stdio"
      },
      "environmentVariables": [
        {
          "description": "Your API key for the service",
          "isRequired": true,
          "format": "string",
          "isSecret": true,
          "name": "YOUR_API_KEY"
        }
      ]
    }
  ]
}
按需编辑其中内容:
server.json
 {
   "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
   "name": "io.github.my-username/weather",
   "description": "An MCP server for weather information.",
   "repository": {
     "url": "https://github.com/my-username/mcp-weather-server",
     "source": "github"
   },
-  "version": "1.0.0",
+  "version": "1.0.1",
   "packages": [
     {
       "registryType": "npm",
       "identifier": "@my-username/mcp-weather-server",
-      "version": "1.0.0",
+      "version": "1.0.1",
       "transport": {
         "type": "stdio"
-      },
-      "environmentVariables": [
-        {
-          "description": "Your API key for the service",
-          "isRequired": true,
-          "format": "string",
-          "isSecret": true,
-          "name": "YOUR_API_KEY"
-        }
-      ]
+      }
     }
   ]
 }
server.json 中的 name 属性必须package.json 中的 mcpName 属性一致。

第 5 步:向 MCP 注册表认证

本教程会使用基于 GitHub 的认证方式向 MCP 注册表认证。 运行 mcp-publisher login 命令发起认证:
mcp-publisher login github
你应该会看到类似输出:
Output
Logging in with github...

To authenticate, please:
1. Go to: https://github.com/login/device
2. Enter code: ABCD-1234
3. Authorize this application
Waiting for authorization...
访问该链接,按提示操作,并输入终端中打印的授权码(例如上方输出中的 ABCD-1234)。完成后回到终端,你应该会看到类似输出:
Output
Successfully authenticated!
✓ Successfully logged in

第 6 步:发布到 MCP 注册表

最后,使用 mcp-publisher publish 命令将服务器发布到 MCP 注册表:
mcp-publisher publish
你应该会看到类似输出:
Output
Publishing to https://registry.modelcontextprotocol.io...
✓ Successfully published
✓ Server io.github.my-username/weather version 1.0.1
可以使用 MCP 注册表 API 搜索该服务器,确认它已发布:
curl "https://registry.modelcontextprotocol.io/v0.1/servers?search=io.github.my-username/weather"
你应该会在搜索结果 JSON 中看到服务器元数据:
Output
{"servers":[{ ... "name":"io.github.my-username/weather" ... }]}

排障

错误消息处理方式
”Registry validation failed for package”确认你的包包含所需的验证信息(例如 package.json 中的 mcpName 属性)。
“Invalid or expired Registry JWT token”运行 mcp-publisher login github 重新认证。
“You do not have permission to publish this server”你的认证方式与服务器命名空间格式不匹配。使用 GitHub 认证时,服务器名称必须以 io.github.your-username/ 开头。

后续步骤