发布远程服务器

发布远程服务器

社区译文;来源: MCP 80041ab0

MCP Registry 目前处于预览阶段。在正式发布之前,可能发生破坏性变更或数据重置。如果遇到任何问题,请在 GitHub 上报告。

MCP Registry 通过 server.json 中的 remotes 属性支持远程 MCP 服务器:

{
  "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
  "name": "com.example/acme-analytics",
  "title": "ACME Analytics",
  "description": "Real-time business intelligence and reporting platform",
  "version": "2.0.0",
  "remotes": [
    {
      "type": "streamable-http",
      "url": "https://analytics.example.com/mcp"
    }
  ]
}

远程服务器**必须(MUST)**能够通过指定 URL 公开访问。

传输类型

远程服务器应使用可流式 HTTP 传输。SSE 传输已弃用 ,因此只有在需要支持现有客户端时才应发布使用 "sse" 的远程服务器。远程服务器也可以在不同 URL 上同时支持这两种传输。

将 remotes 条目的 type 属性设置为 "streamable-http" 或 "sse" 来指定传输:

{
  "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
  "name": "com.example/acme-analytics",
  "title": "ACME Analytics",
  "description": "Real-time business intelligence and reporting platform",
  "version": "2.0.0",
  "remotes": [
    {
      "type": "streamable-http",
      "url": "https://analytics.example.com/mcp"
    },
    {
      "type": "sse",
      "url": "https://analytics.example.com/sse"
    }
  ]
}

URL 模板变量

远程服务器可以使用 {curly_braces} 表示法定义 URL 模板变量。借助这种方式,单个服务器定义可以通过可配置的值支持多个端点,适用于多租户部署:

{
  "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
  "name": "com.example/acme-analytics",
  "title": "ACME Analytics",
  "description": "Real-time business intelligence and reporting platform",
  "version": "2.0.0",
  "remotes": [
    {
      "type": "streamable-http",
      "url": "https://{tenant_id}.analytics.example.com/mcp",
      "variables": {
        "tenant_id": {
          "description": "Your tenant identifier (e.g., 'us-cell1', 'emea-cell1')",
          "isRequired": true
        }
      }
    }
  ]
}

配置此服务器时,用户提供自己的 tenant_id 值,URL 模板随后会解析为相应端点(例如 https://us-cell1.analytics.example.com/mcp)。

变量还支持 default、choices 和 isSecret 等附加属性:

{
  "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
  "name": "com.example/multi-region-mcp",
  "title": "Multi-Region MCP",
  "description": "MCP server with regional endpoints",
  "version": "1.0.0",
  "remotes": [
    {
      "type": "streamable-http",
      "url": "https://api.example.com/{region}/mcp",
      "variables": {
        "region": {
          "description": "Deployment region",
          "isRequired": true,
          "choices": [
            "us-east-1",
            "eu-west-1",
            "ap-southeast-1"
          ],
          "default": "us-east-1"
        }
      }
    }
  ]
}

HTTP 标头

在 remotes 条目中添加 headers 属性,可以指示 MCP 客户端发送指定的 HTTP 标头:

{
  "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
  "name": "com.example/acme-analytics",
  "title": "ACME Analytics",
  "description": "Real-time business intelligence and reporting platform",
  "version": "2.0.0",
  "remotes": [
    {
      "type": "streamable-http",
      "url": "https://analytics.example.com/mcp",
      "headers": [
        {
          "name": "X-API-Key",
          "description": "API key for authentication",
          "isRequired": true,
          "isSecret": true
        }
      ]
    }
  ]
}

同时支持远程和非远程安装

server.json 中的 remotes 属性可以与 packages 属性共存,让 MCP 主机应用程序选择首选安装方式。

{
  "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
  "name": "io.github.username/email-integration-mcp",
  "title": "Email Integration",
  "description": "Send emails and manage email accounts",
  "version": "1.0.0",
  "remotes": [
    {
      "type": "streamable-http",
      "url": "https://email.example.com/mcp"
    }
  ],
  "packages": [
    {
      "registryType": "npm",
      "identifier": "@example/email-integration-mcp",
      "version": "1.0.0",
      "transport": {
        "type": "stdio"
      }
    }
  ]
}