MCPcopy Create free account
hub / github.com/Noumena-Network/code / uninstallPluginOp

Function uninstallPluginOp

src/services/plugins/pluginOperations.ts:428–560  ·  view source on GitHub ↗
(
  plugin: string,
  scope: InstallableScope = 'user',
  deleteDataDir = true,
)

Source from the content-addressed store, hash-verified

426 * @returns Result indicating success/failure
427 */
428export async function uninstallPluginOp(
429 plugin: string,
430 scope: InstallableScope = 'user',
431 deleteDataDir = true,
432): Promise<PluginOperationResult> {
433 // Validate scope at runtime for early error detection
434 assertInstallableScope(scope)
435
436 const { enabled, disabled } = await loadAllPlugins()
437 const allPlugins = [...enabled, ...disabled]
438
439 // Find the plugin
440 const foundPlugin = findPluginByIdentifier(plugin, allPlugins)
441
442 const settingSource = scopeToSettingSource(scope)
443 const settings = getSettingsForSource(settingSource)
444
445 let pluginId: string
446 let pluginName: string
447
448 if (foundPlugin) {
449 // Find the matching settings key for this plugin (may differ from `plugin`
450 // if user gave short name but settings has plugin@marketplace)
451 pluginId =
452 Object.keys(settings?.enabledPlugins ?? {}).find(
453 k =>
454 k === plugin ||
455 k === foundPlugin.name ||
456 k.startsWith(`${foundPlugin.name}@`),
457 ) ?? (plugin.includes('@') ? plugin : foundPlugin.name)
458 pluginName = foundPlugin.name
459 } else {
460 // Plugin not found via marketplace lookup — it may have been delisted.
461 // Fall back to installed_plugins.json (V2) which tracks installations
462 // independently of marketplace state.
463 const resolved = resolveDelistedPluginId(plugin)
464 if (!resolved) {
465 return {
466 success: false,
467 message: `Plugin "${plugin}" not found in installed plugins`,
468 }
469 }
470 pluginId = resolved.pluginId
471 pluginName = resolved.pluginName
472 }
473
474 // Check if the plugin is installed in this scope (in V2 file)
475 const projectPath = getProjectPathForScope(scope)
476 const installedData = loadInstalledPluginsV2()
477 const installations = installedData.plugins[pluginId]
478 const scopeInstallation = installations?.find(
479 i => i.scope === scope && i.projectPath === projectPath,
480 )
481
482 if (!scopeInstallation) {
483 // Try to find where the plugin is actually installed to provide a helpful error
484 const { scope: actualScope } = getPluginInstallationFromV2(pluginId)
485 if (actualScope !== scope && installations && installations.length > 0) {

Callers 5

handleSingleOperationFunction · 0.85
ManagePluginsFunction · 0.85
doUninstallFunction · 0.85
uninstallPluginFunction · 0.85

Calls 15

assertInstallableScopeFunction · 0.85
loadAllPluginsFunction · 0.85
findPluginByIdentifierFunction · 0.85
scopeToSettingSourceFunction · 0.85
getSettingsForSourceFunction · 0.85
resolveDelistedPluginIdFunction · 0.85
getProjectPathForScopeFunction · 0.85
loadInstalledPluginsV2Function · 0.85
clearAllCachesFunction · 0.85
removePluginInstallationFunction · 0.85

Tested by

no test coverage detected