Skip to content

Commit 5d889dc

Browse files
authored
Add Show JSON Configuration (microsoft#257861)
1 parent 51b78b5 commit 5d889dc

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

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

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import { Emitter } from '../../../../base/common/event.js';
1111
import { IMarkdownString, MarkdownString } from '../../../../base/common/htmlContent.js';
1212
import { disposeIfDisposable } from '../../../../base/common/lifecycle.js';
1313
import { ThemeIcon } from '../../../../base/common/themables.js';
14+
import { URI } from '../../../../base/common/uri.js';
1415
import { localize } from '../../../../nls.js';
16+
import { Location } from '../../../../editor/common/languages.js';
1517
import { ICommandService } from '../../../../platform/commands/common/commands.js';
1618
import { IContextMenuService } from '../../../../platform/contextview/browser/contextView.js';
1719
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
@@ -22,6 +24,7 @@ import { IAccountQuery, IAuthenticationQueryService } from '../../../services/au
2224
import { IEditorService } from '../../../services/editor/common/editorService.js';
2325
import { errorIcon, infoIcon, manageExtensionIcon, trustIcon, warningIcon } from '../../extensions/browser/extensionsIcons.js';
2426
import { McpCommandIds } from '../common/mcpCommandIds.js';
27+
import { IMcpRegistry } from '../common/mcpRegistryTypes.js';
2528
import { IMcpSamplingService, IMcpServer, IMcpServerContainer, IMcpService, IMcpWorkbenchService, IWorkbenchMcpServer, McpCapability, McpConnectionState, McpServerEditorTab, McpServerInstallState } from '../common/mcpTypes.js';
2629

2730
export abstract class McpServerAction extends Action implements IMcpServerContainer {
@@ -234,6 +237,7 @@ export class ManageMcpServerAction extends DropDownAction {
234237
groups.push([
235238
this.instantiationService.createInstance(ShowServerOutputAction),
236239
this.instantiationService.createInstance(ShowServerConfigurationAction),
240+
this.instantiationService.createInstance(ShowServerJsonConfigurationAction),
237241
]);
238242
groups.push([
239243
this.instantiationService.createInstance(ConfigureModelAccessAction),
@@ -574,7 +578,6 @@ export class ShowServerConfigurationAction extends McpServerAction {
574578
}
575579
this.class = ShowServerConfigurationAction.CLASS;
576580
this.enabled = true;
577-
this.label = localize('config', "Show Configuration");
578581
}
579582

580583
override async run(): Promise<any> {
@@ -586,6 +589,59 @@ export class ShowServerConfigurationAction extends McpServerAction {
586589

587590
}
588591

592+
export class ShowServerJsonConfigurationAction extends McpServerAction {
593+
594+
static readonly CLASS = `${this.LABEL_ACTION_CLASS} prominent config`;
595+
private static readonly HIDE = `${this.CLASS} hide`;
596+
597+
constructor(
598+
@IMcpService private readonly mcpService: IMcpService,
599+
@IMcpRegistry private readonly mcpRegistry: IMcpRegistry,
600+
@IEditorService private readonly editorService: IEditorService,
601+
) {
602+
super('extensions.jsonConfig', localize('configJson', "Show Configuration (JSON)"), ShowServerJsonConfigurationAction.CLASS, false);
603+
this.update();
604+
}
605+
606+
update(): void {
607+
this.enabled = false;
608+
this.class = ShowServerJsonConfigurationAction.HIDE;
609+
const configurationTarget = this.getConfigurationTarget();
610+
if (!configurationTarget) {
611+
return;
612+
}
613+
this.class = ShowServerConfigurationAction.CLASS;
614+
this.enabled = true;
615+
}
616+
617+
override async run(): Promise<any> {
618+
const configurationTarget = this.getConfigurationTarget();
619+
if (!configurationTarget) {
620+
return;
621+
}
622+
this.editorService.openEditor({
623+
resource: URI.isUri(configurationTarget) ? configurationTarget : configurationTarget!.uri,
624+
options: { selection: URI.isUri(configurationTarget) ? undefined : configurationTarget!.range }
625+
});
626+
}
627+
628+
private getConfigurationTarget(): Location | URI | undefined {
629+
if (!this.mcpServer) {
630+
return;
631+
}
632+
if (!this.mcpServer.local) {
633+
return;
634+
}
635+
const server = this.mcpService.servers.get().find(s => s.definition.label === this.mcpServer?.name);
636+
if (!server) {
637+
return;
638+
}
639+
const collection = this.mcpRegistry.collections.get().find(c => c.id === server.collection.id);
640+
const serverDefinition = collection?.serverDefinitions.get().find(s => s.id === server.definition.id);
641+
return serverDefinition?.presentation?.origin || collection?.presentation?.origin;
642+
}
643+
}
644+
589645
export class ConfigureModelAccessAction extends McpServerAction {
590646

591647
static readonly CLASS = `${this.LABEL_ACTION_CLASS} prominent config`;

0 commit comments

Comments
 (0)