Skip to content

Commit 86a8f0d

Browse files
authored
1 parent 6bd21d4 commit 86a8f0d

File tree

3 files changed

+96
-3
lines changed

3 files changed

+96
-3
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { McpSamplingService } from '../common/mcpSamplingService.js';
3030
import { McpService } from '../common/mcpService.js';
3131
import { IMcpElicitationService, IMcpSamplingService, IMcpService, IMcpWorkbenchService } from '../common/mcpTypes.js';
3232
import { McpAddContextContribution } from './mcpAddContextContribution.js';
33-
import { AddConfigurationAction, EditStoredInput, ListMcpServerCommand, McpBrowseCommand, McpBrowseResourcesCommand, McpConfigureSamplingModels, MCPServerActionRendering, McpServerOptionsCommand, McpStartPromptingServerCommand, RemoveStoredInput, ResetMcpCachedTools, ResetMcpTrustCommand, RestartServer, ShowConfiguration, ShowInstalledMcpServersCommand, ShowOutput, StartServer, StopServer } from './mcpCommands.js';
33+
import { AddConfigurationAction, EditStoredInput, ListMcpServerCommand, McpBrowseCommand, McpBrowseResourcesCommand, McpConfigureSamplingModels, MCPServerActionRendering, McpServerOptionsCommand, McpStartPromptingServerCommand, OpenRemoteUserMcpResourceCommand, OpenUserMcpResourceCommand, OpenWorkspaceFolderMcpResourceCommand, OpenWorkspaceMcpResourceCommand, RemoveStoredInput, ResetMcpCachedTools, ResetMcpTrustCommand, RestartServer, ShowConfiguration, ShowInstalledMcpServersCommand, ShowOutput, StartServer, StopServer } from './mcpCommands.js';
3434
import { McpDiscovery } from './mcpDiscovery.js';
3535
import { McpElicitationService } from './mcpElicitationService.js';
3636
import { McpLanguageFeatures } from './mcpLanguageFeatures.js';
@@ -71,6 +71,10 @@ registerAction2(ShowOutput);
7171
registerAction2(RestartServer);
7272
registerAction2(ShowConfiguration);
7373
registerAction2(McpBrowseCommand);
74+
registerAction2(OpenUserMcpResourceCommand);
75+
registerAction2(OpenRemoteUserMcpResourceCommand);
76+
registerAction2(OpenWorkspaceMcpResourceCommand);
77+
registerAction2(OpenWorkspaceFolderMcpResourceCommand);
7478
registerAction2(ShowInstalledMcpServersCommand);
7579
registerAction2(McpBrowseResourcesCommand);
7680
registerAction2(McpConfigureSamplingModels);

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

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import { IInstantiationService, ServicesAccessor } from '../../../../platform/in
2626
import { IQuickInputService, IQuickPickItem, IQuickPickSeparator } from '../../../../platform/quickinput/common/quickInput.js';
2727
import { StorageScope } from '../../../../platform/storage/common/storage.js';
2828
import { spinningLoading } from '../../../../platform/theme/common/iconRegistry.js';
29-
import { IWorkspaceContextService } from '../../../../platform/workspace/common/workspace.js';
30-
import { ActiveEditorContext, ResourceContextKey } from '../../../common/contextkeys.js';
29+
import { IWorkspaceContextService, IWorkspaceFolder } from '../../../../platform/workspace/common/workspace.js';
30+
import { ActiveEditorContext, RemoteNameContext, ResourceContextKey, WorkbenchStateContext, WorkspaceFolderCountContext } from '../../../common/contextkeys.js';
3131
import { IWorkbenchContribution } from '../../../common/contributions.js';
3232
import { IAccountQuery, IAuthenticationQueryService } from '../../../services/authentication/common/authenticationQuery.js';
3333
import { IAuthenticationService } from '../../../services/authentication/common/authentication.js';
@@ -46,6 +46,10 @@ import { HasInstalledMcpServersContext, IMcpSamplingService, IMcpServer, IMcpSer
4646
import { McpAddConfigurationCommand } from './mcpCommandsAddConfiguration.js';
4747
import { McpResourceQuickAccess, McpResourceQuickPick } from './mcpResourceQuickAccess.js';
4848
import { openPanelChatAndGetWidget } from './openPanelChatAndGetWidget.js';
49+
import { IUserDataProfileService } from '../../../services/userDataProfile/common/userDataProfile.js';
50+
import { IRemoteUserDataProfilesService } from '../../../services/userDataProfile/common/remoteUserDataProfiles.js';
51+
import { PICK_WORKSPACE_FOLDER_COMMAND_ID } from '../../../browser/actions/workspaceCommands.js';
52+
import { MCP_CONFIGURATION_KEY, WORKSPACE_STANDALONE_CONFIGURATIONS } from '../../../services/configuration/common/configuration.js';
4953

5054
// acroynms do not get localized
5155
const category: ILocalizedString = {
@@ -708,6 +712,87 @@ export class ShowInstalledMcpServersCommand extends Action2 {
708712
}
709713
}
710714

715+
export class OpenUserMcpResourceCommand extends Action2 {
716+
constructor() {
717+
super({
718+
id: McpCommandIds.OpenUserMcp,
719+
title: localize2('mcp.command.openUserMcp', "Open User MCP Servers"),
720+
category,
721+
f1: true
722+
});
723+
}
724+
725+
async run(accessor: ServicesAccessor) {
726+
const userDataProfileService = accessor.get(IUserDataProfileService);
727+
const editorService = accessor.get(IEditorService);
728+
await editorService.openEditor({ resource: userDataProfileService.currentProfile.mcpResource });
729+
}
730+
}
731+
732+
export class OpenRemoteUserMcpResourceCommand extends Action2 {
733+
constructor() {
734+
super({
735+
id: McpCommandIds.OpenRemoteUserMcp,
736+
title: localize2('mcp.command.openRemoteUserMcp', "Open Remote User MCP Servers"),
737+
category,
738+
f1: true,
739+
precondition: RemoteNameContext.notEqualsTo('')
740+
});
741+
}
742+
743+
async run(accessor: ServicesAccessor) {
744+
const userDataProfileService = accessor.get(IUserDataProfileService);
745+
const remoteUserDataProfileService = accessor.get(IRemoteUserDataProfilesService);
746+
const editorService = accessor.get(IEditorService);
747+
const remoteProfile = await remoteUserDataProfileService.getRemoteProfile(userDataProfileService.currentProfile);
748+
await editorService.openEditor({ resource: remoteProfile.mcpResource });
749+
}
750+
}
751+
752+
export class OpenWorkspaceFolderMcpResourceCommand extends Action2 {
753+
constructor() {
754+
super({
755+
id: McpCommandIds.OpenWorkspaceFolderMcp,
756+
title: localize2('mcp.command.openWorkspaceFolderMcp', "Open Workspace Folder MCP Servers"),
757+
category,
758+
f1: true,
759+
precondition: WorkspaceFolderCountContext.notEqualsTo(0)
760+
});
761+
}
762+
763+
async run(accessor: ServicesAccessor) {
764+
const workspaceContextService = accessor.get(IWorkspaceContextService);
765+
const commandService = accessor.get(ICommandService);
766+
const editorService = accessor.get(IEditorService);
767+
const workspaceFolders = workspaceContextService.getWorkspace().folders;
768+
const workspaceFolder = workspaceFolders.length === 1 ? workspaceFolders[0] : await commandService.executeCommand<IWorkspaceFolder>(PICK_WORKSPACE_FOLDER_COMMAND_ID);
769+
if (workspaceFolder) {
770+
await editorService.openEditor({ resource: workspaceFolder.toResource(WORKSPACE_STANDALONE_CONFIGURATIONS[MCP_CONFIGURATION_KEY]) });
771+
}
772+
}
773+
}
774+
775+
export class OpenWorkspaceMcpResourceCommand extends Action2 {
776+
constructor() {
777+
super({
778+
id: McpCommandIds.OpenWorkspaceMcp,
779+
title: localize2('mcp.command.openWorkspaceMcp', "Open Workspace MCP Servers"),
780+
category,
781+
f1: true,
782+
precondition: WorkbenchStateContext.isEqualTo('workspace')
783+
});
784+
}
785+
786+
async run(accessor: ServicesAccessor) {
787+
const workspaceContextService = accessor.get(IWorkspaceContextService);
788+
const editorService = accessor.get(IEditorService);
789+
const workspaceConfiguration = workspaceContextService.getWorkspace().configuration;
790+
if (workspaceConfiguration) {
791+
await editorService.openEditor({ resource: workspaceConfiguration });
792+
}
793+
}
794+
}
795+
711796
export class McpBrowseResourcesCommand extends Action2 {
712797
constructor() {
713798
super({

src/vs/workbench/contrib/mcp/common/mcpCommandIds.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ export const enum McpCommandIds {
1010
AddConfiguration = 'workbench.mcp.addConfiguration',
1111
Browse = 'workbench.mcp.browseServers',
1212
ShowInstalled = 'workbench.mcp.showInstalledServers',
13+
OpenUserMcp = 'workbench.mcp.openUserMcpJson',
14+
OpenRemoteUserMcp = 'workbench.mcp.openRemoteUserMcpJson',
15+
OpenWorkspaceFolderMcp = 'workbench.mcp.openWorkspaceFolderMcpJson',
16+
OpenWorkspaceMcp = 'workbench.mcp.openWorkspaceMcpJson',
1317
BrowseResources = 'workbench.mcp.browseResources',
1418
ConfigureSamplingModels = 'workbench.mcp.configureSamplingModels',
1519
EditStoredInput = 'workbench.mcp.editStoredInput',

0 commit comments

Comments
 (0)