Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 53 additions & 29 deletions src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,32 @@ program
.command("init [directory]")
.description("Create a new MCPB extension manifest")
.option("-y, --yes", "Accept all defaults (non-interactive mode)")
.action((directory?: string, options?: { yes?: boolean }) => {
void (async () => {
try {
const success = await initExtension(directory, options?.yes);
process.exit(success ? 0 : 1);
} catch (error) {
console.error(
`ERROR: ${error instanceof Error ? error.message : "Unknown error"}`,
);
process.exit(1);
}
})();
});
.option(
"-s, --schema-version <version>",
"Schema version to use (0.1, 0.2, or 0.3)",
)
.action(
(
directory?: string,
options?: { yes?: boolean; schemaVersion?: string },
) => {
void (async () => {
try {
const success = await initExtension(
directory,
options?.yes,
options?.schemaVersion,
);
process.exit(success ? 0 : 1);
} catch (error) {
console.error(
`ERROR: ${error instanceof Error ? error.message : "Unknown error"}`,
);
process.exit(1);
}
})();
},
);

// Validate command
program
Expand All @@ -88,22 +101,33 @@ program
program
.command("pack [directory] [output]")
.description("Pack a directory into an MCPB extension")
.action((directory: string = process.cwd(), output?: string) => {
void (async () => {
try {
const success = await packExtension({
extensionPath: directory,
outputPath: output,
});
process.exit(success ? 0 : 1);
} catch (error) {
console.error(
`ERROR: ${error instanceof Error ? error.message : "Unknown error"}`,
);
process.exit(1);
}
})();
});
.option(
"-s, --schema-version <version>",
"Schema version to use (0.1, 0.2, or 0.3)",
)
.action(
(
directory: string = process.cwd(),
output?: string,
options?: { schemaVersion?: string },
) => {
void (async () => {
try {
const success = await packExtension({
extensionPath: directory,
outputPath: output,
schemaVersion: options?.schemaVersion,
});
process.exit(success ? 0 : 1);
} catch (error) {
console.error(
`ERROR: ${error instanceof Error ? error.message : "Unknown error"}`,
);
process.exit(1);
}
})();
},
);

// Unpack command
program
Expand Down
24 changes: 20 additions & 4 deletions src/cli/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
import { existsSync, readFileSync, writeFileSync } from "fs";
import { basename, join, resolve } from "path";

import { LATEST_MANIFEST_VERSION } from "../shared/constants.js";
import type { McpbManifestLatest } from "../types.js";
import {
DEFAULT_MANIFEST_VERSION,
LATEST_MANIFEST_VERSION,

Check warning on line 7 in src/cli/init.ts

View workflow job for this annotation

GitHub Actions / Test (20.19.x, macos-latest)

'LATEST_MANIFEST_VERSION' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 7 in src/cli/init.ts

View workflow job for this annotation

GitHub Actions / Test (20.19.x, ubuntu-latest)

'LATEST_MANIFEST_VERSION' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 7 in src/cli/init.ts

View workflow job for this annotation

GitHub Actions / Test (22.17.x, ubuntu-latest)

'LATEST_MANIFEST_VERSION' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 7 in src/cli/init.ts

View workflow job for this annotation

GitHub Actions / Test (22.17.x, macos-latest)

'LATEST_MANIFEST_VERSION' is defined but never used. Allowed unused vars must match /^_/u
VALID_MANIFEST_VERSIONS,
} from "../shared/constants.js";
import type { McpbManifest } from "../types.js";

interface PackageJson {
name?: string;
Expand Down Expand Up @@ -878,14 +882,15 @@
resources: string;
default_locale: string;
},
): McpbManifestLatest {
schemaVersion: string = DEFAULT_MANIFEST_VERSION,
): McpbManifest {
const { name, displayName, version, description, authorName } = basicInfo;
const { authorEmail, authorUrl } = authorInfo;
const { serverType, entryPoint, mcp_config } = serverConfig;
const { keywords, license, repository } = optionalFields;

return {
manifest_version: LATEST_MANIFEST_VERSION,
manifest_version: schemaVersion as "0.1" | "0.2" | "0.3",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll probably want to update this so that the contents actually reflect the schema for the particular manifest version (ie, no localization field pre-v0.3)

name,
...(displayName && displayName !== name
? { display_name: displayName }
Expand Down Expand Up @@ -942,6 +947,7 @@
export async function initExtension(
targetPath: string = process.cwd(),
nonInteractive = false,
schemaVersion: string = DEFAULT_MANIFEST_VERSION,
): Promise<boolean> {
const resolvedPath = resolve(targetPath);
const manifestPath = join(resolvedPath, "manifest.json");
Expand Down Expand Up @@ -1011,6 +1017,15 @@
? getDefaultOptionalFields(packageData)
: await promptOptionalFields(packageData);

// Validate schema version
if (!VALID_MANIFEST_VERSIONS.includes(schemaVersion as any)) {

Check failure on line 1021 in src/cli/init.ts

View workflow job for this annotation

GitHub Actions / Test (20.19.x, macos-latest)

Unexpected any. Specify a different type

Check failure on line 1021 in src/cli/init.ts

View workflow job for this annotation

GitHub Actions / Test (20.19.x, ubuntu-latest)

Unexpected any. Specify a different type

Check failure on line 1021 in src/cli/init.ts

View workflow job for this annotation

GitHub Actions / Test (22.17.x, ubuntu-latest)

Unexpected any. Specify a different type

Check failure on line 1021 in src/cli/init.ts

View workflow job for this annotation

GitHub Actions / Test (22.17.x, macos-latest)

Unexpected any. Specify a different type
console.error(`ERROR: Invalid schema version: ${schemaVersion}`);
console.error(
`Valid versions are: ${VALID_MANIFEST_VERSIONS.join(", ")}`,
);
return false;
}

// Build manifest
const manifest = buildManifest(
basicInfo,
Expand All @@ -1027,6 +1042,7 @@
userConfig,
optionalFields,
localization,
schemaVersion,
);

// Write manifest
Expand Down
28 changes: 22 additions & 6 deletions src/cli/pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
import { getAllFilesWithCount, readMcpbIgnorePatterns } from "../node/files.js";
import { validateManifest } from "../node/validate.js";
import {
LATEST_MANIFEST_SCHEMA,
DEFAULT_MANIFEST_VERSION,
LATEST_MANIFEST_VERSION,

Check warning on line 18 in src/cli/pack.ts

View workflow job for this annotation

GitHub Actions / Test (20.19.x, macos-latest)

'LATEST_MANIFEST_VERSION' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 18 in src/cli/pack.ts

View workflow job for this annotation

GitHub Actions / Test (20.19.x, ubuntu-latest)

'LATEST_MANIFEST_VERSION' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 18 in src/cli/pack.ts

View workflow job for this annotation

GitHub Actions / Test (22.17.x, ubuntu-latest)

'LATEST_MANIFEST_VERSION' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 18 in src/cli/pack.ts

View workflow job for this annotation

GitHub Actions / Test (22.17.x, macos-latest)

'LATEST_MANIFEST_VERSION' is defined but never used. Allowed unused vars must match /^_/u
MANIFEST_SCHEMAS,
VALID_MANIFEST_VERSIONS,
} from "../shared/constants.js";
import { getLogger } from "../shared/log.js";
import { initExtension } from "./init.js";
Expand All @@ -24,6 +26,7 @@
extensionPath: string;
outputPath?: string;
silent?: boolean;
schemaVersion?: string;
}

function formatFileSize(bytes: number): string {
Expand Down Expand Up @@ -52,10 +55,20 @@
extensionPath,
outputPath,
silent,
schemaVersion = DEFAULT_MANIFEST_VERSION,
}: PackOptions): Promise<boolean> {
const resolvedPath = resolve(extensionPath);
const logger = getLogger({ silent });

// Validate schema version
if (!VALID_MANIFEST_VERSIONS.includes(schemaVersion as any)) {

Check failure on line 64 in src/cli/pack.ts

View workflow job for this annotation

GitHub Actions / Test (20.19.x, macos-latest)

Unexpected any. Specify a different type

Check failure on line 64 in src/cli/pack.ts

View workflow job for this annotation

GitHub Actions / Test (20.19.x, ubuntu-latest)

Unexpected any. Specify a different type

Check failure on line 64 in src/cli/pack.ts

View workflow job for this annotation

GitHub Actions / Test (22.17.x, ubuntu-latest)

Unexpected any. Specify a different type

Check failure on line 64 in src/cli/pack.ts

View workflow job for this annotation

GitHub Actions / Test (22.17.x, macos-latest)

Unexpected any. Specify a different type
logger.error(`ERROR: Invalid schema version: ${schemaVersion}`);
logger.error(

Check warning on line 66 in src/cli/pack.ts

View workflow job for this annotation

GitHub Actions / Test (20.19.x, macos-latest)

Replace `⏎······`Valid·versions·are:·${VALID_MANIFEST_VERSIONS.join(",·")}`,⏎····` with ``Valid·versions·are:·${VALID_MANIFEST_VERSIONS.join(",·")}``

Check warning on line 66 in src/cli/pack.ts

View workflow job for this annotation

GitHub Actions / Test (20.19.x, ubuntu-latest)

Replace `⏎······`Valid·versions·are:·${VALID_MANIFEST_VERSIONS.join(",·")}`,⏎····` with ``Valid·versions·are:·${VALID_MANIFEST_VERSIONS.join(",·")}``

Check warning on line 66 in src/cli/pack.ts

View workflow job for this annotation

GitHub Actions / Test (22.17.x, ubuntu-latest)

Replace `⏎······`Valid·versions·are:·${VALID_MANIFEST_VERSIONS.join(",·")}`,⏎····` with ``Valid·versions·are:·${VALID_MANIFEST_VERSIONS.join(",·")}``

Check warning on line 66 in src/cli/pack.ts

View workflow job for this annotation

GitHub Actions / Test (22.17.x, macos-latest)

Replace `⏎······`Valid·versions·are:·${VALID_MANIFEST_VERSIONS.join(",·")}`,⏎····` with ``Valid·versions·are:·${VALID_MANIFEST_VERSIONS.join(",·")}``
`Valid versions are: ${VALID_MANIFEST_VERSIONS.join(", ")}`,
);
return false;
}

// Check if directory exists
if (!existsSync(resolvedPath) || !statSync(resolvedPath).isDirectory()) {
logger.error(`ERROR: Directory not found: ${extensionPath}`);
Expand All @@ -72,7 +85,7 @@
});

if (shouldInit) {
const success = await initExtension(extensionPath);
const success = await initExtension(extensionPath, false, schemaVersion);
if (!success) {
logger.error("ERROR: Failed to create manifest");
return false;
Expand All @@ -95,7 +108,10 @@
try {
const manifestContent = readFileSync(manifestPath, "utf-8");
const manifestData = JSON.parse(manifestContent);
manifest = LATEST_MANIFEST_SCHEMA.parse(manifestData);

// Get the schema for the specified version
const schema = MANIFEST_SCHEMAS[schemaVersion as keyof typeof MANIFEST_SCHEMAS];

Check warning on line 113 in src/cli/pack.ts

View workflow job for this annotation

GitHub Actions / Test (20.19.x, macos-latest)

Insert `⏎·····`

Check warning on line 113 in src/cli/pack.ts

View workflow job for this annotation

GitHub Actions / Test (20.19.x, ubuntu-latest)

Insert `⏎·····`

Check warning on line 113 in src/cli/pack.ts

View workflow job for this annotation

GitHub Actions / Test (22.17.x, ubuntu-latest)

Insert `⏎·····`

Check warning on line 113 in src/cli/pack.ts

View workflow job for this annotation

GitHub Actions / Test (22.17.x, macos-latest)

Insert `⏎·····`
manifest = schema.parse(manifestData);
} catch (error) {
logger.error("ERROR: Failed to parse manifest.json");
if (error instanceof Error) {
Expand All @@ -105,12 +121,12 @@
}

const manifestVersion = manifest.manifest_version || manifest.dxt_version;
if (manifestVersion !== LATEST_MANIFEST_VERSION) {
if (manifestVersion !== schemaVersion) {
logger.error(
`ERROR: Manifest version mismatch. Expected "${LATEST_MANIFEST_VERSION}", found "${manifestVersion}"`,
`ERROR: Manifest version mismatch. Expected "${schemaVersion}", found "${manifestVersion}"`,
);
logger.error(
` Please update the manifest_version in your manifest.json to "${LATEST_MANIFEST_VERSION}"`,
` Please update the manifest_version in your manifest.json to "${schemaVersion}"`,
);
return false;
}
Expand Down
25 changes: 24 additions & 1 deletion src/shared/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
import { McpbManifestSchema as CurrentLooseManifestSchema } from "../schemas_loose/latest.js";

/**
* Latest manifest version - the version that new manifests should use
* Default manifest version - the version that new manifests should use
* This is the version that most clients currently support
*/
export const DEFAULT_MANIFEST_VERSION = "0.2" as const;

/**
* Latest manifest version - the newest version of the manifest schema
*/
export const LATEST_MANIFEST_VERSION = "0.3" as const;

Expand All @@ -21,6 +27,13 @@
"0.3": ManifestSchemaV0_3,
} as const;

/**
* Valid manifest versions
*/
export const VALID_MANIFEST_VERSIONS = Object.keys(

Check warning on line 33 in src/shared/constants.ts

View workflow job for this annotation

GitHub Actions / Test (20.19.x, macos-latest)

Replace `⏎··MANIFEST_SCHEMAS,⏎)·as·Array<keyof·typeof·MANIFEST_SCHEMAS` with `MANIFEST_SCHEMAS)·as·Array<⏎··keyof·typeof·MANIFEST_SCHEMAS⏎`

Check warning on line 33 in src/shared/constants.ts

View workflow job for this annotation

GitHub Actions / Test (20.19.x, ubuntu-latest)

Replace `⏎··MANIFEST_SCHEMAS,⏎)·as·Array<keyof·typeof·MANIFEST_SCHEMAS` with `MANIFEST_SCHEMAS)·as·Array<⏎··keyof·typeof·MANIFEST_SCHEMAS⏎`

Check warning on line 33 in src/shared/constants.ts

View workflow job for this annotation

GitHub Actions / Test (22.17.x, ubuntu-latest)

Replace `⏎··MANIFEST_SCHEMAS,⏎)·as·Array<keyof·typeof·MANIFEST_SCHEMAS` with `MANIFEST_SCHEMAS)·as·Array<⏎··keyof·typeof·MANIFEST_SCHEMAS⏎`

Check warning on line 33 in src/shared/constants.ts

View workflow job for this annotation

GitHub Actions / Test (22.17.x, macos-latest)

Replace `⏎··MANIFEST_SCHEMAS,⏎)·as·Array<keyof·typeof·MANIFEST_SCHEMAS` with `MANIFEST_SCHEMAS)·as·Array<⏎··keyof·typeof·MANIFEST_SCHEMAS⏎`
MANIFEST_SCHEMAS,
) as Array<keyof typeof MANIFEST_SCHEMAS>;

/**
* Map of manifest versions to their loose schemas (with passthrough)
*/
Expand All @@ -39,3 +52,13 @@
* Get the latest loose manifest schema based on LATEST_MANIFEST_VERSION
*/
export const LATEST_MANIFEST_SCHEMA_LOOSE = CurrentLooseManifestSchema;

/**
* Get the default manifest schema based on DEFAULT_MANIFEST_VERSION
*/
export const DEFAULT_MANIFEST_SCHEMA = ManifestSchemaV0_2;

/**
* Get the default loose manifest schema based on DEFAULT_MANIFEST_VERSION
*/
export const DEFAULT_MANIFEST_SCHEMA_LOOSE = LooseManifestSchemaV0_2;
Loading