将 MCP 服务器发布到官方注册表

January 11, 2026

这篇指南介绍如何将 MCP(Model Context Protocol,模型上下文协议)服务器发布到官方 MCP Registry。注册表存储服务器的元数据,让 Claude Desktop 等 AI 客户端可以发现它们。

准备工作

  • Node.js:用于 TypeScript/JavaScript 实现的 MCP 服务器。
  • npm 账号:注册表只存元数据,必须先把包发布到 npm。
  • GitHub 账号:用于向注册表验证身份。

第一步:在 package.json 中添加验证信息

MCP Registry 需要通过 package.json 中的 mcpName 属性验证所有权:

{
  "name": "your-mcp-server",
  "version": "1.0.0",
  "mcpName": "io.github.YourUsername/your-server-name",
  ...
}

注意: mcpName 中的 GitHub 用户名必须与实际用户名完全一致,包括大小写。如果用户名是 S2thend,就应写成 io.github.S2thend/;io.github.s2thend/ 的大小写不符。

第二步:创建 server.json

在项目根目录创建 server.json,填写 MCP Registry 的元数据:

{
  "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
  "name": "io.github.YourUsername/your-server-name",
  "description": "Description of your MCP server",
  "repository": {
    "url": "https://github.com/YourUsername/your-repo",
    "source": "github"
  },
  "version": "1.0.0",
  "packages": [
    {
      "registryType": "npm",
      "identifier": "your-mcp-server",
      "version": "1.0.0",
      "transport": {
        "type": "stdio"
      }
    }
  ]
}

常见错误

错误原因处理方法
cannot unmarshal string into Go struct field ServerJSON.repositoryrepository 写成了字符串,要求的是对象使用对象格式 {"url": "...", "source": "github"}
cannot unmarshal object into Go struct field ServerJSON.packagespackages 写成了对象,要求的是数组使用数组格式 "packages": [{ ... }]
You do not have permission to publish this server用户名大小写不一致与 GitHub 用户名的大小写完全一致,例如写 S2thend,而非 s2thend

第三步:先发布到 npm

MCP Registry 只存元数据,包本身必须已经存在于 npm:

npm install
npm run build
npm publish --access public

第四步:安装 mcp-publisher 命令行工具

macOS/Linux

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/

使用 Homebrew

brew install mcp-publisher

第五步:登录并发布

# Authenticate with GitHub
mcp-publisher login github

# Follow the device code flow in your browser
# Then publish
mcp-publisher publish

用 GitHub Actions 自动发布

把发布到 MCP Registry 的步骤添加到 CI/CD 流程中:

name: Publish to npm and MCP Registry

on:
  release:
    types: [published]

jobs:
  publish:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      id-token: write  # Required for OIDC authentication

    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: 'lts/*'
          registry-url: 'https://registry.npmjs.org'

      - name: Install dependencies
        run: npm ci

      - name: Run tests
        run: npm run test --if-present

      - name: Build
        run: npm run build --if-present

      - name: Publish to npm
        run: npm publish --provenance --access public
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

      # Publish to MCP Registry
      - name: Install mcp-publisher
        run: |
          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

      - name: Authenticate to MCP Registry
        run: ./mcp-publisher login github-oidc

      - name: Set version in server.json
        run: |
          VERSION=${GITHUB_REF#refs/tags/v}
          jq --arg v "$VERSION" '.version = $v | .packages[0].version = $v' server.json > server.tmp && mv server.tmp server.json

      - name: Publish to MCP Registry
        run: ./mcp-publisher publish

GitHub Actions 配置要点

  1. OIDC 认证:在 CI 中使用 github-oidc,本地才用 github。CI 需要 id-token: write 权限。
  2. 同步版本:用 jq 从 Git 标签更新 .version 和 .packages[0].version 两处。
  3. 先发布 npm 包:MCP Registry 在接受元数据前会验证 npm 包已经存在。

故障排查

报错 403 Forbidden:You do not have permission

You have permission to publish: io.github.S2thend/*.
Attempting to publish: io.github.s2thend/cursor-history.

处理方法: MCP 名称中的 GitHub 用户名区分大小写。核对实际用户名,每个字母的大小写都要一致。

报错 cannot unmarshal string/object

server.json 的结构有严格要求:

  • repository 必须是带 url 和 source 字段的对象。
  • packages 必须是由包对象组成的数组。
  • 每个包都需要 registryType、identifier、version 和 transport。

报错 403:Cannot publish over previously published versions

这个版本已经发到了 npm。先增加版本号:

npm version patch  # or minor/major

然后同步更新 package.json 和 server.json。

验证

发布后,检查注册表能否查到你的服务器:

curl "https://registry.modelcontextprotocol.io/v0.1/servers?search=io.github.YourUsername/your-server"

发布清单

  • 在 package.json 中添加 mcpName,其中 GitHub 用户名的大小写须完全一致。
  • 按要求创建 server.json,把 repository 写成对象,把 packages 写成数组。
  • 先发到 npm。
  • 本地使用 mcp-publisher login github,CI 使用 github-oidc。
  • 运行 mcp-publisher publish。

参考资料

  1. Model Context Protocol. (n.d.). Quickstart: Publishing an MCP Server. GitHub。查阅于 2026 年 1 月 11 日。https://github.com/modelcontextprotocol/registry/blob/main/docs/modelcontextprotocol-io/quickstart.mdx

  2. Model Context Protocol. (n.d.). How to Automate Publishing with GitHub Actions. GitHub。查阅于 2026 年 1 月 11 日。https://github.com/modelcontextprotocol/registry/blob/main/docs/modelcontextprotocol-io/github-actions.mdx

  3. Model Context Protocol. (n.d.). MCP Registry Publisher CLI. GitHub。查阅于 2026 年 1 月 11 日。https://github.com/modelcontextprotocol/registry

  4. Model Context Protocol. (n.d.). Server.json Schema (2025-12-11)。查阅于 2026 年 1 月 11 日。https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json

© 2026 borui. All rights reserved. This content may be freely reproduced, displayed, modified, or distributed with proper attribution to borui and a link to the article: borui (2026-01-11). 将 MCP 服务器发布到官方注册表. https://caiborui.com/blog/2026-01-11-en-publish-mcp-server-to-registry-zhtrans

@misc{borui2026-b898ce92,
  author = {borui},
  title = {{将 MCP 服务器发布到官方注册表}},
  year = {2026},
  publisher = {borui's blog},
  url = {https://caiborui.com/blog/2026-01-11-en-publish-mcp-server-to-registry-zhtrans}
}