Skip to content

Commit 42fd68f

Browse files
authored
mcp: polishes to user experience (microsoft#253062)
- Fix new configs not being typed correctly - Add an 'update' option to the notification - Fix opening settings throwing an error if the mcp.json doesn't yet exist
1 parent 40a0ef2 commit 42fd68f

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

src/vs/platform/mcp/common/mcpResourceScannerService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export class McpResourceScannerService extends Disposable implements IMcpResourc
204204

205205
private sanitizeServer(serverOrConfig: IOldScannedMcpServer | Mutable<IMcpServerConfiguration>): IMcpServerConfiguration {
206206
let server: IMcpServerConfiguration;
207-
if (!(<IOldScannedMcpServer>serverOrConfig).config) {
207+
if ((<IOldScannedMcpServer>serverOrConfig).config) {
208208
const oldScannedMcpServer = <IOldScannedMcpServer>serverOrConfig;
209209
server = {
210210
...oldScannedMcpServer.config,

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

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ import { IUserDataProfileService } from '../../../services/userDataProfile/commo
5050
import { IRemoteUserDataProfilesService } from '../../../services/userDataProfile/common/remoteUserDataProfiles.js';
5151
import { PICK_WORKSPACE_FOLDER_COMMAND_ID } from '../../../browser/actions/workspaceCommands.js';
5252
import { MCP_CONFIGURATION_KEY, WORKSPACE_STANDALONE_CONFIGURATIONS } from '../../../services/configuration/common/configuration.js';
53+
import { IFileService } from '../../../../platform/files/common/files.js';
54+
import { VSBuffer } from '../../../../base/common/buffer.js';
5355

5456
// acroynms do not get localized
5557
const category: ILocalizedString = {
@@ -712,40 +714,52 @@ export class ShowInstalledMcpServersCommand extends Action2 {
712714
}
713715
}
714716

715-
export class OpenUserMcpResourceCommand extends Action2 {
717+
abstract class OpenMcpResourceCommand extends Action2 {
718+
protected abstract getURI(accessor: ServicesAccessor): Promise<URI>;
719+
720+
async run(accessor: ServicesAccessor) {
721+
const fileService = accessor.get(IFileService);
722+
const editorService = accessor.get(IEditorService);
723+
const resource = await this.getURI(accessor);
724+
if (!(await fileService.exists(resource))) {
725+
await fileService.createFile(resource, VSBuffer.fromString(JSON.stringify({ servers: {} }, null, '\t')));
726+
}
727+
await editorService.openEditor({ resource });
728+
}
729+
}
730+
731+
export class OpenUserMcpResourceCommand extends OpenMcpResourceCommand {
716732
constructor() {
717733
super({
718734
id: McpCommandIds.OpenUserMcp,
719-
title: localize2('mcp.command.openUserMcp', "Open User MCP Configuration"),
735+
title: localize2('mcp.command.openUserMcp', "Open User Configuration"),
720736
category,
721737
f1: true
722738
});
723739
}
724740

725-
async run(accessor: ServicesAccessor) {
741+
protected override getURI(accessor: ServicesAccessor): Promise<URI> {
726742
const userDataProfileService = accessor.get(IUserDataProfileService);
727-
const editorService = accessor.get(IEditorService);
728-
await editorService.openEditor({ resource: userDataProfileService.currentProfile.mcpResource });
743+
return Promise.resolve(userDataProfileService.currentProfile.mcpResource);
729744
}
730745
}
731746

732-
export class OpenRemoteUserMcpResourceCommand extends Action2 {
747+
export class OpenRemoteUserMcpResourceCommand extends OpenMcpResourceCommand {
733748
constructor() {
734749
super({
735750
id: McpCommandIds.OpenRemoteUserMcp,
736-
title: localize2('mcp.command.openRemoteUserMcp', "Open Remote User MCP Configuration"),
751+
title: localize2('mcp.command.openRemoteUserMcp', "Open Remote User Configuration"),
737752
category,
738753
f1: true,
739754
precondition: RemoteNameContext.notEqualsTo('')
740755
});
741756
}
742757

743-
async run(accessor: ServicesAccessor) {
758+
protected override async getURI(accessor: ServicesAccessor): Promise<URI> {
744759
const userDataProfileService = accessor.get(IUserDataProfileService);
745760
const remoteUserDataProfileService = accessor.get(IRemoteUserDataProfilesService);
746-
const editorService = accessor.get(IEditorService);
747761
const remoteProfile = await remoteUserDataProfileService.getRemoteProfile(userDataProfileService.currentProfile);
748-
await editorService.openEditor({ resource: remoteProfile.mcpResource });
762+
return remoteProfile.mcpResource;
749763
}
750764
}
751765

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ export class McpConfigMigrationContribution extends Disposable implements IWorkb
9696

9797
private showMcpConfigErrorNotification(isRemote: boolean): void {
9898
const message = isRemote
99-
? localize('mcp.migration.remoteConfigFound', 'MCP servers should not be configured in remote user settings. Use the dedicated MCP configuration instead.')
100-
: localize('mcp.migration.userConfigFound', 'MCP servers should not be configured in user settings. Use the dedicated MCP configuration instead.');
99+
? localize('mcp.migration.remoteConfigFound', 'MCP servers should no longer be configured in remote user settings. Use the dedicated MCP configuration instead.')
100+
: localize('mcp.migration.userConfigFound', 'MCP servers should no longer be configured in user settings. Use the dedicated MCP configuration instead.');
101101

102102
const openConfigLabel = isRemote
103103
? localize('mcp.migration.openRemoteConfig', 'Open Remote User MCP Configuration')
@@ -109,7 +109,14 @@ export class McpConfigMigrationContribution extends Disposable implements IWorkb
109109
Severity.Error,
110110
message,
111111
[{
112+
label: localize('mcp.migration.update', 'Update Now'),
113+
run: async () => {
114+
await this.migrateMcpConfig();
115+
await this.commandService.executeCommand(commandId);
116+
},
117+
}, {
112118
label: openConfigLabel,
119+
keepOpen: true,
113120
run: () => this.commandService.executeCommand(commandId)
114121
}]
115122
);

0 commit comments

Comments
 (0)