-
Couldn't load subscription status.
- Fork 149
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
Changes from 11 commits
cebb0ba
df96544
9724f95
9b4b8d2
ed38888
39d7918
18e6d27
ac1e696
ce2d6cf
e42a448
2ad52a6
106e28a
54563a5
f7cd64a
8ff4eef
a01db62
97c7585
d3b80f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,11 @@ jobs: | |
| RELEASE_CHANNEL: ${{ steps.npm-tag.outputs.RELEASE_CHANNEL }} | ||
| steps: | ||
| - uses: GitHubSecurityLab/actions-permissions/monitor@v1 | ||
| - uses: mongodb-js/devtools-shared/actions/setup-bot-token@main | ||
| id: app-token | ||
| with: | ||
| app-id: ${{ vars.DEVTOOLS_BOT_APP_ID }} | ||
| private-key: ${{ secrets.DEVTOOLS_BOT_PRIVATE_KEY }} | ||
| - uses: actions/checkout@v5 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
@@ -75,6 +80,7 @@ jobs: | |
| environment: Production | ||
| permissions: | ||
| contents: write | ||
| id-token: write # Required for OIDC authentication with MCP Registry | ||
gagik marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| needs: | ||
| - check | ||
| if: needs.check.outputs.VERSION_EXISTS == 'false' | ||
|
|
@@ -95,6 +101,23 @@ jobs: | |
| run: npm publish --tag ${{ needs.check.outputs.RELEASE_CHANNEL }} | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
|
|
||
| - name: Update server.json version and arguments | ||
|
||
| run: | | ||
| VERSION="${{ needs.check.outputs.VERSION }}" | ||
| VERSION="${VERSION#v}" | ||
| npm run generate:arguments | ||
|
|
||
| - name: Install MCP Publisher | ||
| run: | | ||
| curl -L "https://github.com/modelcontextprotocol/registry/releases/latest/download/mcp-publisher_$(uname -s | tr '[:upper:]' '[:lower:]')_$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/').tar.gz" | tar xz mcp-publisher | ||
|
|
||
| - name: Login to MCP Registry | ||
| run: ./mcp-publisher login github --token ${{ steps.app-token.outputs.token }} | ||
|
|
||
| - name: Publish to MCP Registry | ||
| run: ./mcp-publisher publish | ||
|
|
||
| - name: Publish git release | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
|
|
||
| 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| * | ||
| * 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(); | ||
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.
Is this in the wrong job?
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.
is it? seems to be the way we get the token everywhere
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.
You're adding this to the
checkjob, but seems like you're trying to use it in thepublishjob. Step outputs cannot be passed across jobs.