-
Notifications
You must be signed in to change notification settings - Fork 145
chore: add MCP registry publishing #679
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 all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
cebb0ba
chore: add server.json file the MCP registry
gagik df96544
chore: fix name
gagik 9724f95
chore: import options
gagik 9b4b8d2
chore: docs
gagik ed38888
chore: cleanup
gagik 39d7918
chore: more cleanup
gagik 18e6d27
chore: use binary, use named not positional arguments
gagik ac1e696
chore: format
gagik ce2d6cf
chore: use app-token publishing
gagik e42a448
chore: use token publishing
gagik 2ad52a6
chore: add clarifications
gagik 106e28a
chore: make args optional
gagik 54563a5
chore: remove id-token, move publish step
gagik f7cd64a
chore: use defaults
gagik 8ff4eef
chore: add default to vector and headers, format
gagik a01db62
chore: add voyage api key default
gagik 97c7585
chore: move argument generation to prepare-release
gagik d3b80f5
chore: move to publish job, fix description
gagik 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,233 @@ | ||
| #!/usr/bin/env tsx | ||
|
|
||
| /** | ||
| * This script generates argument definitions and updates: | ||
| * - server.json arrays | ||
| * - TODO: README.md configuration table | ||
| * | ||
| * It uses the Zod schema and OPTIONS defined in src/common/config.ts | ||
| */ | ||
|
|
||
| import { readFileSync, writeFileSync } from "fs"; | ||
| import { join, dirname } from "path"; | ||
| import { fileURLToPath } from "url"; | ||
| import { OPTIONS, UserConfigSchema } from "../src/common/config.js"; | ||
| import type { ZodObject, ZodRawShape } from "zod"; | ||
|
|
||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = dirname(__filename); | ||
|
|
||
| function camelCaseToSnakeCase(str: string): string { | ||
| return str.replace(/[A-Z]/g, (letter) => `_${letter}`).toUpperCase(); | ||
| } | ||
|
|
||
| // List of configuration keys that contain sensitive/secret information | ||
| // These should be redacted in logs and marked as secret in environment variable definitions | ||
| const SECRET_CONFIG_KEYS = new Set([ | ||
| "connectionString", | ||
| "username", | ||
| "password", | ||
| "apiClientId", | ||
| "apiClientSecret", | ||
| "tlsCAFile", | ||
| "tlsCertificateKeyFile", | ||
| "tlsCertificateKeyFilePassword", | ||
| "tlsCRLFile", | ||
| "sslCAFile", | ||
| "sslPEMKeyFile", | ||
| "sslPEMKeyPassword", | ||
| "sslCRLFile", | ||
| "voyageApiKey", | ||
| ]); | ||
|
|
||
| interface EnvironmentVariable { | ||
| name: string; | ||
| description: string; | ||
| isRequired: boolean; | ||
| format: string; | ||
| isSecret: boolean; | ||
| configKey: string; | ||
| defaultValue?: unknown; | ||
| } | ||
|
|
||
| interface ConfigMetadata { | ||
| description: string; | ||
| defaultValue?: unknown; | ||
| } | ||
|
|
||
| function extractZodDescriptions(): Record<string, ConfigMetadata> { | ||
| const result: Record<string, ConfigMetadata> = {}; | ||
|
|
||
| // Get the shape of the Zod schema | ||
| const shape = (UserConfigSchema as ZodObject<ZodRawShape>).shape; | ||
|
|
||
| for (const [key, fieldSchema] of Object.entries(shape)) { | ||
| const schema = fieldSchema; | ||
| // Extract description from Zod schema | ||
| const description = schema.description || `Configuration option: ${key}`; | ||
|
|
||
| // Extract default value if present | ||
| let defaultValue: unknown = undefined; | ||
| if (schema._def && "defaultValue" in schema._def) { | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access | ||
| defaultValue = schema._def.defaultValue() as unknown; | ||
| } | ||
|
|
||
| result[key] = { | ||
| description, | ||
| defaultValue, | ||
| }; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| function generateEnvironmentVariables( | ||
| options: typeof OPTIONS, | ||
| zodMetadata: Record<string, ConfigMetadata> | ||
| ): EnvironmentVariable[] { | ||
| const envVars: EnvironmentVariable[] = []; | ||
| const processedKeys = new Set<string>(); | ||
|
|
||
| // Helper to add env var | ||
| const addEnvVar = (key: string, type: "string" | "number" | "boolean" | "array"): void => { | ||
| if (processedKeys.has(key)) return; | ||
| processedKeys.add(key); | ||
|
|
||
| const envVarName = `MDB_MCP_${camelCaseToSnakeCase(key)}`; | ||
|
|
||
| // Get description and default value from Zod metadata | ||
| const metadata = zodMetadata[key] || { | ||
| description: `Configuration option: ${key}`, | ||
| }; | ||
|
|
||
| // Determine format based on type | ||
| let format = type; | ||
| if (type === "array") { | ||
| format = "string"; // Arrays are passed as comma-separated strings | ||
| } | ||
|
|
||
| envVars.push({ | ||
| name: envVarName, | ||
| description: metadata.description, | ||
| isRequired: false, | ||
| format: format, | ||
| isSecret: SECRET_CONFIG_KEYS.has(key), | ||
| configKey: key, | ||
| defaultValue: metadata.defaultValue, | ||
| }); | ||
| }; | ||
|
|
||
| // Process all string options | ||
| for (const key of options.string) { | ||
| addEnvVar(key, "string"); | ||
| } | ||
|
|
||
| // Process all number options | ||
| for (const key of options.number) { | ||
| addEnvVar(key, "number"); | ||
| } | ||
|
|
||
| // Process all boolean options | ||
| for (const key of options.boolean) { | ||
| addEnvVar(key, "boolean"); | ||
| } | ||
|
|
||
| // Process all array options | ||
| for (const key of options.array) { | ||
| addEnvVar(key, "array"); | ||
| } | ||
|
|
||
| // Sort by name for consistent output | ||
| return envVars.sort((a, b) => a.name.localeCompare(b.name)); | ||
| } | ||
|
|
||
| function generatePackageArguments(envVars: EnvironmentVariable[]): unknown[] { | ||
| const packageArguments: unknown[] = []; | ||
|
|
||
| // Generate positional arguments from the same config options (only documented ones) | ||
| const documentedVars = envVars.filter((v) => !v.description.startsWith("Configuration option:")); | ||
|
|
||
| // Generate named arguments from the same config options | ||
| for (const argument of documentedVars) { | ||
| const arg: Record<string, unknown> = { | ||
| type: "named", | ||
| name: "--" + argument.configKey, | ||
| description: argument.description, | ||
| isRequired: argument.isRequired, | ||
| }; | ||
|
|
||
| // Add format if it's not string (string is the default) | ||
| if (argument.format !== "string") { | ||
| arg.format = argument.format; | ||
| } | ||
|
|
||
| packageArguments.push(arg); | ||
| } | ||
|
|
||
| return packageArguments; | ||
| } | ||
|
|
||
| function updateServerJsonEnvVars(envVars: EnvironmentVariable[]): void { | ||
| const serverJsonPath = join(__dirname, "..", "server.json"); | ||
| const packageJsonPath = join(__dirname, "..", "package.json"); | ||
|
|
||
| const content = readFileSync(serverJsonPath, "utf-8"); | ||
| const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8")) as { version: string }; | ||
| const serverJson = JSON.parse(content) as { | ||
| version?: string; | ||
| packages: { | ||
| registryType?: string; | ||
| identifier?: string; | ||
| environmentVariables: EnvironmentVariable[]; | ||
| packageArguments?: unknown[]; | ||
| version?: string; | ||
| }[]; | ||
| }; | ||
|
|
||
| // Get version from package.json | ||
| const version = packageJson.version; | ||
|
|
||
| // Generate environment variables array (only documented ones) | ||
| const documentedVars = envVars.filter((v) => !v.description.startsWith("Configuration option:")); | ||
| const envVarsArray = documentedVars.map((v) => ({ | ||
| name: v.name, | ||
| description: v.description, | ||
| isRequired: v.isRequired, | ||
| format: v.format, | ||
| isSecret: v.isSecret, | ||
| })); | ||
|
|
||
| // Generate package arguments (named arguments in camelCase) | ||
| const packageArguments = generatePackageArguments(envVars); | ||
|
|
||
| // Update version at root level | ||
| serverJson.version = process.env.VERSION || version; | ||
|
|
||
| // Update environmentVariables, packageArguments, and version for all packages | ||
| if (serverJson.packages && Array.isArray(serverJson.packages)) { | ||
| for (const pkg of serverJson.packages) { | ||
| pkg.environmentVariables = envVarsArray as EnvironmentVariable[]; | ||
| pkg.packageArguments = packageArguments; | ||
| pkg.version = version; | ||
|
|
||
| // Update OCI identifier version tag if this is an OCI package | ||
| if (pkg.registryType === "oci" && pkg.identifier) { | ||
| // Replace the version tag in the OCI identifier (e.g., docker.io/mongodb/mongodb-mcp-server:1.0.0) | ||
| pkg.identifier = pkg.identifier.replace(/:[^:]+$/, `:${version}`); | ||
| } | ||
gagik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| writeFileSync(serverJsonPath, JSON.stringify(serverJson, null, 2) + "\n", "utf-8"); | ||
| console.log(`✓ Updated server.json (version ${version})`); | ||
| } | ||
|
|
||
| function main(): void { | ||
| const zodMetadata = extractZodDescriptions(); | ||
|
|
||
| const envVars = generateEnvironmentVariables(OPTIONS, zodMetadata); | ||
| updateServerJsonEnvVars(envVars); | ||
| } | ||
|
|
||
| main(); | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needed some extra handling but will be great to have in the future.