MCPcopy Index your code
hub / github.com/codeaashu/claude-code / loadMcpServersFromMcpb

Function loadMcpServersFromMcpb

src/utils/plugins/mcpPluginIntegration.ts:34–124  ·  view source on GitHub ↗

* Load MCP servers from an MCPB file * Handles downloading, extracting, and converting DXT manifest to MCP config

(
  plugin: LoadedPlugin,
  mcpbPath: string,
  errors: PluginError[],
)

Source from the content-addressed store, hash-verified

32 * Handles downloading, extracting, and converting DXT manifest to MCP config
33 */
34async function loadMcpServersFromMcpb(
35 plugin: LoadedPlugin,
36 mcpbPath: string,
37 errors: PluginError[],
38): Promise<Record<string, McpServerConfig> | null> {
39 try {
40 logForDebugging(`Loading MCP servers from MCPB: ${mcpbPath}`)
41
42 // Use plugin.repository directly - it's already in "plugin@marketplace" format
43 const pluginId = plugin.repository
44
45 const result = await loadMcpbFile(
46 mcpbPath,
47 plugin.path,
48 pluginId,
49 status => {
50 logForDebugging(`MCPB [${plugin.name}]: ${status}`)
51 },
52 )
53
54 // Check if MCPB needs user configuration
55 if ('status' in result && result.status === 'needs-config') {
56 // User config needed - this is normal for unconfigured plugins
57 // Don't load the MCP server yet - user can configure via /plugin menu
58 logForDebugging(
59 `MCPB ${mcpbPath} requires user configuration. ` +
60 `User can configure via: /plugin → Manage plugins → ${plugin.name} → Configure`,
61 )
62 // Return null to skip this server for now (not an error)
63 return null
64 }
65
66 // Type guard passed - result is success type
67 const successResult = result as McpbLoadResult
68
69 // Use the DXT manifest name as the server name
70 const serverName = successResult.manifest.name
71
72 // Check for server name conflicts with existing servers
73 // This will be checked later when merging all servers, but we log here for debugging
74 logForDebugging(
75 `Loaded MCP server "${serverName}" from MCPB (extracted to ${successResult.extractedPath})`,
76 )
77
78 return { [serverName]: successResult.mcpConfig }
79 } catch (error) {
80 const errorMsg = errorMessage(error)
81 logForDebugging(`Failed to load MCPB ${mcpbPath}: ${errorMsg}`, {
82 level: 'error',
83 })
84
85 // Use plugin@repository as source (consistent with other plugin errors)
86 const source = `${plugin.name}@${plugin.repository}`
87
88 // Determine error type based on error message
89 const isUrl = mcpbPath.startsWith('http')
90 if (
91 isUrl &&

Callers 1

loadPluginMcpServersFunction · 0.85

Calls 4

logForDebuggingFunction · 0.85
loadMcpbFileFunction · 0.85
errorMessageFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected