MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / loadMcpbFile

Function loadMcpbFile

source code/utils/plugins/mcpbHandler.ts:700–970  ·  view source on GitHub ↗
(
  source: string,
  pluginPath: string,
  pluginId: string,
  onProgress?: ProgressCallback,
  providedUserConfig?: UserConfigValues,
  forceConfigDialog?: boolean,
)

Source from the content-addressed store, hash-verified

698 * @returns Success with MCP config, or needs-config status with schema
699 */
700export async function loadMcpbFile(
701 source: string,
702 pluginPath: string,
703 pluginId: string,
704 onProgress?: ProgressCallback,
705 providedUserConfig?: UserConfigValues,
706 forceConfigDialog?: boolean,
707): Promise<McpbLoadResult | McpbNeedsConfigResult> {
708 const fs = getFsImplementation()
709 const cacheDir = getMcpbCacheDir(pluginPath)
710 await fs.mkdir(cacheDir)
711
712 logForDebugging(`Loading MCPB from source: ${source}`)
713
714 // Check cache first
715 const metadata = await loadCacheMetadata(cacheDir, source)
716 if (metadata && !(await checkMcpbChanged(source, pluginPath))) {
717 logForDebugging(
718 `Using cached MCPB from ${metadata.extractedPath} (hash: ${metadata.contentHash})`,
719 )
720
721 // Load manifest from cache
722 const manifestPath = join(metadata.extractedPath, 'manifest.json')
723 let manifestContent: string
724 try {
725 manifestContent = await fs.readFile(manifestPath, { encoding: 'utf-8' })
726 } catch (error) {
727 if (isENOENT(error)) {
728 const err = new Error(`Cached manifest not found: ${manifestPath}`)
729 logError(err)
730 throw err
731 }
732 throw error
733 }
734
735 const manifestData = new TextEncoder().encode(manifestContent)
736 const manifest = await parseAndValidateManifestFromBytes(manifestData)
737
738 // Check for user_config requirement
739 if (manifest.user_config && Object.keys(manifest.user_config).length > 0) {
740 // Server name from DXT manifest
741 const serverName = manifest.name
742
743 // Try to load existing config from settings.json or use provided config
744 const savedConfig = loadMcpServerUserConfig(pluginId, serverName)
745 const userConfig = providedUserConfig || savedConfig || {}
746
747 // Validate we have all required fields
748 const validation = validateUserConfig(userConfig, manifest.user_config)
749
750 // Return needs-config if: forced (reconfiguration) OR validation failed
751 if (forceConfigDialog || !validation.valid) {
752 return {
753 status: 'needs-config',
754 manifest,
755 extractedPath: metadata.extractedPath,
756 contentHash: metadata.contentHash,
757 configSchema: manifest.user_config,

Callers 3

loadMcpServersFromMcpbFunction · 0.85
ManagePluginsFunction · 0.85
handleSaveFunction · 0.85

Calls 15

getFsImplementationFunction · 0.85
getMcpbCacheDirFunction · 0.85
logForDebuggingFunction · 0.85
loadCacheMetadataFunction · 0.85
checkMcpbChangedFunction · 0.85
isENOENTFunction · 0.85
loadMcpServerUserConfigFunction · 0.85
saveMcpServerUserConfigFunction · 0.85
generateMcpConfigFunction · 0.85
isUrlFunction · 0.85
downloadMcpbFunction · 0.85

Tested by

no test coverage detected