MCPcopy Create free account
hub / github.com/modelcontextprotocol/mcpb / packExtension

Function packExtension

src/cli/pack.ts:49–254  ·  view source on GitHub ↗
({
  extensionPath,
  outputPath,
  silent,
}: PackOptions)

Source from the content-addressed store, hash-verified

47}
48
49export async function packExtension({
50 extensionPath,
51 outputPath,
52 silent,
53}: PackOptions): Promise<boolean> {
54 const resolvedPath = resolve(extensionPath);
55 const logger = getLogger({ silent });
56
57 // Check if directory exists
58 if (!existsSync(resolvedPath) || !statSync(resolvedPath).isDirectory()) {
59 logger.error(`ERROR: Directory not found: ${extensionPath}`);
60 return false;
61 }
62
63 // Check if manifest exists
64 const manifestPath = join(resolvedPath, "manifest.json");
65 if (!existsSync(manifestPath)) {
66 logger.log(`No manifest.json found in ${extensionPath}`);
67 const shouldInit = await confirm({
68 message: "Would you like to create a manifest.json file?",
69 default: true,
70 });
71
72 if (shouldInit) {
73 const success = await initExtension(extensionPath);
74 if (!success) {
75 logger.error("ERROR: Failed to create manifest");
76 return false;
77 }
78 } else {
79 logger.error("ERROR: Cannot pack extension without manifest.json");
80 return false;
81 }
82 }
83
84 // Validate manifest first
85 logger.log("Validating manifest...");
86 if (!validateManifest(manifestPath)) {
87 logger.error("ERROR: Cannot pack extension with invalid manifest");
88 return false;
89 }
90
91 // Read and parse manifest
92 let manifest;
93 try {
94 const manifestContent = readFileSync(manifestPath, "utf-8");
95 const manifestData = JSON.parse(manifestContent);
96 const manifestVersion = getManifestVersionFromRawData(manifestData);
97 if (!manifestVersion) {
98 logger.error(
99 `ERROR: Manifest version mismatch. Expected "${Object.keys(MANIFEST_SCHEMAS).join(" or ")}", found "${manifestVersion}"`,
100 );
101 logger.error(
102 ` Please update the manifest_version in your manifest.json to a supported version`,
103 );
104 return false;
105 }
106

Callers 2

cli.tsFile · 0.85
cleanMcpbFunction · 0.85

Calls 8

getLoggerFunction · 0.85
initExtensionFunction · 0.85
validateManifestFunction · 0.85
readMcpbIgnorePatternsFunction · 0.85
getAllFilesWithCountFunction · 0.85
formatFileSizeFunction · 0.85
sanitizeNameForFilenameFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…