模型上下文协议注册API

一个基于Fastify和SQLite的模型上下文协议注册API,用于发布和提供MCP服务器元数据,并符合官方OpenAPI规范。

  • by mpchenette
  • TypeScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 mpchenette/mcp-registry

使用说明

MCP注册API

Fastify+SQLite的实现 模型上下文协议 通用注册表API。
使用它来发布和提供MCP服务器元数据,其响应符合官方OpenAPI规范。

先决条件

  • Node.js 18.19+(建议Azure应用服务使用Node 20.x)
  • npm 9+

入门指南

git clone <this repo>
cd mcp-registry
npm install
cp .env.example .env    # tweak PORT / DATABASE_PATH / REGISTRY_PUBLISH_TOKEN

在本地运行

# optional: load sample data from registry.json
npm run seed

# start the API with live reload
npm run dev

# or build for production and run the compiled server
npm run build
npm start

服务正在监听 http://0.0.0.0:${PORT} (默认值 3000).
/healthz 为就绪探测返回一个简单的状态有效载荷。

核心API表面(v0)

方法和路径 描述
GET /v0/servers 列出服务器(默认为最新版本)。支持 cursor, limit, search, updated_since,以及 version 过滤器。
GET /v0/servers/{serverName}/versions 列出服务器的每个版本(serverName 必须进行URL编码,例如。 io.modelcontextprotocol%2Ffilesystem).
GET /v0/servers/{serverName}/versions/{version} 获取特定版本(version=latest 最新版本)。
POST /v0/publish 发布或更新服务器版本。在以下情况下需要不记名代币 REGISTRY_PUBLISH_TOKEN 已配置。

请求和响应在运行时根据上游OpenAPI模式进行验证(参见 docs/reference/api/openapi.yaml).

示例:发布服务器

curl -X POST http://localhost:3000/v0/publish \
  -H "Authorization: Bearer $REGISTRY_PUBLISH_TOKEN" \
  -H "Content-Type: application/json" \
  --data @samples/filesystem.json

使用 registry.json 当您想一次为多个条目添加种子时(请参见 npm run seed).

示例:服务器页面

curl "http://localhost:3000/v0/servers?limit=20"
# use the metadata.nextCursor value on the next request:
curl "http://localhost:3000/v0/servers?cursor=<nextCursor>"

配置

  • PORT –HTTP端口(默认为 3000)
  • DATABASE_PATH –SQLite数据库文件的位置(./data/registry.sqlite 默认情况下)
  • REGISTRY_PUBLISH_TOKEN –需要不记名代币 POST /v0/publish。保留未设置以使注册表为只读。
  • OPENAPI_SPEC_PATH –如果重新定位OpenAPI文档,则可选覆盖。

启动时读取所有配置(.env 通过支持 dotenv).

部署到Azure应用服务

  1. 登录Azure
az login
  1. 配置变量
cd terraform
cp terraform.tfvars.example terraform.tfvars
Edit terraform.tfvars with your values
  1. 部署基础设施
terraform init
terraform apply
  1. 获取您的API URL
terraform -chdir=terraform output api_url

工具

  • npm run dev –用热加载(tsx)禁食
  • npm run typecheck / npm test –TypeScript编译检查
  • npm run clean –删除 dist 目录
  • npm run seed [file] –从JSON数组加载服务器定义

有用的链接

  • OpenAPI规范: docs/reference/api/openapi.yaml
  • MCP注册API参考:https://github.com/modelcontextprotocol/registry/blob/main/docs/reference/api/generic-registry-api.md

您可以在这个基线之上添加额外的CI/CD和基础设施自动化。