|
| 1 | +/** |
| 2 | + * Consistency check for the official MCP Registry listing (issue #835). |
| 3 | + * |
| 4 | + * The registry accepts `server.json` only if every package it lists proves ownership at |
| 5 | + * exactly the listed version: the npm package's `mcpName` and the Docker image's |
| 6 | + * `io.modelcontextprotocol.server.name` label must both equal the server name. Those three |
| 7 | + * copies of the name live in three files, and the versions move with every release cut, so |
| 8 | + * this check runs in the release dry-run, in the release job before publishing, and in the |
| 9 | + * unit tests. |
| 10 | + */ |
| 11 | +import fs from 'fs'; |
| 12 | +import path from 'path'; |
| 13 | +import { fileURLToPath } from 'url'; |
| 14 | +import { isMain } from './lib/is-main.mjs'; |
| 15 | + |
| 16 | +/** The registry's schema caps these fields (server.schema.json 2025-12-11). */ |
| 17 | +export const DESCRIPTION_MAX = 100; |
| 18 | +export const TITLE_MAX = 100; |
| 19 | + |
| 20 | +const LABEL = /^LABEL\s+io\.modelcontextprotocol\.server\.name="([^"]+)"\s*$/m; |
| 21 | + |
| 22 | +/** |
| 23 | + * The server name the Dockerfile's label declares, or `null` when there is no label. |
| 24 | + * |
| 25 | + * @param {string} dockerfile |
| 26 | + * @returns {string | null} |
| 27 | + */ |
| 28 | +export function dockerfileServerName(dockerfile) { |
| 29 | + const match = LABEL.exec(dockerfile.replace(/\r\n/g, '\n')); |
| 30 | + return match ? match[1] : null; |
| 31 | +} |
| 32 | + |
| 33 | +/** |
| 34 | + * Every way the three sources disagree with each other or with `version`. |
| 35 | + * |
| 36 | + * @param {{ serverJson: any, cliPackage: any, dockerfile: string, version: string }} input |
| 37 | + * @returns {string[]} problems; empty when the listing is consistent |
| 38 | + */ |
| 39 | +export function checkMcpRegistryMetadata({ serverJson, cliPackage, dockerfile, version }) { |
| 40 | + const problems = []; |
| 41 | + const name = serverJson.name; |
| 42 | + |
| 43 | + if (cliPackage.mcpName !== name) { |
| 44 | + problems.push(`packages/mcp-debugger/package.json mcpName is ${JSON.stringify(cliPackage.mcpName)}, server.json name is ${JSON.stringify(name)}`); |
| 45 | + } |
| 46 | + const label = dockerfileServerName(dockerfile); |
| 47 | + if (label !== name) { |
| 48 | + problems.push(`Dockerfile label io.modelcontextprotocol.server.name is ${JSON.stringify(label)}, server.json name is ${JSON.stringify(name)}`); |
| 49 | + } |
| 50 | + if (typeof serverJson.description !== 'string' || serverJson.description.length > DESCRIPTION_MAX) { |
| 51 | + problems.push(`server.json description must be at most ${DESCRIPTION_MAX} characters`); |
| 52 | + } |
| 53 | + if (serverJson.title !== undefined && serverJson.title.length > TITLE_MAX) { |
| 54 | + problems.push(`server.json title must be at most ${TITLE_MAX} characters`); |
| 55 | + } |
| 56 | + if (serverJson.version !== version) { |
| 57 | + problems.push(`server.json version is ${serverJson.version}, expected ${version}`); |
| 58 | + } |
| 59 | + |
| 60 | + const packages = serverJson.packages ?? []; |
| 61 | + const npm = packages.find(entry => entry.registryType === 'npm'); |
| 62 | + const oci = packages.find(entry => entry.registryType === 'oci'); |
| 63 | + if (!npm) { |
| 64 | + problems.push('server.json lists no npm package'); |
| 65 | + } else { |
| 66 | + if (npm.identifier !== cliPackage.name) { |
| 67 | + problems.push(`server.json npm identifier is ${npm.identifier}, the CLI package is ${cliPackage.name}`); |
| 68 | + } |
| 69 | + if (npm.version !== version) problems.push(`server.json npm version is ${npm.version}, expected ${version}`); |
| 70 | + } |
| 71 | + if (!oci) { |
| 72 | + problems.push('server.json lists no oci package'); |
| 73 | + } else { |
| 74 | + const tag = oci.identifier.slice(oci.identifier.lastIndexOf(':') + 1); |
| 75 | + if (!oci.identifier.startsWith('docker.io/debugmcp/mcp-debugger:')) { |
| 76 | + problems.push(`server.json oci identifier ${oci.identifier} is not docker.io/debugmcp/mcp-debugger:<version>`); |
| 77 | + } else if (tag !== version) { |
| 78 | + problems.push(`server.json oci tag is ${tag}, expected ${version}`); |
| 79 | + } |
| 80 | + } |
| 81 | + return problems; |
| 82 | +} |
| 83 | + |
| 84 | +/** Read the three sources from a checkout. */ |
| 85 | +export function readMcpRegistrySources(root) { |
| 86 | + return { |
| 87 | + serverJson: JSON.parse(fs.readFileSync(path.join(root, 'server.json'), 'utf8')), |
| 88 | + cliPackage: JSON.parse(fs.readFileSync(path.join(root, 'packages', 'mcp-debugger', 'package.json'), 'utf8')), |
| 89 | + dockerfile: fs.readFileSync(path.join(root, 'Dockerfile'), 'utf8'), |
| 90 | + rootVersion: JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8')).version |
| 91 | + }; |
| 92 | +} |
| 93 | + |
| 94 | +if (isMain(import.meta.url)) { |
| 95 | + const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); |
| 96 | + const versionFlag = process.argv.indexOf('--version'); |
| 97 | + try { |
| 98 | + const sources = readMcpRegistrySources(root); |
| 99 | + const version = versionFlag !== -1 ? process.argv[versionFlag + 1] : sources.rootVersion; |
| 100 | + if (!version) throw new Error('Usage: node scripts/check-mcp-registry-metadata.mjs [--version <x.y.z>]'); |
| 101 | + const problems = checkMcpRegistryMetadata({ ...sources, version }); |
| 102 | + if (problems.length > 0) { |
| 103 | + console.error(`MCP Registry metadata is inconsistent for ${version}:`); |
| 104 | + for (const problem of problems) console.error(` - ${problem}`); |
| 105 | + console.error('Run scripts/sync-versions.cjs to move server.json with the release.'); |
| 106 | + process.exit(1); |
| 107 | + } |
| 108 | + console.log(`MCP Registry metadata consistent: ${sources.serverJson.name} at ${version}`); |
| 109 | + } catch (error) { |
| 110 | + console.error(error instanceof Error ? error.message : String(error)); |
| 111 | + process.exit(1); |
| 112 | + } |
| 113 | +} |
0 commit comments