Skip to content

Commit bcd2e0f

Browse files
Copilotsergeibbb
andcommitted
Add automatic uninstall of duplicate manual MCP servers
When the bundled MCP provider is used (VS Code >= 1.101.0 with MCP API support), automatically detect and uninstall any duplicate manual MCP installations that were previously set up via the CLI when the IDE didn't support bundled MCP. This prevents duplicate MCP servers from coexisting when an IDE adds support for VS Code's native MCP API. Co-authored-by: sergeibbb <[email protected]>
1 parent 8a00627 commit bcd2e0f

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

docs/telemetry-events.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2813,6 +2813,17 @@ void
28132813
}
28142814
```
28152815

2816+
### mcp/uninstall/duplicate
2817+
2818+
> Sent when a duplicate manual MCP installation is uninstalled
2819+
2820+
```typescript
2821+
{
2822+
'app': string,
2823+
'source': 'account' | 'subscription' | 'graph' | 'composer' | 'patchDetails' | 'settings' | 'timeline' | 'home' | 'ai' | 'ai:markdown-preview' | 'ai:markdown-editor' | 'ai:picker' | 'associateIssueWithBranch' | 'cloud-patches' | 'code-suggest' | 'commandPalette' | 'deeplink' | 'editor:hover' | 'feature-badge' | 'feature-gate' | 'gk-cli-integration' | 'gk-mcp-provider' | 'inspect' | 'inspect-overview' | 'integrations' | 'launchpad' | 'launchpad-indicator' | 'launchpad-view' | 'mcp' | 'mcp-welcome-message' | 'merge-target' | 'notification' | 'prompt' | 'quick-wizard' | 'rebaseEditor' | 'remoteProvider' | 'scm' | 'scm-input' | 'startWork' | 'trial-indicator' | 'view' | 'walkthrough' | 'whatsnew' | 'worktrees'
2824+
}
2825+
```
2826+
28162827
### openReviewMode
28172828

28182829
> Sent when a PR review was started in the inspect overview

src/constants.telemetry.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ export interface TelemetryEvents extends WebviewShowAbortedEvents, WebviewShownE
254254
'mcp/setup/failed': MCPSetupFailedEvent;
255255
/** Sent when GitKraken MCP registration fails */
256256
'mcp/registration/failed': MCPSetupFailedEvent;
257+
/** Sent when a duplicate manual MCP installation is uninstalled */
258+
'mcp/uninstall/duplicate': MCPUninstallDuplicateEvent;
257259

258260
/** Sent when a PR review was started in the inspect overview */
259261
openReviewMode: OpenReviewModeEvent;
@@ -526,6 +528,11 @@ export interface MCPSetupFailedEvent {
526528
'error.message'?: string;
527529
}
528530

531+
export interface MCPUninstallDuplicateEvent {
532+
app: string;
533+
source: Sources;
534+
}
535+
529536
interface CloudIntegrationsConnectingEvent {
530537
'integration.ids': string | undefined;
531538
}

src/env/node/gk/mcp/integration.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ export class GkMcpProvider implements McpServerDefinitionProvider, Disposable {
9595
return undefined;
9696
}
9797

98+
// Clean up any duplicate manual installations before registering the bundled version
99+
await this.uninstallManualMcpIfExists(appName, cliPath);
100+
98101
let output = await runCLICommand(['mcp', 'config', appName, '--source=gitlens', `--scheme=${env.uriScheme}`], {
99102
cwd: cliPath,
100103
});
@@ -120,6 +123,36 @@ export class GkMcpProvider implements McpServerDefinitionProvider, Disposable {
120123
return undefined;
121124
}
122125

126+
@debug()
127+
private async uninstallManualMcpIfExists(appName: string, cliPath: string): Promise<void> {
128+
try {
129+
// Check if a manual MCP installation exists by attempting to uninstall it
130+
// The uninstall command will only succeed if there's an existing manual installation
131+
const output = await runCLICommand(
132+
['mcp', 'uninstall', appName, '--source=gitlens', `--scheme=${env.uriScheme}`],
133+
{
134+
cwd: cliPath,
135+
},
136+
);
137+
138+
// If uninstall succeeded, log and send telemetry
139+
if (output.trim().length > 0) {
140+
Logger.log(`Uninstalled duplicate manual MCP installation for ${appName}`);
141+
142+
if (this.container.telemetry.enabled) {
143+
this.container.telemetry.sendEvent('mcp/uninstall/duplicate', {
144+
app: appName,
145+
source: 'gk-mcp-provider',
146+
});
147+
}
148+
}
149+
} catch (ex) {
150+
// If uninstall fails, it likely means no manual installation exists
151+
// Log the error at debug level but don't fail the overall process
152+
Logger.debug(`No manual MCP installation to uninstall for ${appName}: ${ex}`);
153+
}
154+
}
155+
123156
private onRegistrationCompleted(_cliVersion?: string | undefined) {
124157
if (!this.container.telemetry.enabled) return;
125158

0 commit comments

Comments
 (0)