MCP注册表API服务器
只读API服务器,用于从远程JSON文件提供模型上下文协议(MCP)注册表数据。
概述
此Go服务通过RESTful API下载、验证并提供MCP服务器注册表数据。它定期刷新注册表数据以保持最新状态,而不需要重新部署。
特性
- 从可配置的URL下载注册表JSON
- 根据MCP规范验证数据
- 用于查询服务器和版本的RESTful API
- 定期自动刷新
- 容器编排的健康和准备状态探测
- 平滑关闭
- 结构化JSON日志记录
- 浏览器客户端的CORS支持
配置
所有配置都是通过环境变量完成的:
所需的环境变量
REGISTRY_URL-下载注册表JSON文件的URL
- 例子: https://raw.githubusercontent.com/example/mcp-registry/main/registry.json
REFRESH_INTERVAL-多久刷新一次注册表数据
- 格式:Go持续时间字符串(例如。, 5m, 1h, 30s) - 例子: 5m (每5分钟刷新一次)
可选环境变量
PORT-HTTP服务器端口(默认值:8080)
- 有效范围:1-65535 - 例子: 8080
LOG_LEVEL-日志记录级别(默认值:info)
- 有效值: debug, info, warn, error - 例子: info
API终点
注册表端点
GET /v0.1/servers-列出所有具有分页和筛选功能的服务器
- 查询参数: - cursor -分页光标(整数索引) - limit -每页显示结果(默认值:30,最大值:100) - search -按服务器名称子字符串筛选(不区分大小写) - version -按精确版本匹配进行筛选 - updated_since -按更新时间戳过滤(RFC3339格式) - 答复: ServerListResponse 具有服务器数组和分页元数据
GET /v0.1/servers/{serverName}/versions-获取特定服务器的所有版本
- 退货: ServerListResponse 对于所有版本,按最新版本排序
GET /v0.1/servers/{serverName}/versions/{version}-获取特定版本
- 支持特殊版本 latest 获取最新版本 - 退货: ServerResponse 使用单个服务器对象
健康终点
GET /health-始终返回200 OK{"status": "ok"}
- 用于活性探针
GET /ready-加载注册表时返回200 OK,否则返回503
- 用于准备就绪探头
快速开始
# Build
go build -o mcp-registry-server
# Run
export REGISTRY_URL="https://example.com/registry.json"
export REFRESH_INTERVAL="5m"
./mcp-registry-serverDocker部署
构建Docker镜像
docker build -t mcp-registry-server:latest .使用Docker运行
docker run -d \
--name mcp-registry \
-p 8080:8080 \
-e REGISTRY_URL="https://example.com/registry.json" \
-e REFRESH_INTERVAL="5m" \
-e LOG_LEVEL="info" \
mcp-registry-server:latest检查健康
# Liveness check
curl http://localhost:8080/health
# Readiness check
curl http://localhost:8080/ready
# List servers
curl http://localhost:8080/v0.1/serversAzure容器应用程序部署
创建容器应用程序
az containerapp create \
--name mcp-registry \
--resource-group my-resource-group \
--environment my-environment \
--image myregistry.azurecr.io/mcp-registry-server:latest \
--target-port 8080 \
--ingress external \
--env-vars \
REGISTRY_URL="https://example.com/registry.json" \
REFRESH_INTERVAL="5m" \
LOG_LEVEL="info" \
--cpu 0.5 \
--memory 1.0Gi配置健康探测器
az containerapp update \
--name mcp-registry \
--resource-group my-resource-group \
--set-env-vars \
REGISTRY_URL="https://example.com/registry.json" \
REFRESH_INTERVAL="5m" \
--health-probe-liveness-path="/health" \
--health-probe-readiness-path="/ready"Azure容器实例部署
az container create \
--resource-group my-resource-group \
--name mcp-registry \
--image myregistry.azurecr.io/mcp-registry-server:latest \
--dns-name-label mcp-registry-unique \
--ports 8080 \
--environment-variables \
REGISTRY_URL="https://example.com/registry.json" \
REFRESH_INTERVAL="5m" \
LOG_LEVEL="info" \
--cpu 1 \
--memory 1发展
# Install dependencies
go mod download
# Build
go build
# Run tests
go test ./...
# Run with local development settings
export REGISTRY_URL="https://example.com/registry.json"
export REFRESH_INTERVAL="1m"
export PORT="8080"
export LOG_LEVEL="debug"
go run main.goMCP注册表规范
此服务器实现了MCP注册表规范。有关注册表JSON格式的详细信息,请参阅 MCP注册表文件.
许可证
麻省理工学院
