Skip to content

Commit 761e834

Browse files
feat: add --manifest-version option to init command
Allow developers to specify which manifest version to use when initializing a new manifest.json file. Usage: mcpb init --manifest-version 0.3 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 3635e20 commit 761e834

File tree

2 files changed

+43
-20
lines changed

2 files changed

+43
-20
lines changed

src/cli/cli.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,29 @@ program
5151
.command("init [directory]")
5252
.description("Create a new MCPB extension manifest")
5353
.option("-y, --yes", "Accept all defaults (non-interactive mode)")
54-
.action((directory?: string, options?: { yes?: boolean }) => {
55-
void (async () => {
56-
try {
57-
const success = await initExtension(directory, options?.yes);
58-
process.exit(success ? 0 : 1);
59-
} catch (error) {
60-
console.error(
61-
`ERROR: ${error instanceof Error ? error.message : "Unknown error"}`,
62-
);
63-
process.exit(1);
64-
}
65-
})();
66-
});
54+
.option(
55+
"--manifest-version <version>",
56+
"Manifest version to use in the generated manifest",
57+
)
58+
.action(
59+
(directory?: string, options?: { yes?: boolean; manifestVersion?: string }) => {
60+
void (async () => {
61+
try {
62+
const success = await initExtension(
63+
directory,
64+
options?.yes,
65+
options?.manifestVersion,
66+
);
67+
process.exit(success ? 0 : 1);
68+
} catch (error) {
69+
console.error(
70+
`ERROR: ${error instanceof Error ? error.message : "Unknown error"}`,
71+
);
72+
process.exit(1);
73+
}
74+
})();
75+
},
76+
);
6777

6878
// Validate command
6979
program

src/cli/init.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { confirm, input, select } from "@inquirer/prompts";
22
import { existsSync, readFileSync, writeFileSync } from "fs";
33
import { basename, join, resolve } from "path";
4-
import type { z } from "zod";
54

6-
// Import the schema for DEFAULT_MANIFEST_VERSION
7-
// TODO: Allow dynamic manifest version choice
8-
import type { McpbManifestSchema } from "../schemas/0.2.js";
9-
import { DEFAULT_MANIFEST_VERSION } from "../shared/constants.js";
5+
import {
6+
DEFAULT_MANIFEST_VERSION,
7+
MANIFEST_SCHEMAS,
8+
} from "../shared/constants.js";
9+
import type { McpbManifestAny } from "../types.js";
1010

1111
interface PackageJson {
1212
name?: string;
@@ -877,18 +877,19 @@ export function buildManifest(
877877
license: string;
878878
repository?: { type: string; url: string };
879879
},
880+
manifestVersion: keyof typeof MANIFEST_SCHEMAS = DEFAULT_MANIFEST_VERSION,
880881
// localization?: {
881882
// resources: string;
882883
// default_locale: string;
883884
// },
884-
): z.infer<typeof McpbManifestSchema> {
885+
): McpbManifestAny {
885886
const { name, displayName, version, description, authorName } = basicInfo;
886887
const { authorEmail, authorUrl } = authorInfo;
887888
const { serverType, entryPoint, mcp_config } = serverConfig;
888889
const { keywords, license, repository } = optionalFields;
889890

890891
return {
891-
manifest_version: DEFAULT_MANIFEST_VERSION,
892+
manifest_version: manifestVersion,
892893
name,
893894
...(displayName && displayName !== name
894895
? { display_name: displayName }
@@ -945,10 +946,21 @@ export function printNextSteps() {
945946
export async function initExtension(
946947
targetPath: string = process.cwd(),
947948
nonInteractive = false,
949+
manifestVersion?: string,
948950
): Promise<boolean> {
949951
const resolvedPath = resolve(targetPath);
950952
const manifestPath = join(resolvedPath, "manifest.json");
951953

954+
// Validate manifest version if provided
955+
if (manifestVersion && !(manifestVersion in MANIFEST_SCHEMAS)) {
956+
console.error(
957+
`ERROR: Invalid manifest version "${manifestVersion}". Supported versions: ${Object.keys(MANIFEST_SCHEMAS).join(", ")}`,
958+
);
959+
return false;
960+
}
961+
const effectiveManifestVersion = (manifestVersion ||
962+
DEFAULT_MANIFEST_VERSION) as keyof typeof MANIFEST_SCHEMAS;
963+
952964
if (existsSync(manifestPath)) {
953965
if (nonInteractive) {
954966
console.log(
@@ -1029,6 +1041,7 @@ export async function initExtension(
10291041
compatibility,
10301042
userConfig,
10311043
optionalFields,
1044+
effectiveManifestVersion,
10321045
);
10331046

10341047
// Write manifest

0 commit comments

Comments
 (0)