Skip to content

Commit d9f1bf8

Browse files
authored
1 parent 2fda72e commit d9f1bf8

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

src/vs/workbench/contrib/mcp/browser/mcpServerEditor.ts

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { IWebview, IWebviewService } from '../../webview/browser/webview.js';
3737
import { IEditorGroup } from '../../../services/editor/common/editorGroupsService.js';
3838
import { IExtensionService } from '../../../services/extensions/common/extensions.js';
3939
import { IHoverService } from '../../../../platform/hover/browser/hover.js';
40-
import { IMcpServerEditorOptions, IWorkbenchMcpServer, McpServerContainers } from '../common/mcpTypes.js';
40+
import { IMcpServerEditorOptions, IMcpWorkbenchService, IWorkbenchMcpServer, McpServerContainers } from '../common/mcpTypes.js';
4141
import { InstallCountWidget, McpServerIconWidget, McpServerWidget, onClick, PublisherWidget, RatingsWidget } from './mcpServerWidgets.js';
4242
import { DropDownAction, InstallAction, InstallingLabelAction, ManageMcpServerAction, UninstallAction } from './mcpServerActions.js';
4343
import { McpServerEditorInput } from './mcpServerEditorInput.js';
@@ -73,19 +73,34 @@ class NavBar extends Disposable {
7373
this.actionbar = this._register(new ActionBar(element));
7474
}
7575

76-
push(id: string, label: string, tooltip: string): void {
76+
push(id: string, label: string, tooltip: string, index?: number): void {
7777
const action = new Action(id, label, undefined, true, () => this.update(id, true));
7878

7979
action.tooltip = tooltip;
8080

81-
this.actions.push(action);
82-
this.actionbar.push(action);
81+
if (typeof index === 'number') {
82+
this.actions.splice(index, 0, action);
83+
} else {
84+
this.actions.push(action);
85+
}
86+
this.actionbar.push(action, { index });
8387

8488
if (this.actions.length === 1) {
8589
this.update(id);
8690
}
8791
}
8892

93+
remove(id: string): void {
94+
const index = this.actions.findIndex(action => action.id === id);
95+
if (index !== -1) {
96+
this.actions.splice(index, 1);
97+
this.actionbar.pull(index);
98+
if (this._currentId === id) {
99+
this.switch(this.actions[0]?.id);
100+
}
101+
}
102+
}
103+
89104
clear(): void {
90105
this.actions = dispose(this.actions);
91106
this.actionbar.clear();
@@ -100,6 +115,10 @@ class NavBar extends Disposable {
100115
return false;
101116
}
102117

118+
has(id: string): boolean {
119+
return this.actions.some(action => action.id === id);
120+
}
121+
103122
private update(id: string, focus?: boolean): void {
104123
this._currentId = id;
105124
this._onChange.fire({ id, focus: !!focus });
@@ -165,6 +184,7 @@ export class McpServerEditor extends EditorPane {
165184
@IWebviewService private readonly webviewService: IWebviewService,
166185
@ILanguageService private readonly languageService: ILanguageService,
167186
@IContextKeyService private readonly contextKeyService: IContextKeyService,
187+
@IMcpWorkbenchService private readonly mcpWorkbenchService: IMcpWorkbenchService,
168188
@IHoverService private readonly hoverService: IHoverService,
169189
) {
170190
super(McpServerEditor.ID, group, telemetryService, themeService, storageService);
@@ -341,6 +361,17 @@ export class McpServerEditor extends EditorPane {
341361
template.navbar.push(McpServerEditorTab.Manifest, localize('manifest', "Manifest"), localize('manifesttooltip', "Server manifest details"));
342362
}
343363

364+
this.transientDisposables.add(this.mcpWorkbenchService.onChange(e => {
365+
if (e === extension) {
366+
if (e.config && !template.navbar.has(McpServerEditorTab.Configuration)) {
367+
template.navbar.push(McpServerEditorTab.Configuration, localize('configuration', "Configuration"), localize('configurationtooltip', "Server configuration details"), extension.readmeUrl ? 1 : 0);
368+
}
369+
if (!e.config && template.navbar.has(McpServerEditorTab.Configuration)) {
370+
template.navbar.remove(McpServerEditorTab.Configuration);
371+
}
372+
}
373+
}));
374+
344375
if ((<IMcpServerEditorOptions | undefined>this.options)?.tab) {
345376
template.navbar.switch((<IMcpServerEditorOptions>this.options).tab!);
346377
}

src/vs/workbench/contrib/mcp/browser/mcpWorkbenchService.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,15 @@ export class McpWorkbenchService extends Disposable implements IMcpWorkbenchServ
209209
}
210210

211211
private onDidInstallMcpServer(local: IWorkbenchLocalMcpServer, gallery?: IGalleryMcpServer): IWorkbenchMcpServer {
212-
let server = this._local.find(server => server.local?.name === local.name);
212+
let server = this.installing.find(server => server.name === local.name);
213+
this.installing = server ? this.installing.filter(e => e !== server) : this.installing;
213214
if (server) {
214215
server.local = local;
215216
} else {
216217
server = this.instantiationService.createInstance(McpWorkbenchServer, e => this.getInstallState(e), local, gallery, undefined);
217-
this._local.push(server);
218218
}
219+
this._local = this._local.filter(e => e.name === local.name);
220+
this._local.push(server);
219221
this._onChange.fire(server);
220222
return server;
221223
}
@@ -334,7 +336,7 @@ export class McpWorkbenchService extends Disposable implements IMcpWorkbenchServ
334336
private async doInstall(server: McpWorkbenchServer, installTask: () => Promise<IWorkbenchLocalMcpServer>): Promise<IWorkbenchMcpServer> {
335337
this.installing.push(server);
336338
this._onChange.fire(server);
337-
await installTask().finally(() => this.installing = this.installing.filter(s => s !== server));
339+
await installTask();
338340
return this.waitAndGetInstalledMcpServer(server);
339341
}
340342

0 commit comments

Comments
 (0)