-
Notifications
You must be signed in to change notification settings - Fork 2
Add upstream registry schema documentation #465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
28480c3
Add upstream registry schema
danbarr bbe0db0
Split the server object schema out for readability
danbarr d410537
Add setup step to update workflow
danbarr 5c2fd5d
Override JSON schema viewer styles for neutral appearance
danbarr d34b3a0
Add links to the registry JSON schemas
danbarr 6e43fcc
Add redirect
danbarr bd5da47
Run npm audit fix
danbarr 2989e33
Address Copilot review
danbarr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| --- | ||
| title: Upstream registry JSON schema | ||
| description: The JSON schema for the official upstream MCP registry format. | ||
| displayed_sidebar: toolhiveSidebar | ||
| --- | ||
|
|
||
| import JSONSchemaViewer from '@theme/JSONSchemaViewer'; | ||
| import RegistrySchema from '@site/static/api-specs/upstream-registry.schema.json'; | ||
| import McpServerSchema from '@site/static/api-specs/mcp-server.schema.json'; | ||
|
|
||
| This is the JSON schema for the official upstream MCP registry format. It | ||
| defines the structure and constraints for registry entries, ensuring that all | ||
| entries conform to a consistent format. The registry wraps the official MCP | ||
| server schema, which is documented separately below. | ||
|
|
||
| :::info | ||
|
|
||
| ToolHive also supports the | ||
| [ToolHive-native registry format](./registry-schema-toolhive.mdx), which is used | ||
| by the built-in registry. Both formats work with custom file-based registries | ||
| and the ToolHive Registry Server. | ||
|
|
||
| ::: | ||
|
|
||
| To use this schema in your own custom registry file, add a `$schema` property at | ||
| the top of your JSON file: | ||
|
|
||
| ```json | ||
| { | ||
| "$schema": "https://raw.githubusercontent.com/stacklok/toolhive/main/pkg/registry/data/upstream-registry.schema.json", | ||
| ... | ||
| } | ||
| ``` | ||
|
|
||
| ## Registry schema | ||
|
|
||
| <JSONSchemaViewer schema={RegistrySchema} /> | ||
|
|
||
| ## MCP server object schema | ||
|
|
||
| The `servers` array in the registry contains objects that conform to the | ||
| official MCP server schema: | ||
|
|
||
| <JSONSchemaViewer schema={McpServerSchema} /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| #!/usr/bin/env node | ||
| // SPDX-FileCopyrightText: Copyright 2025 Stacklok, Inc. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| /** | ||
| * This script dereferences the upstream registry schema, resolving all $ref | ||
| * references (including remote ones) into a single bundled schema file. | ||
| * | ||
| * It also fetches and dereferences the official MCP server schema separately | ||
| * for improved rendering on the documentation page. The MCP server schema URL | ||
| * is extracted from the $ref in the upstream registry schema. | ||
| * | ||
| * This is necessary because the upstream schema references the official MCP | ||
| * server schema, which contains internal $ref references that the JSON Schema | ||
| * Viewer plugin cannot resolve at runtime. | ||
| */ | ||
|
|
||
| import { readFileSync, writeFileSync } from 'fs'; | ||
| import { dirname, join } from 'path'; | ||
| import { fileURLToPath } from 'url'; | ||
| import $RefParser from '@apidevtools/json-schema-ref-parser'; | ||
|
|
||
| const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
| const STATIC_DIR = join(__dirname, '..', 'static', 'api-specs'); | ||
|
|
||
| const REGISTRY_SCHEMA = join(STATIC_DIR, 'upstream-registry.schema.json'); | ||
| const MCP_SERVER_SCHEMA = join(STATIC_DIR, 'mcp-server.schema.json'); | ||
|
|
||
| /** | ||
| * Extract the MCP server schema URL from the upstream registry schema. | ||
| * Looks for $ref in data.properties.servers.items. | ||
| */ | ||
| function extractMcpServerUrl(registrySchemaPath) { | ||
| const schema = JSON.parse(readFileSync(registrySchemaPath, 'utf-8')); | ||
| const ref = schema?.properties?.data?.properties?.servers?.items?.$ref; | ||
|
|
||
| if (!ref || !ref.startsWith('http')) { | ||
| throw new Error( | ||
| 'Could not find MCP server schema $ref in upstream registry schema' | ||
| ); | ||
| } | ||
|
|
||
| return ref; | ||
| } | ||
|
|
||
| /** | ||
| * Replace the MCP server $ref in the registry with a placeholder that directs | ||
| * readers to the separate MCP server schema section. | ||
| */ | ||
| function simplifyRegistrySchema(schema, mcpServerUrl) { | ||
| const serverPlaceholder = { | ||
| type: 'object', | ||
| description: `MCP server object (see MCP server object schema section below). Source: ${mcpServerUrl}`, | ||
| }; | ||
|
|
||
| // Replace servers.items $ref | ||
| if (schema?.properties?.data?.properties?.servers?.items) { | ||
| schema.properties.data.properties.servers.items = serverPlaceholder; | ||
| } | ||
|
|
||
| // Replace groups.items.properties.servers.items $ref if present | ||
| if ( | ||
| schema?.properties?.data?.properties?.groups?.items?.properties?.servers | ||
| ?.items | ||
| ) { | ||
| schema.properties.data.properties.groups.items.properties.servers.items = | ||
| serverPlaceholder; | ||
| } | ||
|
|
||
| return schema; | ||
| } | ||
|
|
||
| async function main() { | ||
| try { | ||
| const mcpServerUrl = extractMcpServerUrl(REGISTRY_SCHEMA); | ||
|
|
||
| // Simplify registry schema by replacing $refs with placeholders | ||
| const registrySchema = JSON.parse(readFileSync(REGISTRY_SCHEMA, 'utf-8')); | ||
| const simplifiedSchema = simplifyRegistrySchema( | ||
| registrySchema, | ||
| mcpServerUrl | ||
| ); | ||
| writeFileSync(REGISTRY_SCHEMA, JSON.stringify(simplifiedSchema, null, 2)); | ||
| echo('Upstream registry schema processed successfully'); | ||
|
|
||
| // Fetch and dereference the MCP server schema | ||
| const mcpServerSchema = await $RefParser.dereference(mcpServerUrl); | ||
| writeFileSync(MCP_SERVER_SCHEMA, JSON.stringify(mcpServerSchema, null, 2)); | ||
| echo('MCP server schema fetched successfully'); | ||
| } catch (error) { | ||
| console.error('Failed to process schemas:', error.message); | ||
| process.exit(1); | ||
| } | ||
| } | ||
|
|
||
| function echo(msg) { | ||
| console.log(msg); | ||
| } | ||
|
|
||
| main(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.