Skip to content

Commit 69b73b7

Browse files
authored
mcp: fix start all servers command (#286624)
* mcp: fix start all servers command If user specified `undefined` as the `serverId` ``` await vscode.commands.executeCommand('workbench.mcp.startServer', undefined); ``` …it would be turned into `null` when passed through the command system and was therefore not being treated as a wildcard. Resolves #283959. * mcp: fix start all servers command Resolves #283959. Previous implementation looked strictly for `undefined`, but the IPC layer converts `undefined` to `null`. This meant that calling the command via IPC like: ``` await vscode.commands.executeCommand('workbench.mcp.startServer', undefined); ``` was not working (while `vscode.commands.executeCommand('workbench.mcp.startServer')` was). Instead of handling `null` as a value as well, use a specicial value of `*` to indicate all servers should be started so the intent is clearer: ``` BEFORE: await vscode.commands.executeCommand('workbench.mcp.startServer'); AFTER : await vscode.commands.executeCommand('workbench.mcp.startServer', '*'); ``` Additionally, add a `waitForLiveTools` parameter that blocks the command from resolving until the server is downloaded, started, and tools are availble. Without this, a static sleep or poll would be needed.
1 parent dea178a commit 69b73b7

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import { IMcpRegistry } from '../common/mcpRegistryTypes.js';
6464
import { HasInstalledMcpServersContext, IMcpSamplingService, IMcpServer, IMcpServerStartOpts, IMcpService, InstalledMcpServersViewId, LazyCollectionState, McpCapability, McpCollectionDefinition, McpConnectionState, McpDefinitionReference, mcpPromptPrefix, McpServerCacheState, McpStartServerInteraction } from '../common/mcpTypes.js';
6565
import { McpAddConfigurationCommand } from './mcpCommandsAddConfiguration.js';
6666
import { McpResourceQuickAccess, McpResourceQuickPick } from './mcpResourceQuickAccess.js';
67+
import { startServerAndWaitForLiveTools } from '../common/mcpTypesUtils.js';
6768
import './media/mcpServerAction.css';
6869
import { openPanelChatAndGetWidget } from './openPanelChatAndGetWidget.js';
6970

@@ -821,13 +822,18 @@ export class StartServer extends Action2 {
821822
});
822823
}
823824

824-
async run(accessor: ServicesAccessor, serverId: string | undefined, opts?: IMcpServerStartOpts) {
825+
async run(accessor: ServicesAccessor, serverId: string, opts?: IMcpServerStartOpts & { waitForLiveTools?: boolean }) {
825826
let servers = accessor.get(IMcpService).servers.get();
826-
if (serverId !== undefined) {
827+
if (serverId !== '*') {
827828
servers = servers.filter(s => s.definition.id === serverId);
828829
}
829830

830-
await Promise.all(servers.map(s => s.start({ promptType: 'all-untrusted', ...opts })));
831+
const startOpts: IMcpServerStartOpts = { promptType: 'all-untrusted', ...opts };
832+
if (opts?.waitForLiveTools) {
833+
await Promise.all(servers.map(s => startServerAndWaitForLiveTools(s, startOpts)));
834+
} else {
835+
await Promise.all(servers.map(s => s.start(startOpts)));
836+
}
831837
}
832838
}
833839

0 commit comments

Comments
 (0)