Skip to content

Commit 8e70a03

Browse files
committed
Update too
1 parent 6582640 commit 8e70a03

File tree

1 file changed

+75
-3
lines changed

1 file changed

+75
-3
lines changed

src/commands/uninstall.ts

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ import {Args, Command, Flags} from '@oclif/core'
22
import * as fs from 'node:fs/promises'
33
import * as os from 'node:os'
44
import * as path from 'node:path'
5+
import { execFile } from 'node:child_process'
6+
import { promisify } from 'node:util'
57

68
import { servers } from '../data/servers/index.js'
9+
10+
const execFileAsync = promisify(execFile)
11+
712
interface MCPServerTransport {
813
transport: {
914
args: string[];
@@ -70,6 +75,10 @@ export default class Uninstall extends Command {
7075
// Ignore errors reading Continue config
7176
}
7277

78+
// Try to get installed servers from VSCode and VSCode Insiders
79+
await getInstalledServersFromVSCode('code', installedServers)
80+
await getInstalledServersFromVSCode('code-insiders', installedServers)
81+
7382
const matches = [...installedServers].filter(id =>
7483
id.toLowerCase().startsWith(input.toLowerCase())
7584
)
@@ -85,14 +94,16 @@ export default class Uninstall extends Command {
8594
static override examples = [
8695
'<%= config.bin %> <%= command.id %> server-name',
8796
'<%= config.bin %> <%= command.id %> server-name1 server-name2 --client claude',
97+
'<%= config.bin %> <%= command.id %> server-name --client vscode',
98+
'<%= config.bin %> <%= command.id %> server-name --client vscode-insiders',
8899
]
89100

90101
static override flags = {
91102
client: Flags.string({
92103
char: 'c',
93104
default: 'claude',
94105
description: 'Uninstall the MCP servers from this client',
95-
options: ['claude', 'continue'],
106+
options: ['claude', 'continue', 'vscode', 'vscode-insiders'],
96107
}),
97108
}
98109

@@ -251,10 +262,71 @@ export default class Uninstall extends Command {
251262
this.error('An unknown error occurred')
252263
}
253264
}
265+
} else if (client === 'vscode' || client === 'vscode-insiders') {
266+
const command = client === 'vscode' ? 'code' : 'code-insiders'
267+
268+
try {
269+
// Use VSCode's CLI to remove the server
270+
const json = JSON.stringify({ name: serverName })
271+
await execFileAsync(command, ['--remove-mcp', json])
272+
273+
this.log(`🗑️ Successfully uninstalled ${serverName} from ${client}`)
274+
} catch (error: unknown) {
275+
if (error instanceof Error) {
276+
this.error(`Error uninstalling server from ${client}: ${error.message}`)
277+
} else {
278+
this.error(`An unknown error occurred while uninstalling from ${client}`)
279+
}
280+
}
281+
}
282+
}
283+
284+
private async uninstallOnWindows(serverName: string, client: string): Promise<void> {
285+
if (client === 'vscode' || client === 'vscode-insiders') {
286+
const command = client === 'vscode' ? 'code.cmd' : 'code-insiders.cmd'
287+
288+
try {
289+
// Use VSCode's CLI to remove the server
290+
const json = JSON.stringify({ name: serverName })
291+
await execFileAsync(command, ['--remove-mcp', json])
292+
293+
this.log(`🗑️ Successfully uninstalled ${serverName} from ${client}`)
294+
} catch (error: unknown) {
295+
if (error instanceof Error) {
296+
this.error(`Error uninstalling server from ${client}: ${error.message}`)
297+
} else {
298+
this.error(`An unknown error occurred while uninstalling from ${client}`)
299+
}
300+
}
301+
} else {
302+
throw new Error('Windows uninstallation not implemented yet for this client')
254303
}
255304
}
305+
}
256306

257-
private async uninstallOnWindows(_serverName: string, _client: string): Promise<void> {
258-
throw new Error('Windows uninstallation not implemented yet')
307+
// Helper function to get installed servers from VSCode or VSCode Insiders
308+
async function getInstalledServersFromVSCode(command: string, installedServers: Set<string>): Promise<void> {
309+
try {
310+
const results = await execFileAsync(command, ['--list-mcp'])
311+
if (results.stdout) {
312+
for (const line of results.stdout.split('\n')) {
313+
if (line.trim()) {
314+
try {
315+
const serverInfo = JSON.parse(line.trim())
316+
const server = servers.find(srv =>
317+
serverInfo.command === srv.config.command &&
318+
JSON.stringify(serverInfo.args.slice(0, srv.config.args.length)) === JSON.stringify(srv.config.args)
319+
)
320+
if (server) {
321+
installedServers.add(server.id)
322+
}
323+
} catch {
324+
// Ignore parsing errors
325+
}
326+
}
327+
}
328+
}
329+
} catch {
330+
// Ignore errors reading VSCode servers
259331
}
260332
}

0 commit comments

Comments
 (0)