MCPcopy
hub / github.com/codeaashu/claude-code / marketplaceAddHandler

Function marketplaceAddHandler

src/cli/handlers/plugins.ts:447–524  ·  view source on GitHub ↗
(
  source: string,
  options: { cowork?: boolean; sparse?: string[]; scope?: string },
)

Source from the content-addressed store, hash-verified

445
446// marketplace add (lines 5433–5487)
447export async function marketplaceAddHandler(
448 source: string,
449 options: { cowork?: boolean; sparse?: string[]; scope?: string },
450): Promise<void> {
451 if (options.cowork) setUseCoworkPlugins(true)
452 try {
453 const parsed = await parseMarketplaceInput(source)
454
455 if (!parsed) {
456 cliError(
457 `${figures.cross} Invalid marketplace source format. Try: owner/repo, https://..., or ./path`,
458 )
459 }
460
461 if ('error' in parsed) {
462 cliError(`${figures.cross} ${parsed.error}`)
463 }
464
465 // Validate scope
466 const scope = options.scope ?? 'user'
467 if (scope !== 'user' && scope !== 'project' && scope !== 'local') {
468 cliError(
469 `${figures.cross} Invalid scope '${scope}'. Use: user, project, or local`,
470 )
471 }
472 const settingSource = scopeToSettingSource(scope)
473
474 let marketplaceSource = parsed
475
476 if (options.sparse && options.sparse.length > 0) {
477 if (
478 marketplaceSource.source === 'github' ||
479 marketplaceSource.source === 'git'
480 ) {
481 marketplaceSource = {
482 ...marketplaceSource,
483 sparsePaths: options.sparse,
484 }
485 } else {
486 cliError(
487 `${figures.cross} --sparse is only supported for github and git marketplace sources (got: ${marketplaceSource.source})`,
488 )
489 }
490 }
491
492 // biome-ignore lint/suspicious/noConsole:: intentional console output
493 console.log('Adding marketplace...')
494
495 const { name, alreadyMaterialized, resolvedSource } =
496 await addMarketplaceSource(marketplaceSource, message => {
497 // biome-ignore lint/suspicious/noConsole:: intentional console output
498 console.log(message)
499 })
500
501 // Write intent to settings at the requested scope
502 saveMarketplaceToSettings(name, { source: resolvedSource }, settingSource)
503
504 clearAllCaches()

Callers 1

runFunction · 0.85

Calls 10

setUseCoworkPluginsFunction · 0.85
parseMarketplaceInputFunction · 0.85
cliErrorFunction · 0.85
scopeToSettingSourceFunction · 0.85
addMarketplaceSourceFunction · 0.85
clearAllCachesFunction · 0.85
logEventFunction · 0.85
cliOkFunction · 0.85
handleMarketplaceErrorFunction · 0.85

Tested by

no test coverage detected