|
1 | 1 | import { confirm, input, select } from "@inquirer/prompts"; |
2 | 2 | import { existsSync, readFileSync, writeFileSync } from "fs"; |
3 | 3 | import { basename, join, resolve } from "path"; |
4 | | -import type { z } from "zod"; |
5 | 4 |
|
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"; |
10 | 10 |
|
11 | 11 | interface PackageJson { |
12 | 12 | name?: string; |
@@ -877,18 +877,19 @@ export function buildManifest( |
877 | 877 | license: string; |
878 | 878 | repository?: { type: string; url: string }; |
879 | 879 | }, |
| 880 | + manifestVersion: keyof typeof MANIFEST_SCHEMAS = DEFAULT_MANIFEST_VERSION, |
880 | 881 | // localization?: { |
881 | 882 | // resources: string; |
882 | 883 | // default_locale: string; |
883 | 884 | // }, |
884 | | -): z.infer<typeof McpbManifestSchema> { |
| 885 | +): McpbManifestAny { |
885 | 886 | const { name, displayName, version, description, authorName } = basicInfo; |
886 | 887 | const { authorEmail, authorUrl } = authorInfo; |
887 | 888 | const { serverType, entryPoint, mcp_config } = serverConfig; |
888 | 889 | const { keywords, license, repository } = optionalFields; |
889 | 890 |
|
890 | 891 | return { |
891 | | - manifest_version: DEFAULT_MANIFEST_VERSION, |
| 892 | + manifest_version: manifestVersion, |
892 | 893 | name, |
893 | 894 | ...(displayName && displayName !== name |
894 | 895 | ? { display_name: displayName } |
@@ -945,10 +946,21 @@ export function printNextSteps() { |
945 | 946 | export async function initExtension( |
946 | 947 | targetPath: string = process.cwd(), |
947 | 948 | nonInteractive = false, |
| 949 | + manifestVersion?: string, |
948 | 950 | ): Promise<boolean> { |
949 | 951 | const resolvedPath = resolve(targetPath); |
950 | 952 | const manifestPath = join(resolvedPath, "manifest.json"); |
951 | 953 |
|
| 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 | + |
952 | 964 | if (existsSync(manifestPath)) { |
953 | 965 | if (nonInteractive) { |
954 | 966 | console.log( |
@@ -1029,6 +1041,7 @@ export async function initExtension( |
1029 | 1041 | compatibility, |
1030 | 1042 | userConfig, |
1031 | 1043 | optionalFields, |
| 1044 | + effectiveManifestVersion, |
1032 | 1045 | ); |
1033 | 1046 |
|
1034 | 1047 | // Write manifest |
|
0 commit comments