diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ce8f26762..48e5111c4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,6 +29,15 @@ jobs: with: version: v2.11.4 + # Node is required by `make validate`: the server.json JSON Schema is + # generated from docs/reference/server-json/schema.ts and checked for drift. + - name: Set up Node.js + uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af + with: + node-version: '22' + cache: 'npm' + cache-dependency-path: docs/reference/server-json/package-lock.json + - name: Validate schemas and examples run: make validate diff --git a/Makefile b/Makefile index 3cad6918d..728dec2e8 100644 --- a/Makefile +++ b/Makefile @@ -18,15 +18,13 @@ publisher: ## Build the publisher tool with version info go build -ldflags="-X main.Version=dev-$(shell git rev-parse --short HEAD) -X main.GitCommit=$(shell git rev-parse HEAD) -X main.BuildTime=$(shell date -u +%Y-%m-%dT%H:%M:%SZ)" -o bin/mcp-publisher ./cmd/publisher # Schema generation targets -generate-schema: ## Generate server.schema.json from openapi.yaml - @mkdir -p bin - go build -o bin/extract-server-schema ./tools/extract-server-schema - @./bin/extract-server-schema +SCHEMA_DIR := docs/reference/server-json -check-schema: ## Check if server.schema.json is in sync with openapi.yaml - @mkdir -p bin - go build -o bin/extract-server-schema ./tools/extract-server-schema - @./bin/extract-server-schema -check +generate-schema: ## Generate server.schema.json from schema.ts (TypeScript source of truth) + cd $(SCHEMA_DIR) && npm ci && npm run generate + +check-schema: ## Check server.schema.json + openapi.yaml are in sync with schema.ts + cd $(SCHEMA_DIR) && npm ci && npm run check && npm run validate # Test targets test-unit: ## Run unit tests with coverage (requires PostgreSQL) diff --git a/docs/reference/api/openapi.yaml b/docs/reference/api/openapi.yaml index 61cae2da7..ac75373f1 100644 --- a/docs/reference/api/openapi.yaml +++ b/docs/reference/api/openapi.yaml @@ -604,29 +604,7 @@ components: Some registries may use JWT tokens, others may use API keys or OAuth. Consult your specific registry's authentication documentation. schemas: Repository: - type: object - description: "Repository metadata for the MCP server source code. Enables users and security experts to inspect the code, improving transparency." - required: - - url - - source - properties: - url: - type: string - format: uri - description: "Repository URL for browsing source code. Should support both web browsing and git clone operations." - example: "https://github.com/modelcontextprotocol/servers" - source: - type: string - description: "Repository hosting service identifier. Used by registries to determine validation and API access methods." - example: "github" - id: - type: string - description: "Repository identifier from the hosting service (e.g., GitHub repo ID). Owned and determined by the source forge. Should remain stable across repository renames and may be used to detect repository resurrection attacks - if a repository is deleted and recreated, the ID should change. For GitHub, use: gh api repos// --jq '.id'" - example: "b94b5f7e-c7c6-d760-2c78-a5e9b8a5b8c9" - subfolder: - type: string - description: "Optional relative path from repository root to the server location within a monorepo or nested package structure. Must be a clean relative path." - example: "src/everything" + $ref: '../server-json/draft/server.schema.json#/definitions/Repository' ServerList: type: object @@ -651,370 +629,46 @@ components: example: 30 Package: - type: object - required: - - registryType - - identifier - - transport - properties: - registryType: - type: string - description: Registry type indicating how to download packages (e.g., 'npm', 'pypi', 'cargo', 'oci', 'nuget', 'mcpb') - examples: - - "npm" - - "pypi" - - "cargo" - - "oci" - - "nuget" - - "mcpb" - registryBaseUrl: - type: string - format: uri - description: Base URL of the package registry - examples: - - "https://registry.npmjs.org" - - "https://pypi.org" - - "https://crates.io" - - "https://docker.io" - - "https://api.nuget.org/v3/index.json" - - "https://github.com" - - "https://gitlab.com" - identifier: - type: string - description: Package identifier - either a package name (for registries) or URL (for direct downloads) - examples: - - "@modelcontextprotocol/server-brave-search" - - "https://github.com/example/releases/download/v1.0.0/package.mcpb" - version: - type: string - description: "Package version. Must be a specific version. Version ranges are rejected (e.g., '^1.2.3', '~1.2.3', '>=1.2.3', '1.x', '1.*')." - example: "1.0.2" - minLength: 1 - maxLength: 255 - not: - const: "latest" - fileSha256: - type: string - description: "SHA-256 hash of the package file for integrity verification. Required for MCPB packages and optional for other package types. Authors are responsible for generating correct SHA-256 hashes when creating server.json. If present, MCP clients must validate the downloaded file matches the hash before running packages to ensure file integrity." - example: "fe333e598595000ae021bd27117db32ec69af6987f507ba7a63c90638ff633ce" - pattern: "^[a-f0-9]{64}$" - runtimeHint: - type: string - description: A hint to help clients determine the appropriate runtime for the package. This field should be provided when `runtimeArguments` are present. - examples: [npx, uvx, docker, dnx] - transport: - $ref: '#/components/schemas/LocalTransport' - description: Transport protocol configuration for the package - runtimeArguments: - type: array - description: A list of arguments to be passed to the package's runtime command (such as docker or npx). The `runtimeHint` field should be provided when `runtimeArguments` are present. - items: - $ref: '#/components/schemas/Argument' - packageArguments: - type: array - description: A list of arguments to be passed to the package's binary. - items: - $ref: '#/components/schemas/Argument' - environmentVariables: - type: array - description: A mapping of environment variables to be set when running the package. - items: - $ref: '#/components/schemas/KeyValueInput' + $ref: '../server-json/draft/server.schema.json#/definitions/Package' Input: - type: object - properties: - description: - description: A description of the input, which clients can use to provide context to the user. - type: string - isRequired: - type: boolean - default: false - format: - type: string - description: "Specifies the input format. Supported values include `filepath`, which should be interpreted as a file on the user's filesystem.\n\nWhen the input is converted to a string, booleans should be represented by the strings \"true\" and \"false\", and numbers should be represented as decimal values." - enum: [string, number, boolean, filepath] - default: string - value: - type: string - description: | - The value for the input. If this is not set, the user may be prompted to provide a value. If a value is set, it should not be configurable by end users. - - Identifiers wrapped in `{curly_braces}` will be replaced with the corresponding properties from the input `variables` map. If an identifier in braces is not found in `variables`, or if `variables` is not provided, the `{curly_braces}` substring should remain unchanged. - isSecret: - type: boolean - description: Indicates whether the input is a secret value (e.g., password, token). If true, clients should handle the value securely. - default: false - default: - type: string - description: "The default value for the input. This should be a valid value for the input. If you want to provide input examples or guidance, use the `placeholder` field instead." - placeholder: - type: string - description: "A placeholder for the input to be displaying during configuration. This is used to provide examples or guidance about the expected form or content of the input." - choices: - type: array - description: A list of possible values for the input. If provided, the user must select one of these values. - items: - type: string - example: [] + $ref: '../server-json/draft/server.schema.json#/definitions/Input' InputWithVariables: - allOf: - - $ref: '#/components/schemas/Input' - - type: object - properties: - variables: - type: object - description: A map of variable names to their values. Keys in the input `value` that are wrapped in `{curly_braces}` will be replaced with the corresponding variable values. - additionalProperties: - $ref: '#/components/schemas/Input' + $ref: '../server-json/draft/server.schema.json#/definitions/InputWithVariables' PositionalArgument: - description: A positional input is a value inserted verbatim into the command line. - allOf: - - $ref: '#/components/schemas/InputWithVariables' - - type: object - required: - - type - properties: - type: - type: string - enum: [positional] - example: "positional" - valueHint: - type: string - description: "An identifier for the positional argument. It is not part of the command line. It may be used by client configuration as a label identifying the argument. It is also used to identify the value in transport URL variable substitution." - example: file_path - isRepeated: - type: boolean - description: Whether the argument can be repeated multiple times in the command line. - default: false - anyOf: - - required: - - valueHint - - required: - - value + $ref: '../server-json/draft/server.schema.json#/definitions/PositionalArgument' NamedArgument: - description: A command-line `--flag={value}`. - allOf: - - $ref: '#/components/schemas/InputWithVariables' - - type: object - required: - - type - - name - properties: - type: - type: string - enum: [named] - example: "named" - name: - type: string - description: The flag name, including any leading dashes. - example: "--port" - isRepeated: - type: boolean - description: Whether the argument can be repeated multiple times. - default: false + $ref: '../server-json/draft/server.schema.json#/definitions/NamedArgument' KeyValueInput: - allOf: - - $ref: '#/components/schemas/InputWithVariables' - - type: object - required: - - name - properties: - name: - type: string - description: Name of the header or environment variable. - example: SOME_VARIABLE + $ref: '../server-json/draft/server.schema.json#/definitions/KeyValueInput' Argument: - description: "Warning: Arguments construct command-line parameters that may contain user-provided input. This creates potential command injection risks if clients execute commands in a shell environment. For example, a malicious argument value like ';rm -rf ~/Development' could execute dangerous commands. Clients should prefer non-shell execution methods (e.g., posix_spawn) when possible to eliminate injection risks entirely. Where not possible, clients should obtain consent from users or agents to run the resolved command before execution." - anyOf: - - $ref: '#/components/schemas/PositionalArgument' - - $ref: '#/components/schemas/NamedArgument' + $ref: '../server-json/draft/server.schema.json#/definitions/Argument' StdioTransport: - type: object - required: - - type - properties: - type: - type: string - enum: [stdio] - description: Transport type - example: "stdio" + $ref: '../server-json/draft/server.schema.json#/definitions/StdioTransport' StreamableHttpTransport: - type: object - required: - - type - - url - properties: - type: - type: string - enum: [streamable-http] - description: Transport type - example: "streamable-http" - url: - type: string - description: "URL template for the streamable-http transport. Must start with http://, https://, or a template variable (e.g., {baseUrl}). Variables in {curly_braces} are resolved based on context: In Package context, they reference argument valueHints, argument names, or environment variable names from the parent Package. In Remote context, they reference variables from the transport's 'variables' object. After variable substitution, this should produce a valid URI." - example: "https://api.example.com/mcp" - pattern: "^(https?://[^\\s]+|\\{[a-zA-Z_][a-zA-Z0-9_]*\\}[^\\s]*)$" - headers: - type: array - description: HTTP headers to include - items: - $ref: '#/components/schemas/KeyValueInput' + $ref: '../server-json/draft/server.schema.json#/definitions/StreamableHttpTransport' SseTransport: - type: object - required: - - type - - url - properties: - type: - type: string - enum: [sse] - description: Transport type - example: "sse" - url: - type: string - description: "Server-Sent Events endpoint URL template. Must start with http://, https://, or a template variable (e.g., {baseUrl}). Variables in {curly_braces} are resolved based on context: In Package context, they reference argument valueHints, argument names, or environment variable names from the parent Package. In Remote context, they reference variables from the transport's 'variables' object. After variable substitution, this should produce a valid URI." - example: "https://mcp-fs.example.com/sse" - pattern: "^(https?://[^\\s]+|\\{[a-zA-Z_][a-zA-Z0-9_]*\\}[^\\s]*)$" - headers: - type: array - description: HTTP headers to include - items: - $ref: '#/components/schemas/KeyValueInput' + $ref: '../server-json/draft/server.schema.json#/definitions/SseTransport' LocalTransport: - anyOf: - - $ref: '#/components/schemas/StdioTransport' - - $ref: '#/components/schemas/StreamableHttpTransport' - - $ref: '#/components/schemas/SseTransport' - description: Transport protocol configuration for local/package context + $ref: '../server-json/draft/server.schema.json#/definitions/LocalTransport' RemoteTransport: - allOf: - - anyOf: - - $ref: '#/components/schemas/StreamableHttpTransport' - - $ref: '#/components/schemas/SseTransport' - - type: object - properties: - variables: - type: object - description: "Configuration variables that can be referenced in URL template {curly_braces}. The key is the variable name, and the value defines the variable properties." - additionalProperties: - $ref: '#/components/schemas/Input' - description: Transport protocol configuration for remote context - extends StreamableHttpTransport or SseTransport with variables + $ref: '../server-json/draft/server.schema.json#/definitions/RemoteTransport' Icon: - type: object - description: An optionally-sized icon that can be displayed in a user interface. - required: - - src - properties: - src: - type: string - format: uri - description: "A standard URI pointing to an icon resource. Must be an HTTPS URL. Consumers SHOULD take steps to ensure URLs serving icons are from the same domain as the server or a trusted domain. Consumers SHOULD take appropriate precautions when consuming SVGs as they can contain executable JavaScript." - example: "https://example.com/icon.png" - maxLength: 255 - mimeType: - type: string - description: "Optional MIME type override if the source MIME type is missing or generic. Must be one of: image/png, image/jpeg, image/jpg, image/svg+xml, image/webp." - enum: [image/png, image/jpeg, image/jpg, image/svg+xml, image/webp] - example: "image/png" - sizes: - type: array - description: "Optional array of strings that specify sizes at which the icon can be used. Each string should be in WxH format (e.g., '48x48', '96x96') or 'any' for scalable formats like SVG. If not provided, the client should assume that the icon can be used at any size." - items: - type: string - pattern: "^(\\d+x\\d+|any)$" - examples: - - ["48x48", "96x96"] - - ["any"] - theme: - type: string - description: "Optional specifier for the theme this icon is designed for. 'light' indicates the icon is designed to be used with a light background, and 'dark' indicates the icon is designed to be used with a dark background. If not provided, the client should assume the icon can be used with any theme." - enum: [light, dark] + $ref: '../server-json/draft/server.schema.json#/definitions/Icon' ServerDetail: - description: Schema for a static representation of an MCP server. Used in various contexts related to discovery, installation, and configuration. - type: object - required: - - name - - description - - version - properties: - name: - type: string - description: "Server name in reverse-DNS format. Must contain exactly one forward slash separating namespace from server name." - example: "io.github.user/weather" - minLength: 3 - maxLength: 200 - pattern: "^[a-zA-Z0-9.-]+/[a-zA-Z0-9._-]+$" - description: - type: string - description: "Clear human-readable explanation of server functionality. Should focus on capabilities, not implementation details." - example: "MCP server providing weather data and forecasts via OpenWeatherMap API" - minLength: 1 - maxLength: 100 - title: - type: string - description: "Optional human-readable title or display name for the MCP server. MCP subregistries or clients MAY choose to use this for display purposes." - example: "Weather API" - minLength: 1 - maxLength: 100 - repository: - $ref: '#/components/schemas/Repository' - description: "Optional repository metadata for the MCP server source code. Recommended for transparency and security inspection." - version: - type: string - example: "1.0.2" - description: "Version string for this server. SHOULD follow semantic versioning (e.g., '1.0.2', '2.1.0-alpha'). Equivalent of Implementation.version in MCP specification. Non-semantic versions are allowed but may not sort predictably. Version ranges are rejected (e.g., '^1.2.3', '~1.2.3', '>=1.2.3', '1.x', '1.*')." - maxLength: 255 - websiteUrl: - type: string - format: uri - description: "Optional URL to the server's homepage, documentation, or project website. This provides a central link for users to learn more about the server. Particularly useful when the server has custom installation instructions or setup requirements." - example: "https://modelcontextprotocol.io/examples" - icons: - type: array - description: "Optional set of sized icons that the client can display in a user interface. Clients that support rendering icons MUST support at least the following MIME types: image/png and image/jpeg (safe, universal compatibility). Clients SHOULD also support: image/svg+xml (scalable but requires security precautions) and image/webp (modern, efficient format)." - items: - $ref: '#/components/schemas/Icon' - $schema: - type: string - format: uri - description: JSON Schema URI for this server.json format - example: "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json" - packages: - type: array - items: - $ref: '#/components/schemas/Package' - remotes: - type: array - items: - $ref: '#/components/schemas/RemoteTransport' - _meta: - type: object - description: "Extension metadata using reverse DNS namespacing for vendor-specific data" - properties: - io.modelcontextprotocol.registry/publisher-provided: - type: object - description: "Publisher-provided metadata for downstream registries" - additionalProperties: true - example: - tool: "publisher-cli" - version: "1.2.3" - buildInfo: - commit: "abc123def456" - timestamp: "2023-12-01T10:30:00Z" - pipelineId: "build-789" + $ref: '../server-json/draft/server.schema.json#/definitions/ServerDetail' ServerResponse: description: API response format with separated server data and registry metadata diff --git a/docs/reference/server-json/.gitignore b/docs/reference/server-json/.gitignore new file mode 100644 index 000000000..c2658d7d1 --- /dev/null +++ b/docs/reference/server-json/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/docs/reference/server-json/CONTRIBUTING.md b/docs/reference/server-json/CONTRIBUTING.md index 802cc2ce3..5a91ee11a 100644 --- a/docs/reference/server-json/CONTRIBUTING.md +++ b/docs/reference/server-json/CONTRIBUTING.md @@ -4,13 +4,50 @@ This document describes the process for making and releasing changes to the `ser ## Making Changes -1. **Modify the OpenAPI spec**: Edit `docs/reference/api/openapi.yaml` with your schema changes. The `ServerDetail` component defines the server.json structure. +The schema has a single source of truth: [`schema.ts`](./schema.ts). The committed +artifact [`draft/server.schema.json`](./draft/server.schema.json) is generated from it +and must not be edited by hand. -2. **Regenerate the schema**: Run `make generate-schema` to update `server.schema.json` from the OpenAPI spec. +1. **Edit the source of truth**: Modify [`schema.ts`](./schema.ts) with your schema changes. -3. **Update the changelog**: Add your changes to the "Draft (Unreleased)" section in `CHANGELOG.md`. +2. **Regenerate the schema**: Run `make generate-schema` (or, from this directory, + `npm run generate`) to update `draft/server.schema.json` from `schema.ts`. -4. **Open a PR**: Submit a pull request to this repository for review. +3. **OpenAPI references the schema automatically**: `docs/reference/api/openapi.yaml` + no longer duplicates these definitions — its `components/schemas` exposes each + server.json type as an external `$ref` into the generated `draft/server.schema.json`. + You do **not** need to edit `openapi.yaml` for an ordinary schema change. The only + time it needs a manual edit is when you **add or remove a top-level definition** in + `schema.ts`: add (or delete) the matching one-line `$ref` stub under + `components/schemas`. `npm run check` enforces that every definition has a stub and + every stub targets a real definition. Because the stubs are relative-path `$ref`s + into `draft/server.schema.json`, the reference `openapi.yaml` now needs the repo + checkout alongside it to fully resolve; the self-contained spec that subregistries + consume is the runtime-served one at `registry.modelcontextprotocol.io/openapi.yaml` + (generated independently from the Go types), which is unaffected. + +4. **Add or update examples**: Example documents under [`examples/`](./examples) are + validated against the generated schema. `examples/valid/` must validate cleanly and + `examples/invalid/` must fail at least one constraint. Run `npm run validate` (or + `make validate`) to check. + +5. **Update the changelog**: Add your changes to the "Draft (Unreleased)" section in `CHANGELOG.md`. + +6. **Open a PR**: Submit a pull request to this repository for review. + +### Local tooling + +From this directory (`docs/reference/server-json/`): + +```bash +npm ci # install dev dependencies (tsx, typescript, ajv, yaml) +npm run generate # regenerate draft/server.schema.json from schema.ts +npm run check # schema up to date + openapi $ref stubs in sync + type-check schema.ts +npm run validate # validate examples/ against the generated schema +``` + +The generated JSON deliberately reproduces the previous Go (`encoding/json`) output +byte-for-byte, so the schema *content* is unchanged by this pipeline. ## Releasing Changes @@ -18,7 +55,7 @@ When the draft changes are ready for release: 1. **Update the changelog**: Move changes from "Draft (Unreleased)" to a new dated section (e.g., `## 2025-XX-XX`). -2. **Update the schema URL**: Change the `$id` in the schema and the example URL in `openapi.yaml` from `draft` to the release date (e.g., `2025-XX-XX`). +2. **Update the schema URL**: Change the `$id` in [`schema.ts`](./schema.ts) from `draft` to the release date (e.g., `2025-XX-XX`) and run `make generate-schema`. 3. **Merge the PR**: Get approval and merge the changes to main. diff --git a/docs/reference/server-json/draft/server.schema.json b/docs/reference/server-json/draft/server.schema.json index e3aeab6a6..34fd911ae 100644 --- a/docs/reference/server-json/draft/server.schema.json +++ b/docs/reference/server-json/draft/server.schema.json @@ -1,5 +1,5 @@ { - "$comment": "This file is auto-generated from docs/reference/api/openapi.yaml. Do not edit manually. Run 'make generate-schema' to update.", + "$comment": "This file is auto-generated from docs/reference/server-json/schema.ts. Do not edit manually. Run 'make generate-schema' to update.", "$id": "https://raw.githubusercontent.com/modelcontextprotocol/registry/main/docs/reference/server-json/draft/server.schema.json", "$ref": "#/definitions/ServerDetail", "$schema": "http://json-schema.org/draft-07/schema#", diff --git a/docs/reference/server-json/examples/invalid/bad-name-pattern.json b/docs/reference/server-json/examples/invalid/bad-name-pattern.json new file mode 100644 index 000000000..f200f73e6 --- /dev/null +++ b/docs/reference/server-json/examples/invalid/bad-name-pattern.json @@ -0,0 +1,5 @@ +{ + "name": "no-namespace-separator", + "description": "The name must contain exactly one slash separating namespace from name.", + "version": "1.0.0" +} diff --git a/docs/reference/server-json/examples/invalid/description-too-long.json b/docs/reference/server-json/examples/invalid/description-too-long.json new file mode 100644 index 000000000..265ef0dc7 --- /dev/null +++ b/docs/reference/server-json/examples/invalid/description-too-long.json @@ -0,0 +1,5 @@ +{ + "name": "io.github.user/verbose", + "description": "This description deliberately exceeds the one-hundred character maximum length enforced by the schema for sure.", + "version": "1.0.0" +} diff --git a/docs/reference/server-json/examples/invalid/missing-name.json b/docs/reference/server-json/examples/invalid/missing-name.json new file mode 100644 index 000000000..c83ba569a --- /dev/null +++ b/docs/reference/server-json/examples/invalid/missing-name.json @@ -0,0 +1,4 @@ +{ + "description": "Server without the required name field.", + "version": "1.0.0" +} diff --git a/docs/reference/server-json/examples/invalid/package-version-latest.json b/docs/reference/server-json/examples/invalid/package-version-latest.json new file mode 100644 index 000000000..89dc178aa --- /dev/null +++ b/docs/reference/server-json/examples/invalid/package-version-latest.json @@ -0,0 +1,13 @@ +{ + "name": "io.github.user/bad-version", + "description": "Package pins the disallowed floating tag 'latest'.", + "version": "1.0.0", + "packages": [ + { + "registryType": "npm", + "identifier": "@modelcontextprotocol/server-weather", + "version": "latest", + "transport": { "type": "stdio" } + } + ] +} diff --git a/docs/reference/server-json/examples/invalid/positional-argument-missing-value.json b/docs/reference/server-json/examples/invalid/positional-argument-missing-value.json new file mode 100644 index 000000000..03fca0bc5 --- /dev/null +++ b/docs/reference/server-json/examples/invalid/positional-argument-missing-value.json @@ -0,0 +1,16 @@ +{ + "name": "io.github.user/bad-argument", + "description": "Positional argument provides neither valueHint nor value.", + "version": "1.0.0", + "packages": [ + { + "registryType": "npm", + "identifier": "@modelcontextprotocol/server-weather", + "version": "1.0.0", + "transport": { "type": "stdio" }, + "packageArguments": [ + { "type": "positional", "isRepeated": false } + ] + } + ] +} diff --git a/docs/reference/server-json/examples/valid/minimal.json b/docs/reference/server-json/examples/valid/minimal.json new file mode 100644 index 000000000..96ffda4f5 --- /dev/null +++ b/docs/reference/server-json/examples/valid/minimal.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json", + "name": "io.github.user/weather", + "description": "MCP server providing weather data and forecasts.", + "version": "1.0.2" +} diff --git a/docs/reference/server-json/examples/valid/with-package.json b/docs/reference/server-json/examples/valid/with-package.json new file mode 100644 index 000000000..39ff84312 --- /dev/null +++ b/docs/reference/server-json/examples/valid/with-package.json @@ -0,0 +1,22 @@ +{ + "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json", + "name": "io.github.user/local-weather", + "description": "Local MCP server distributed as an npm package.", + "version": "1.0.0", + "packages": [ + { + "registryType": "npm", + "identifier": "@modelcontextprotocol/server-weather", + "version": "1.0.0", + "transport": { "type": "stdio" }, + "runtimeHint": "npx", + "packageArguments": [ + { "type": "positional", "valueHint": "config_path" }, + { "type": "named", "name": "--port", "value": "8080" } + ], + "environmentVariables": [ + { "name": "API_KEY", "isSecret": true, "isRequired": true } + ] + } + ] +} diff --git a/docs/reference/server-json/examples/valid/with-remote.json b/docs/reference/server-json/examples/valid/with-remote.json new file mode 100644 index 000000000..4531c820f --- /dev/null +++ b/docs/reference/server-json/examples/valid/with-remote.json @@ -0,0 +1,32 @@ +{ + "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json", + "name": "io.github.user/remote-weather", + "description": "Remote MCP server reachable over streamable HTTP.", + "version": "2.1.0", + "title": "Remote Weather", + "websiteUrl": "https://modelcontextprotocol.io/examples", + "repository": { + "url": "https://github.com/modelcontextprotocol/servers", + "source": "github", + "subfolder": "src/weather" + }, + "icons": [ + { + "src": "https://example.com/icon.png", + "mimeType": "image/png", + "sizes": ["48x48", "96x96"] + } + ], + "remotes": [ + { + "type": "streamable-http", + "url": "https://{host}/mcp", + "headers": [ + { "name": "Authorization", "isSecret": true, "isRequired": true } + ], + "variables": { + "host": { "description": "API host", "default": "api.example.com" } + } + } + ] +} diff --git a/docs/reference/server-json/package-lock.json b/docs/reference/server-json/package-lock.json new file mode 100644 index 000000000..680b7d80d --- /dev/null +++ b/docs/reference/server-json/package-lock.json @@ -0,0 +1,661 @@ +{ + "name": "@modelcontextprotocol/registry-server-json-schema", + "version": "0.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@modelcontextprotocol/registry-server-json-schema", + "version": "0.0.0", + "devDependencies": { + "@types/node": "^22.10.2", + "ajv": "^8.17.1", + "ajv-formats": "^3.0.1", + "tsx": "^4.19.2", + "typescript": "^5.7.2", + "yaml": "^2.6.1" + } + }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.28.1.tgz", + "integrity": "sha512-Svl7tq8k/08+p6CXPpRjQ1fKX+1odH/BQbb48fV6fj3CWHhsoIOoY87w1oHXm0qEpkIK3ZfVgp0hed3XBXzXMQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.28.1.tgz", + "integrity": "sha512-0k2F129Xdio1TdJfzJ8sy1Q47vUD2NnwdhiAf7drUN1EBTfPf4hsFCtmMgu/6m8JSzsBrlmVjudMBQqOfG8usQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.28.1.tgz", + "integrity": "sha512-34EGEbCIAgosYz6goLcopX6Mo7NyGv9tfwEM2/7Ce2VcVRk568iSvniGWcUXIy7wEDR1wzolcxcriFVrWYcwBg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.28.1.tgz", + "integrity": "sha512-dbwY7ltSMDWsRatcRpCnES4F+im88OCUgGZjy52shC7GqHRE/cYlxNbB4Z4UpJswpcc4Qxd2oE/ufM0p61IKng==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.28.1.tgz", + "integrity": "sha512-TZbWkQY7kvTAXbXUT7uVACR5cMHsDiSz9z7ZKAX/RTq/WJEk3QyRr0wZpNhBDX+/0CtdqUIJlOiodQcta6tY3Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.28.1.tgz", + "integrity": "sha512-zfdzgK9ACBNZLI/CyHTOx81SyNbM6YXn7rxSgX97VjyiPl9W1i4Ka4fgKECEoFCKGpvBj5qArWIGgQjOwkgskQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.28.1.tgz", + "integrity": "sha512-wG2EA8ENdEI0qhkSZMjfqrdY+ziCYCPMmtZjjIwOmXFjmyzEHn+UUxk5of+SYsjtfs3VpnlC7QLzSI5hY/rOAw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.28.1.tgz", + "integrity": "sha512-i7dZ9vQgnvSCzi/rYCXNgtF/U+eKZNJBzu3eTQbRgHnM7tNSizLOkRFAl3qzVc/Op/u5YkHHa4pf/3DOYHthLQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.28.1.tgz", + "integrity": "sha512-qVXBOHQS+d5Y722GwJzJUtOLlX7km3CraOaGormF1pDtPd2C/l1SHRPgjLunLGe51Sh5YYWKMFDyV4SxgMQYTQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.28.1.tgz", + "integrity": "sha512-yHs+0uc8+nvEAfAfxrWQKK5peSNzBc4PegcMO0EJ2hT71uA7vB8Ihg2e77R2P7SG5uYjPbHlLLmve4LLLRCf0g==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.28.1.tgz", + "integrity": "sha512-d1z4ZuP0ajrfz/FhGT4vv278rX8KnPPJx8i5+AtK7TYbx9Le9F1hyzurZpkEyjkGa9dUGhQow4C1NmeGvqxN2w==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.28.1.tgz", + "integrity": "sha512-M5sRjUVZrkm1OAPR3dlOYzNmN+loZKGVi1VUQGrwuqLcbR6qeAz+famMhjASeH3YVKvZz+zT1jlh/keC3Rj/lg==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.28.1.tgz", + "integrity": "sha512-mRObBZeHh2OxcBFPWE/FjylkRgZdYuiTR3vaTozquCGOH14iP9oN4x4Ge81CoIDYQrXmIxpFumJBu5MtZpnQJQ==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.28.1.tgz", + "integrity": "sha512-slScBsMAb3GFDcdrCgLwZtPYRoH2H/youv10QiZyRjmsP48fznoveWytSgCI/R0ZcUgpc0ZhIUEx6LHts8yrfQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.28.1.tgz", + "integrity": "sha512-kw0owk1o0GFETUJyW0jc0G4Yzs0BHZn0JDZ8JRT088vjJYX777BAs1fDGxAC+q831qOs2DTC96mNsG2opdfyyQ==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.28.1.tgz", + "integrity": "sha512-/lAIjX8aYFRByhh6L5rYtPEDRqa9de/4V/juOXcta5frjvzXO4/sqEtyytse0g3zZFuWu5cDN0MkLz2qRDD2Ag==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.28.1.tgz", + "integrity": "sha512-u/anNYF2mmVOEDwLtnQ1wOr3EZ9sTNGLWrsYGYwHWzGA3Si84IOkHXlbWTD1NB+9/1lcnweYKO54uhxZydNzfA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.28.1.tgz", + "integrity": "sha512-oks0DYbLwWMmaakTsCb+zL4E+aHRVLom9IJZOAthMQEPiQmydXHkziYEsGYRx0uNV/IjEKGAV941JzH02pflqw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.28.1.tgz", + "integrity": "sha512-aeL6lAnN89Hz43Mlh1G8ARasbuoYvSITDEx0tHh5b7jJnHcssqgjy9Yx430GDpmCa6OyrKoS0aNRjKundRizGg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.28.1.tgz", + "integrity": "sha512-MEFJe5C3R8pwXdZ5Y21oo6m7ePiS0d9pWucn99O/wvyJZChoIQKrQDxKrGeW8F5+T0okTHesAmDeiHDTIq0V/Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.28.1.tgz", + "integrity": "sha512-i/ZLIOafE0Z8cI/XANJAixoJL/uRAoS2xOA3rb0xN+KK0K177cMAsQYkzHtBrtMXAKuAc7HGgcWiZ/sRC1Nxgw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openharmony-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.28.1.tgz", + "integrity": "sha512-ge+Z7EXFNt2BO1oAMsVpiQ8EwndV9i1xXerAeTIK7AtPs3bKFXQM7nlRxDSIUIMeueR1CNXxqztLzdNeReKBJg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.28.1.tgz", + "integrity": "sha512-BEjgtECkL3vY+SaSQ6nzVfiALUeFxpawyp8Jmf5PtYhf1Ug40N1h/hxlhts+f1FvSvarEigdxS3BlSMI2PJLcQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.28.1.tgz", + "integrity": "sha512-lCv9eK/H6ZJWbE7bh2nw54CZ9M2nupBxJcTsdk/QQnWkdSjKGuxmmH8/GWrlT1eMmZfn4dGcCjRte397WqfQXA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.28.1.tgz", + "integrity": "sha512-zvb/mB2bSCoJOpoCBgYKKpX6YM6mJBlBUVUtVj41DlZJVEB6/0CKlRYxP5wWl1C1ILiCoAU5wZZ4q1P3qeS6Eg==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.28.1.tgz", + "integrity": "sha512-bm4Mowrv+GXMlpWX++EcXw/iLyd1o3+bJkC2DkWXYVvgZCqD/bSj9ctZeAMC3cIxgjRVR2Dufaiu4YPxr5gW1A==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@types/node": { + "version": "22.19.21", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.19.21.tgz", + "integrity": "sha512-VMeFBSCKQKmm2swI2kW51SFusDqekC6q9trBCvJ/JliDchFSuoYYKN7yVNjPthP1HKZcx3U1gI/wTcEBjEFKTA==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~6.21.0" + } + }, + "node_modules/ajv": { + "version": "8.20.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.20.0.tgz", + "integrity": "sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/ajv-formats": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-3.0.1.tgz", + "integrity": "sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "ajv": "^8.0.0" + }, + "peerDependencies": { + "ajv": "^8.0.0" + }, + "peerDependenciesMeta": { + "ajv": { + "optional": true + } + } + }, + "node_modules/esbuild": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.1.tgz", + "integrity": "sha512-HrJrvZv5ayxBzPfwphOoNzkzOIIlifzk0KJrGK2c8R4+LKpMtpYLQeUdjnwjWv/LZlkH2laZk+4w78pi99D4Vw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.28.1", + "@esbuild/android-arm": "0.28.1", + "@esbuild/android-arm64": "0.28.1", + "@esbuild/android-x64": "0.28.1", + "@esbuild/darwin-arm64": "0.28.1", + "@esbuild/darwin-x64": "0.28.1", + "@esbuild/freebsd-arm64": "0.28.1", + "@esbuild/freebsd-x64": "0.28.1", + "@esbuild/linux-arm": "0.28.1", + "@esbuild/linux-arm64": "0.28.1", + "@esbuild/linux-ia32": "0.28.1", + "@esbuild/linux-loong64": "0.28.1", + "@esbuild/linux-mips64el": "0.28.1", + "@esbuild/linux-ppc64": "0.28.1", + "@esbuild/linux-riscv64": "0.28.1", + "@esbuild/linux-s390x": "0.28.1", + "@esbuild/linux-x64": "0.28.1", + "@esbuild/netbsd-arm64": "0.28.1", + "@esbuild/netbsd-x64": "0.28.1", + "@esbuild/openbsd-arm64": "0.28.1", + "@esbuild/openbsd-x64": "0.28.1", + "@esbuild/openharmony-arm64": "0.28.1", + "@esbuild/sunos-x64": "0.28.1", + "@esbuild/win32-arm64": "0.28.1", + "@esbuild/win32-ia32": "0.28.1", + "@esbuild/win32-x64": "0.28.1" + } + }, + "node_modules/fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "dev": true, + "license": "MIT" + }, + "node_modules/fast-uri": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.2.tgz", + "integrity": "sha512-rVjf7ArG3LTk+FS6Yw81V1DLuZl1bRbNrev6Tmd/9RaroeeRRJhAt7jg/6YFxbvAQXUCavSoZhPPj6oOx+5KjQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "BSD-3-Clause" + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", + "dev": true, + "license": "MIT" + }, + "node_modules/require-from-string": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/tsx": { + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.22.4.tgz", + "integrity": "sha512-X8EX+XV4QR5xCsrgxaED954zTDfY8KqlDtskKEL0cHhyS/P8b4IFOvGDQpsC9Q1XnLq915wEfwwY/zzskCtmhg==", + "dev": true, + "license": "MIT", + "dependencies": { + "esbuild": "~0.28.0" + }, + "bin": { + "tsx": "dist/cli.mjs" + }, + "engines": { + "node": ">=18.0.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + } + }, + "node_modules/typescript": { + "version": "5.9.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", + "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/undici-types": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", + "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/yaml": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.9.0.tgz", + "integrity": "sha512-2AvhNX3mb8zd6Zy7INTtSpl1F15HW6Wnqj0srWlkKLcpYl/gMIMJiyuGq2KeI2YFxUPjdlB+3Lc10seMLtL4cA==", + "dev": true, + "license": "ISC", + "bin": { + "yaml": "bin.mjs" + }, + "engines": { + "node": ">= 14.6" + }, + "funding": { + "url": "https://github.com/sponsors/eemeli" + } + } + } +} diff --git a/docs/reference/server-json/package.json b/docs/reference/server-json/package.json new file mode 100644 index 000000000..c9f647e02 --- /dev/null +++ b/docs/reference/server-json/package.json @@ -0,0 +1,20 @@ +{ + "name": "@modelcontextprotocol/registry-server-json-schema", + "version": "0.0.0", + "private": true, + "description": "TypeScript source of truth and generator for the server.json JSON Schema.", + "type": "module", + "scripts": { + "generate": "tsx scripts/generate-schema.ts", + "check": "tsx scripts/generate-schema.ts --check && tsx scripts/check-openapi.ts && tsc --noEmit", + "validate": "tsx scripts/validate-examples.ts" + }, + "devDependencies": { + "@types/node": "^22.10.2", + "ajv": "^8.17.1", + "ajv-formats": "^3.0.1", + "tsx": "^4.19.2", + "typescript": "^5.7.2", + "yaml": "^2.6.1" + } +} diff --git a/docs/reference/server-json/schema.ts b/docs/reference/server-json/schema.ts new file mode 100644 index 000000000..648c27789 --- /dev/null +++ b/docs/reference/server-json/schema.ts @@ -0,0 +1,592 @@ +// Source of truth for the server.json JSON Schema. +// +// This TypeScript file is the canonical definition of the schema. The committed +// artifact `draft/server.schema.json` is generated from it -- do not edit that +// JSON by hand. Run `npm run generate` (or `make generate-schema` from the repo +// root) to regenerate it, and `npm run check` to verify it is in sync. +// +// The schema is expressed as a plain object literal so the generated JSON can be +// reproduced exactly (a strict no-op vs. the previous OpenAPI-derived output). +// The `JSONSchema` type is intentionally permissive: the document is draft-07 +// JSON Schema that also carries OpenAPI-style `example` annotations, which are +// not part of the standard JSON Schema vocabulary. + +export type JSONSchema = { [keyword: string]: unknown }; + +export const schema: JSONSchema = { + "$comment": "This file is auto-generated from docs/reference/server-json/schema.ts. Do not edit manually. Run 'make generate-schema' to update.", + "$id": "https://raw.githubusercontent.com/modelcontextprotocol/registry/main/docs/reference/server-json/draft/server.schema.json", + "$ref": "#/definitions/ServerDetail", + "$schema": "http://json-schema.org/draft-07/schema#", + "definitions": { + "Argument": { + "anyOf": [ + { + "$ref": "#/definitions/PositionalArgument" + }, + { + "$ref": "#/definitions/NamedArgument" + } + ], + "description": "Warning: Arguments construct command-line parameters that may contain user-provided input. This creates potential command injection risks if clients execute commands in a shell environment. For example, a malicious argument value like ';rm -rf ~/Development' could execute dangerous commands. Clients should prefer non-shell execution methods (e.g., posix_spawn) when possible to eliminate injection risks entirely. Where not possible, clients should obtain consent from users or agents to run the resolved command before execution." + }, + "Icon": { + "description": "An optionally-sized icon that can be displayed in a user interface.", + "properties": { + "mimeType": { + "description": "Optional MIME type override if the source MIME type is missing or generic. Must be one of: image/png, image/jpeg, image/jpg, image/svg+xml, image/webp.", + "enum": [ + "image/png", + "image/jpeg", + "image/jpg", + "image/svg+xml", + "image/webp" + ], + "example": "image/png", + "type": "string" + }, + "sizes": { + "description": "Optional array of strings that specify sizes at which the icon can be used. Each string should be in WxH format (e.g., '48x48', '96x96') or 'any' for scalable formats like SVG. If not provided, the client should assume that the icon can be used at any size.", + "examples": [ + [ + "48x48", + "96x96" + ], + [ + "any" + ] + ], + "items": { + "pattern": "^(\\d+x\\d+|any)$", + "type": "string" + }, + "type": "array" + }, + "src": { + "description": "A standard URI pointing to an icon resource. Must be an HTTPS URL. Consumers SHOULD take steps to ensure URLs serving icons are from the same domain as the server or a trusted domain. Consumers SHOULD take appropriate precautions when consuming SVGs as they can contain executable JavaScript.", + "example": "https://example.com/icon.png", + "format": "uri", + "maxLength": 255, + "type": "string" + }, + "theme": { + "description": "Optional specifier for the theme this icon is designed for. 'light' indicates the icon is designed to be used with a light background, and 'dark' indicates the icon is designed to be used with a dark background. If not provided, the client should assume the icon can be used with any theme.", + "enum": [ + "light", + "dark" + ], + "type": "string" + } + }, + "required": [ + "src" + ], + "type": "object" + }, + "Input": { + "properties": { + "choices": { + "description": "A list of possible values for the input. If provided, the user must select one of these values.", + "example": [], + "items": { + "type": "string" + }, + "type": "array" + }, + "default": { + "description": "The default value for the input. This should be a valid value for the input. If you want to provide input examples or guidance, use the `placeholder` field instead.", + "type": "string" + }, + "description": { + "description": "A description of the input, which clients can use to provide context to the user.", + "type": "string" + }, + "format": { + "default": "string", + "description": "Specifies the input format. Supported values include `filepath`, which should be interpreted as a file on the user's filesystem.\n\nWhen the input is converted to a string, booleans should be represented by the strings \"true\" and \"false\", and numbers should be represented as decimal values.", + "enum": [ + "string", + "number", + "boolean", + "filepath" + ], + "type": "string" + }, + "isRequired": { + "default": false, + "type": "boolean" + }, + "isSecret": { + "default": false, + "description": "Indicates whether the input is a secret value (e.g., password, token). If true, clients should handle the value securely.", + "type": "boolean" + }, + "placeholder": { + "description": "A placeholder for the input to be displaying during configuration. This is used to provide examples or guidance about the expected form or content of the input.", + "type": "string" + }, + "value": { + "description": "The value for the input. If this is not set, the user may be prompted to provide a value. If a value is set, it should not be configurable by end users.\n\nIdentifiers wrapped in `{curly_braces}` will be replaced with the corresponding properties from the input `variables` map. If an identifier in braces is not found in `variables`, or if `variables` is not provided, the `{curly_braces}` substring should remain unchanged.\n", + "type": "string" + } + }, + "type": "object" + }, + "InputWithVariables": { + "allOf": [ + { + "$ref": "#/definitions/Input" + }, + { + "properties": { + "variables": { + "additionalProperties": { + "$ref": "#/definitions/Input" + }, + "description": "A map of variable names to their values. Keys in the input `value` that are wrapped in `{curly_braces}` will be replaced with the corresponding variable values.", + "type": "object" + } + }, + "type": "object" + } + ] + }, + "KeyValueInput": { + "allOf": [ + { + "$ref": "#/definitions/InputWithVariables" + }, + { + "properties": { + "name": { + "description": "Name of the header or environment variable.", + "example": "SOME_VARIABLE", + "type": "string" + } + }, + "required": [ + "name" + ], + "type": "object" + } + ] + }, + "LocalTransport": { + "anyOf": [ + { + "$ref": "#/definitions/StdioTransport" + }, + { + "$ref": "#/definitions/StreamableHttpTransport" + }, + { + "$ref": "#/definitions/SseTransport" + } + ], + "description": "Transport protocol configuration for local/package context" + }, + "NamedArgument": { + "allOf": [ + { + "$ref": "#/definitions/InputWithVariables" + }, + { + "properties": { + "isRepeated": { + "default": false, + "description": "Whether the argument can be repeated multiple times.", + "type": "boolean" + }, + "name": { + "description": "The flag name, including any leading dashes.", + "example": "--port", + "type": "string" + }, + "type": { + "enum": [ + "named" + ], + "example": "named", + "type": "string" + } + }, + "required": [ + "type", + "name" + ], + "type": "object" + } + ], + "description": "A command-line `--flag={value}`." + }, + "Package": { + "properties": { + "environmentVariables": { + "description": "A mapping of environment variables to be set when running the package.", + "items": { + "$ref": "#/definitions/KeyValueInput" + }, + "type": "array" + }, + "fileSha256": { + "description": "SHA-256 hash of the package file for integrity verification. Required for MCPB packages and optional for other package types. Authors are responsible for generating correct SHA-256 hashes when creating server.json. If present, MCP clients must validate the downloaded file matches the hash before running packages to ensure file integrity.", + "example": "fe333e598595000ae021bd27117db32ec69af6987f507ba7a63c90638ff633ce", + "pattern": "^[a-f0-9]{64}$", + "type": "string" + }, + "identifier": { + "description": "Package identifier - either a package name (for registries) or URL (for direct downloads)", + "examples": [ + "@modelcontextprotocol/server-brave-search", + "https://github.com/example/releases/download/v1.0.0/package.mcpb" + ], + "type": "string" + }, + "packageArguments": { + "description": "A list of arguments to be passed to the package's binary.", + "items": { + "$ref": "#/definitions/Argument" + }, + "type": "array" + }, + "registryBaseUrl": { + "description": "Base URL of the package registry", + "examples": [ + "https://registry.npmjs.org", + "https://pypi.org", + "https://crates.io", + "https://docker.io", + "https://api.nuget.org/v3/index.json", + "https://github.com", + "https://gitlab.com" + ], + "format": "uri", + "type": "string" + }, + "registryType": { + "description": "Registry type indicating how to download packages (e.g., 'npm', 'pypi', 'cargo', 'oci', 'nuget', 'mcpb')", + "examples": [ + "npm", + "pypi", + "cargo", + "oci", + "nuget", + "mcpb" + ], + "type": "string" + }, + "runtimeArguments": { + "description": "A list of arguments to be passed to the package's runtime command (such as docker or npx). The `runtimeHint` field should be provided when `runtimeArguments` are present.", + "items": { + "$ref": "#/definitions/Argument" + }, + "type": "array" + }, + "runtimeHint": { + "description": "A hint to help clients determine the appropriate runtime for the package. This field should be provided when `runtimeArguments` are present.", + "examples": [ + "npx", + "uvx", + "docker", + "dnx" + ], + "type": "string" + }, + "transport": { + "$ref": "#/definitions/LocalTransport", + "description": "Transport protocol configuration for the package" + }, + "version": { + "description": "Package version. Must be a specific version. Version ranges are rejected (e.g., '^1.2.3', '~1.2.3', '>=1.2.3', '1.x', '1.*').", + "example": "1.0.2", + "maxLength": 255, + "minLength": 1, + "not": { + "const": "latest" + }, + "type": "string" + } + }, + "required": [ + "registryType", + "identifier", + "transport" + ], + "type": "object" + }, + "PositionalArgument": { + "allOf": [ + { + "$ref": "#/definitions/InputWithVariables" + }, + { + "anyOf": [ + { + "required": [ + "valueHint" + ] + }, + { + "required": [ + "value" + ] + } + ], + "properties": { + "isRepeated": { + "default": false, + "description": "Whether the argument can be repeated multiple times in the command line.", + "type": "boolean" + }, + "type": { + "enum": [ + "positional" + ], + "example": "positional", + "type": "string" + }, + "valueHint": { + "description": "An identifier for the positional argument. It is not part of the command line. It may be used by client configuration as a label identifying the argument. It is also used to identify the value in transport URL variable substitution.", + "example": "file_path", + "type": "string" + } + }, + "required": [ + "type" + ], + "type": "object" + } + ], + "description": "A positional input is a value inserted verbatim into the command line." + }, + "RemoteTransport": { + "allOf": [ + { + "anyOf": [ + { + "$ref": "#/definitions/StreamableHttpTransport" + }, + { + "$ref": "#/definitions/SseTransport" + } + ] + }, + { + "properties": { + "variables": { + "additionalProperties": { + "$ref": "#/definitions/Input" + }, + "description": "Configuration variables that can be referenced in URL template {curly_braces}. The key is the variable name, and the value defines the variable properties.", + "type": "object" + } + }, + "type": "object" + } + ], + "description": "Transport protocol configuration for remote context - extends StreamableHttpTransport or SseTransport with variables" + }, + "Repository": { + "description": "Repository metadata for the MCP server source code. Enables users and security experts to inspect the code, improving transparency.", + "properties": { + "id": { + "description": "Repository identifier from the hosting service (e.g., GitHub repo ID). Owned and determined by the source forge. Should remain stable across repository renames and may be used to detect repository resurrection attacks - if a repository is deleted and recreated, the ID should change. For GitHub, use: gh api repos// --jq '.id'", + "example": "b94b5f7e-c7c6-d760-2c78-a5e9b8a5b8c9", + "type": "string" + }, + "source": { + "description": "Repository hosting service identifier. Used by registries to determine validation and API access methods.", + "example": "github", + "type": "string" + }, + "subfolder": { + "description": "Optional relative path from repository root to the server location within a monorepo or nested package structure. Must be a clean relative path.", + "example": "src/everything", + "type": "string" + }, + "url": { + "description": "Repository URL for browsing source code. Should support both web browsing and git clone operations.", + "example": "https://github.com/modelcontextprotocol/servers", + "format": "uri", + "type": "string" + } + }, + "required": [ + "url", + "source" + ], + "type": "object" + }, + "ServerDetail": { + "description": "Schema for a static representation of an MCP server. Used in various contexts related to discovery, installation, and configuration.", + "properties": { + "$schema": { + "description": "JSON Schema URI for this server.json format", + "example": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json", + "format": "uri", + "type": "string" + }, + "_meta": { + "description": "Extension metadata using reverse DNS namespacing for vendor-specific data", + "properties": { + "io.modelcontextprotocol.registry/publisher-provided": { + "additionalProperties": true, + "description": "Publisher-provided metadata for downstream registries", + "example": { + "buildInfo": { + "commit": "abc123def456", + "pipelineId": "build-789", + "timestamp": "2023-12-01T10:30:00Z" + }, + "tool": "publisher-cli", + "version": "1.2.3" + }, + "type": "object" + } + }, + "type": "object" + }, + "description": { + "description": "Clear human-readable explanation of server functionality. Should focus on capabilities, not implementation details.", + "example": "MCP server providing weather data and forecasts via OpenWeatherMap API", + "maxLength": 100, + "minLength": 1, + "type": "string" + }, + "icons": { + "description": "Optional set of sized icons that the client can display in a user interface. Clients that support rendering icons MUST support at least the following MIME types: image/png and image/jpeg (safe, universal compatibility). Clients SHOULD also support: image/svg+xml (scalable but requires security precautions) and image/webp (modern, efficient format).", + "items": { + "$ref": "#/definitions/Icon" + }, + "type": "array" + }, + "name": { + "description": "Server name in reverse-DNS format. Must contain exactly one forward slash separating namespace from server name.", + "example": "io.github.user/weather", + "maxLength": 200, + "minLength": 3, + "pattern": "^[a-zA-Z0-9.-]+/[a-zA-Z0-9._-]+$", + "type": "string" + }, + "packages": { + "items": { + "$ref": "#/definitions/Package" + }, + "type": "array" + }, + "remotes": { + "items": { + "$ref": "#/definitions/RemoteTransport" + }, + "type": "array" + }, + "repository": { + "$ref": "#/definitions/Repository", + "description": "Optional repository metadata for the MCP server source code. Recommended for transparency and security inspection." + }, + "title": { + "description": "Optional human-readable title or display name for the MCP server. MCP subregistries or clients MAY choose to use this for display purposes.", + "example": "Weather API", + "maxLength": 100, + "minLength": 1, + "type": "string" + }, + "version": { + "description": "Version string for this server. SHOULD follow semantic versioning (e.g., '1.0.2', '2.1.0-alpha'). Equivalent of Implementation.version in MCP specification. Non-semantic versions are allowed but may not sort predictably. Version ranges are rejected (e.g., '^1.2.3', '~1.2.3', '>=1.2.3', '1.x', '1.*').", + "example": "1.0.2", + "maxLength": 255, + "type": "string" + }, + "websiteUrl": { + "description": "Optional URL to the server's homepage, documentation, or project website. This provides a central link for users to learn more about the server. Particularly useful when the server has custom installation instructions or setup requirements.", + "example": "https://modelcontextprotocol.io/examples", + "format": "uri", + "type": "string" + } + }, + "required": [ + "name", + "description", + "version" + ], + "type": "object" + }, + "SseTransport": { + "properties": { + "headers": { + "description": "HTTP headers to include", + "items": { + "$ref": "#/definitions/KeyValueInput" + }, + "type": "array" + }, + "type": { + "description": "Transport type", + "enum": [ + "sse" + ], + "example": "sse", + "type": "string" + }, + "url": { + "description": "Server-Sent Events endpoint URL template. Must start with http://, https://, or a template variable (e.g., {baseUrl}). Variables in {curly_braces} are resolved based on context: In Package context, they reference argument valueHints, argument names, or environment variable names from the parent Package. In Remote context, they reference variables from the transport's 'variables' object. After variable substitution, this should produce a valid URI.", + "example": "https://mcp-fs.example.com/sse", + "pattern": "^(https?://[^\\s]+|\\{[a-zA-Z_][a-zA-Z0-9_]*\\}[^\\s]*)$", + "type": "string" + } + }, + "required": [ + "type", + "url" + ], + "type": "object" + }, + "StdioTransport": { + "properties": { + "type": { + "description": "Transport type", + "enum": [ + "stdio" + ], + "example": "stdio", + "type": "string" + } + }, + "required": [ + "type" + ], + "type": "object" + }, + "StreamableHttpTransport": { + "properties": { + "headers": { + "description": "HTTP headers to include", + "items": { + "$ref": "#/definitions/KeyValueInput" + }, + "type": "array" + }, + "type": { + "description": "Transport type", + "enum": [ + "streamable-http" + ], + "example": "streamable-http", + "type": "string" + }, + "url": { + "description": "URL template for the streamable-http transport. Must start with http://, https://, or a template variable (e.g., {baseUrl}). Variables in {curly_braces} are resolved based on context: In Package context, they reference argument valueHints, argument names, or environment variable names from the parent Package. In Remote context, they reference variables from the transport's 'variables' object. After variable substitution, this should produce a valid URI.", + "example": "https://api.example.com/mcp", + "pattern": "^(https?://[^\\s]+|\\{[a-zA-Z_][a-zA-Z0-9_]*\\}[^\\s]*)$", + "type": "string" + } + }, + "required": [ + "type", + "url" + ], + "type": "object" + } + }, + "title": "server.json defining a Model Context Protocol (MCP) server" +}; diff --git a/docs/reference/server-json/scripts/check-openapi.ts b/docs/reference/server-json/scripts/check-openapi.ts new file mode 100644 index 000000000..561f45315 --- /dev/null +++ b/docs/reference/server-json/scripts/check-openapi.ts @@ -0,0 +1,87 @@ +// Verifies that docs/reference/api/openapi.yaml references the generated +// server.json schema instead of duplicating it. +// +// schema.ts is the single source of truth: `npm run generate` produces +// draft/server.schema.json, and openapi.yaml's components/schemas exposes each +// server.json definition as a thin external $ref into that file. This check +// fails (exit 1) if any definition is missing its stub, a stub points at a +// definition that does not exist, or a stub's shape drifts -- e.g. after adding +// or renaming a top-level definition in schema.ts. + +import { readFileSync } from "node:fs"; +import { dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; + +import { parse } from "yaml"; + +import { schema } from "../schema.ts"; + +const __dirname = dirname(fileURLToPath(import.meta.url)); +const OPENAPI = join(__dirname, "..", "..", "api", "openapi.yaml"); +const SCHEMA_REF_PREFIX = "../server-json/draft/server.schema.json#/definitions/"; + +type Schemas = Record; + +function expectedStub(name: string): { $ref: string } { + return { $ref: `${SCHEMA_REF_PREFIX}${name}` }; +} + +function main(): void { + const definitions = (schema.definitions ?? {}) as Schemas; + const definitionNames = Object.keys(definitions); + + const openapi = parse(readFileSync(OPENAPI, "utf-8")) as { + components?: { schemas?: Schemas }; + }; + const schemas = openapi.components?.schemas; + if (!schemas) { + console.error("✗ openapi.yaml has no components.schemas"); + process.exit(1); + } + + const errors: string[] = []; + + // Every server.json definition must be exposed as the expected external $ref. + for (const name of definitionNames) { + const actual = schemas[name]; + const expected = expectedStub(name); + if (JSON.stringify(actual) !== JSON.stringify(expected)) { + errors.push( + `components.schemas.${name} should be ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`, + ); + } + } + + // Every external $ref into server.schema.json must target a real definition. + for (const [name, value] of Object.entries(schemas)) { + if ( + value && + typeof value === "object" && + "$ref" in value && + typeof (value as { $ref: unknown }).$ref === "string" + ) { + const ref = (value as { $ref: string }).$ref; + if (ref.startsWith(SCHEMA_REF_PREFIX)) { + const target = ref.slice(SCHEMA_REF_PREFIX.length); + if (!(target in definitions)) { + errors.push( + `components.schemas.${name} references unknown definition '${target}'`, + ); + } + } + } + } + + if (errors.length > 0) { + console.error("✗ openapi.yaml is out of sync with schema.ts:"); + for (const e of errors) console.error(` - ${e}`); + console.error("\nUpdate the external $ref stubs in openapi.yaml's components/schemas."); + process.exit(1); + } + + console.log( + `✓ openapi.yaml references all ${definitionNames.length} server.json definitions via external $ref`, + ); +} + +main(); diff --git a/docs/reference/server-json/scripts/generate-schema.ts b/docs/reference/server-json/scripts/generate-schema.ts new file mode 100644 index 000000000..329f3785e --- /dev/null +++ b/docs/reference/server-json/scripts/generate-schema.ts @@ -0,0 +1,68 @@ +// Generates draft/server.schema.json from schema.ts. +// +// With --check, regenerates in memory and fails (exit 1) if the committed file +// is out of date instead of writing it. Mirrors the experimental Server Card +// repo's generate-schema.ts (TS source of truth -> generated JSON Schema). +// +// The serialization deliberately reproduces Go's encoding/json output +// (MarshalIndent with a two-space indent) so this change is a strict no-op +// against the schema previously produced by tools/extract-server-schema: +// - object keys are sorted ascending (Go sorts map keys); array order is kept +// - <, >, & and U+2028/U+2029 are escaped (Go's SetEscapeHTML default) +// - a trailing newline is appended + +import { readFileSync, writeFileSync } from "node:fs"; +import { dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; + +import { schema } from "../schema.ts"; + +const __dirname = dirname(fileURLToPath(import.meta.url)); +const SCHEMA_JSON = join(__dirname, "..", "draft", "server.schema.json"); + +const CHECK_MODE = process.argv.includes("--check"); + +function sortKeys(value: unknown): unknown { + if (Array.isArray(value)) return value.map(sortKeys); + if (value && typeof value === "object") { + const sorted: Record = {}; + for (const key of Object.keys(value as Record).sort()) { + sorted[key] = sortKeys((value as Record)[key]); + } + return sorted; + } + return value; +} + +// Match Go's encoding/json HTML escaping so output is byte-for-byte identical. +function escapeLikeGo(json: string): string { + return json + .replace(//g, "\\u003e") + .replace(/&/g, "\\u0026") + .replace(new RegExp("\u2028", "g"), "\\u2028") + .replace(new RegExp("\u2029", "g"), "\\u2029"); +} + +function render(): string { + return escapeLikeGo(JSON.stringify(sortKeys(schema), null, 2)) + "\n"; +} + +function main(): void { + const expected = render(); + if (CHECK_MODE) { + const existing = readFileSync(SCHEMA_JSON, "utf-8"); + if (existing !== expected) { + console.error( + "✗ draft/server.schema.json is out of date. Run: npm run generate", + ); + process.exit(1); + } + console.log("✓ draft/server.schema.json is up to date"); + return; + } + writeFileSync(SCHEMA_JSON, expected, "utf-8"); + console.log("✓ Generated draft/server.schema.json"); +} + +main(); diff --git a/docs/reference/server-json/scripts/validate-examples.ts b/docs/reference/server-json/scripts/validate-examples.ts new file mode 100644 index 000000000..342fd54d2 --- /dev/null +++ b/docs/reference/server-json/scripts/validate-examples.ts @@ -0,0 +1,82 @@ +// Validates the example documents under examples/ against the generated +// draft/server.schema.json. Each file under examples/valid must validate +// cleanly; each file under examples/invalid must fail at least one constraint. +// +// Mirrors the experimental Server Card repo's validate-examples.ts. The schema +// is draft-07 (root $ref -> #/definitions/ServerDetail), so it is compiled with +// the default Ajv entrypoint. + +import { readdirSync, readFileSync } from "node:fs"; +import { basename, dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; + +import Ajv from "ajv"; +import addFormats from "ajv-formats"; + +const __dirname = dirname(fileURLToPath(import.meta.url)); +const SCHEMA_JSON = join(__dirname, "..", "draft", "server.schema.json"); +const EXAMPLES_DIR = join(__dirname, "..", "examples"); + +type Outcome = { + name: string; + passed: boolean; + message: string; +}; + +function listJsonFiles(dir: string): string[] { + try { + return readdirSync(dir) + .filter((f) => f.endsWith(".json")) + .sort() + .map((f) => join(dir, f)); + } catch { + return []; + } +} + +function main(): void { + const schema = JSON.parse(readFileSync(SCHEMA_JSON, "utf-8")); + const ajv = new Ajv({ allErrors: true, strict: false }); + addFormats(ajv); + const validate = ajv.compile(schema); + + const outcomes: Outcome[] = []; + for (const expected of ["valid", "invalid"] as const) { + for (const file of listJsonFiles(join(EXAMPLES_DIR, expected))) { + const data = JSON.parse(readFileSync(file, "utf-8")); + const ok = validate(data); + const passed = expected === "valid" ? ok : !ok; + const errors = validate.errors ?? []; + outcomes.push({ + name: `${expected}/${basename(file)}`, + passed, + message: passed + ? expected === "valid" + ? "validated cleanly" + : `rejected (${errors.length} error(s))` + : expected === "valid" + ? `unexpectedly invalid: ${ajv.errorsText(errors)}` + : "unexpectedly valid (no errors raised)", + }); + } + } + + if (outcomes.length === 0) { + console.error(`No examples found under ${EXAMPLES_DIR}/.`); + process.exit(1); + } + + let failed = 0; + for (const o of outcomes) { + console.log(`${o.passed ? "✓" : "✗"} ${o.name} — ${o.message}`); + if (!o.passed) failed++; + } + console.log(); + if (failed > 0) { + console.error(`${failed} of ${outcomes.length} example(s) failed.`); + process.exit(1); + } + console.log(`All ${outcomes.length} example(s) passed.`); +} + +main(); diff --git a/docs/reference/server-json/tsconfig.json b/docs/reference/server-json/tsconfig.json new file mode 100644 index 000000000..923018587 --- /dev/null +++ b/docs/reference/server-json/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "noEmit": true, + "strict": true, + "target": "es2022", + "module": "esnext", + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "types": ["node"] + }, + "include": ["schema.ts", "scripts/**/*.ts"] +} diff --git a/tools/extract-server-schema/main.go b/tools/extract-server-schema/main.go deleted file mode 100644 index a90aa2d6f..000000000 --- a/tools/extract-server-schema/main.go +++ /dev/null @@ -1,197 +0,0 @@ -package main - -import ( - "encoding/json" - "flag" - "fmt" - "log" - "os" - "strings" - - "gopkg.in/yaml.v3" -) - -const ( - openAPIPath = "docs/reference/api/openapi.yaml" - schemaOutputDir = "docs/reference/server-json/draft" -) - -func main() { - var check bool - flag.BoolVar(&check, "check", false, "Check if schema is in sync (exit 1 if not)") - flag.Parse() - - // Read OpenAPI spec - openapiData, err := os.ReadFile(openAPIPath) - if err != nil { - log.Fatalf("Failed to read OpenAPI spec: %v", err) - } - - // Parse YAML - var openapi map[string]interface{} - if err := yaml.Unmarshal(openapiData, &openapi); err != nil { - log.Fatalf("Failed to parse OpenAPI YAML: %v", err) - } - - // Extract version from info section - info, ok := openapi["info"].(map[string]interface{}) - if !ok { - log.Fatal("Missing 'info' in OpenAPI spec") - } - version, ok := info["version"].(string) - if !ok { - log.Fatal("Missing 'info.version' in OpenAPI spec") - } - - // Extract components/schemas - components, ok := openapi["components"].(map[string]interface{}) - if !ok { - log.Fatal("Missing 'components' in OpenAPI spec") - } - - schemas, ok := components["schemas"].(map[string]interface{}) - if !ok { - log.Fatal("Missing 'components/schemas' in OpenAPI spec") - } - - // Extract ServerDetail - serverDetail, ok := schemas["ServerDetail"].(map[string]interface{}) - if !ok { - log.Fatal("Missing 'ServerDetail' schema in OpenAPI spec") - } - - // Auto-discover all schemas referenced by ServerDetail - referencedSchemas := make(map[string]bool) - findReferencedSchemas(serverDetail, referencedSchemas) - - // Build definitions by recursively collecting all referenced schemas - definitions := make(map[string]interface{}) - definitions["ServerDetail"] = serverDetail - - // Keep discovering until we've found all transitively referenced schemas - for { - added := false - for schemaName := range referencedSchemas { - if _, exists := definitions[schemaName]; !exists { - schema, ok := schemas[schemaName] - if !ok { - log.Fatalf("Referenced schema '%s' not found in OpenAPI spec", schemaName) - } - definitions[schemaName] = schema - // Find schemas referenced by this newly added schema - findReferencedSchemas(schema, referencedSchemas) - added = true - } - } - if !added { - break - } - } - - // Build the JSON Schema document with draft URL - // The in-repo schema uses "draft" since it may contain unreleased changes. - // When releasing, the schema is published to a versioned URL (e.g., 2025-10-17) - // on https://github.com/modelcontextprotocol/static - _ = version // version from OpenAPI spec available if needed - schemaID := "https://raw.githubusercontent.com/modelcontextprotocol/registry/main/docs/reference/server-json/draft/server.schema.json" - jsonSchema := map[string]interface{}{ - "$comment": "This file is auto-generated from docs/reference/api/openapi.yaml. Do not edit manually. Run 'make generate-schema' to update.", - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": schemaID, - "title": "server.json defining a Model Context Protocol (MCP) server", - "$ref": "#/definitions/ServerDetail", - "definitions": definitions, - } - - // Replace all #/components/schemas/ references with #/definitions/ - jsonSchema = replaceComponentRefs(jsonSchema).(map[string]interface{}) - - // Convert to JSON - jsonData, err := json.MarshalIndent(jsonSchema, "", " ") - if err != nil { - log.Fatalf("Failed to marshal JSON schema: %v", err) - } - - // Append newline at end - jsonStr := string(jsonData) + "\n" - - outputPath := schemaOutputDir + "/server.schema.json" - - if check { - // Check mode: compare with existing file - existingData, err := os.ReadFile(outputPath) - if err != nil { - fmt.Fprintf(os.Stderr, "Error reading existing schema: %v\n", err) - os.Exit(1) - } - - if string(existingData) != jsonStr { - fmt.Fprintf(os.Stderr, "ERROR: server.schema.json is out of sync with openapi.yaml\n") - fmt.Fprintf(os.Stderr, "Run 'make generate-schema' to update it.\n") - os.Exit(1) - } - - log.Println("✓ server.schema.json is in sync with openapi.yaml") - return - } - - // Write mode: update the file - if err := os.WriteFile(outputPath, []byte(jsonStr), 0644); err != nil { //nolint:gosec // This is a documentation file that should be world-readable - log.Fatalf("Failed to write schema file: %v", err) - } - - log.Printf("✓ Generated %s from %s\n", outputPath, openAPIPath) -} - -// findReferencedSchemas recursively finds all schema names referenced via $ref -func findReferencedSchemas(obj interface{}, found map[string]bool) { - switch v := obj.(type) { - case map[string]interface{}: - for key, value := range v { - if key == "$ref" { - if ref, ok := value.(string); ok { - // Extract schema name from #/components/schemas/SchemaName - if strings.HasPrefix(ref, "#/components/schemas/") { - schemaName := strings.TrimPrefix(ref, "#/components/schemas/") - found[schemaName] = true - } - } - } else { - findReferencedSchemas(value, found) - } - } - case []interface{}: - for _, item := range v { - findReferencedSchemas(item, found) - } - } -} - -// replaceComponentRefs recursively replaces #/components/schemas/ with #/definitions/ -func replaceComponentRefs(obj interface{}) interface{} { - switch v := obj.(type) { - case map[string]interface{}: - result := make(map[string]interface{}) - for key, value := range v { - if key == "$ref" { - if ref, ok := value.(string); ok { - // Replace the reference path - result[key] = strings.ReplaceAll(ref, "#/components/schemas/", "#/definitions/") - } else { - result[key] = value - } - } else { - result[key] = replaceComponentRefs(value) - } - } - return result - case []interface{}: - result := make([]interface{}, len(v)) - for i, item := range v { - result[i] = replaceComponentRefs(item) - } - return result - default: - return obj - } -}