basant307/AI_Governance_Project
048
1/**2 * @license3 * Copyright 2025 Google LLC4 * SPDX-License-Identifier: Apache-2.05 */6 7// File for 'qwen mcp remove' command8import type { CommandModule } from 'yargs';9import { loadSettings, SettingScope } from '../../config/settings.js';10import { writeStdoutLine } from '../../utils/stdioHelpers.js';11import { MCPOAuthTokenStorage } from '@qwen-code/qwen-code-core';12 13async function removeMcpServer(14 name: string,15 options: {16 scope: string;17 },18) {19 const { scope } = options;20 const settingsScope =21 scope === 'user' ? SettingScope.User : SettingScope.Workspace;22 const settings = loadSettings();23 24 const existingSettings = settings.forScope(settingsScope).settings;25 const mcpServers = existingSettings.mcpServers || {};26 27 if (!mcpServers[name]) {28 writeStdoutLine(`Server "${name}" not found in ${scope} settings.`);29 return;30 }31 32 delete mcpServers[name];33 34 settings.setValue(settingsScope, 'mcpServers', mcpServers);35 36 // Clean up any stored OAuth tokens for this server37 try {38 const tokenStorage = new MCPOAuthTokenStorage();39 await tokenStorage.deleteCredentials(name);40 } catch {41 // Token cleanup is best-effort; don't fail the remove operation42 }43 44 writeStdoutLine(`Server "${name}" removed from ${scope} settings.`);45}46 47export const removeCommand: CommandModule = {48 command: 'remove <name>',49 describe: 'Remove a server',50 builder: (yargs) =>51 yargs52 .usage('Usage: qwen mcp remove [options] <name>')53 .positional('name', {54 describe: 'Name of the server',55 type: 'string',56 demandOption: true,57 })58 .option('scope', {59 alias: 's',60 describe: 'Configuration scope (user or project)',61 type: 'string',62 default: 'user',63 choices: ['user', 'project'],64 }),65 handler: async (argv) => {66 await removeMcpServer(argv['name'] as string, {67 scope: argv['scope'] as string,68 });69 },70};71 