Merge pull request #172 from modelcontextprotocol/feat/init-manifest-version-option

feat: add --manifest-version option to init command
This commit is contained in:
joan-anthropic 2025-12-03 21:32:27 -08:00 • committed by GitHub
commit 27083dcf93
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 46 additions and 20 deletions

View file

@ -51,19 +51,32 @@ program
.command("init [directory]") .command("init [directory]")
.description("Create a new MCPB extension manifest") .description("Create a new MCPB extension manifest")
.option("-y, --yes", "Accept all defaults (non-interactive mode)") .option("-y, --yes", "Accept all defaults (non-interactive mode)")
.action((directory?: string, options?: { yes?: boolean }) => { .option(
void (async () => { "--manifest-version <version>",
try { "Manifest version to use in the generated manifest",
const success = await initExtension(directory, options?.yes); )
process.exit(success ? 0 : 1); .action(
} catch (error) { (
console.error( directory?: string,
`ERROR: ${error instanceof Error ? error.message : "Unknown error"}`, options?: { yes?: boolean; manifestVersion?: string },
); ) => {
process.exit(1); void (async () => {
} try {
})(); const success = await initExtension(
}); directory,
options?.yes,
options?.manifestVersion,
);
process.exit(success ? 0 : 1);
} catch (error) {
console.error(
`ERROR: ${error instanceof Error ? error.message : "Unknown error"}`,
);
process.exit(1);
}
})();
},
);
// Validate command // Validate command
program program

View file

@ -1,12 +1,12 @@
import { confirm, input, select } from "@inquirer/prompts"; import { confirm, input, select } from "@inquirer/prompts";
import { existsSync, readFileSync, writeFileSync } from "fs"; import { existsSync, readFileSync, writeFileSync } from "fs";
import { basename, join, resolve } from "path"; import { basename, join, resolve } from "path";
import type { z } from "zod";
// Import the schema for DEFAULT_MANIFEST_VERSION import {
// TODO: Allow dynamic manifest version choice DEFAULT_MANIFEST_VERSION,
import type { McpbManifestSchema } from "../schemas/0.2.js"; MANIFEST_SCHEMAS,
import { DEFAULT_MANIFEST_VERSION } from "../shared/constants.js"; } from "../shared/constants.js";
import type { McpbManifestAny } from "../types.js";
interface PackageJson { interface PackageJson {
name?: string; name?: string;
@ -877,18 +877,19 @@ export function buildManifest(
license: string; license: string;
repository?: { type: string; url: string }; repository?: { type: string; url: string };
}, },
manifestVersion: keyof typeof MANIFEST_SCHEMAS = DEFAULT_MANIFEST_VERSION,
// localization?: { // localization?: {
// resources: string; // resources: string;
// default_locale: string; // default_locale: string;
// }, // },
): z.infer<typeof McpbManifestSchema> { ): McpbManifestAny {
const { name, displayName, version, description, authorName } = basicInfo; const { name, displayName, version, description, authorName } = basicInfo;
const { authorEmail, authorUrl } = authorInfo; const { authorEmail, authorUrl } = authorInfo;
const { serverType, entryPoint, mcp_config } = serverConfig; const { serverType, entryPoint, mcp_config } = serverConfig;
const { keywords, license, repository } = optionalFields; const { keywords, license, repository } = optionalFields;
return { return {
manifest_version: DEFAULT_MANIFEST_VERSION, manifest_version: manifestVersion,
name, name,
...(displayName && displayName !== name ...(displayName && displayName !== name
? { display_name: displayName } ? { display_name: displayName }
@ -945,10 +946,21 @@ export function printNextSteps() {
export async function initExtension( export async function initExtension(
targetPath: string = process.cwd(), targetPath: string = process.cwd(),
nonInteractive = false, nonInteractive = false,
manifestVersion?: string,
): Promise<boolean> { ): Promise<boolean> {
const resolvedPath = resolve(targetPath); const resolvedPath = resolve(targetPath);
const manifestPath = join(resolvedPath, "manifest.json"); const manifestPath = join(resolvedPath, "manifest.json");
// Validate manifest version if provided
if (manifestVersion && !(manifestVersion in MANIFEST_SCHEMAS)) {
console.error(
`ERROR: Invalid manifest version "${manifestVersion}". Supported versions: ${Object.keys(MANIFEST_SCHEMAS).join(", ")}`,
);
return false;
}
const effectiveManifestVersion = (manifestVersion ||
DEFAULT_MANIFEST_VERSION) as keyof typeof MANIFEST_SCHEMAS;
if (existsSync(manifestPath)) { if (existsSync(manifestPath)) {
if (nonInteractive) { if (nonInteractive) {
console.log( console.log(
@ -1029,6 +1041,7 @@ export async function initExtension(
compatibility, compatibility,
userConfig, userConfig,
optionalFields, optionalFields,
effectiveManifestVersion,
); );
// Write manifest // Write manifest