Skip to content

Commit aab65e8

Browse files
authored
mcp: fix using incorrect remote path format on win->posix remotes (#251457)
Refs #251308
1 parent a2cd45e commit aab65e8

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/vs/workbench/contrib/mcp/common/discovery/configMcpDiscovery.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import { equals as arrayEquals } from '../../../../../base/common/arrays.js';
77
import { Throttler } from '../../../../../base/common/async.js';
88
import { Disposable, DisposableStore, IDisposable, MutableDisposable } from '../../../../../base/common/lifecycle.js';
99
import { autorunDelta, ISettableObservable, observableValue } from '../../../../../base/common/observable.js';
10-
import { isAbsolute, join } from '../../../../../base/common/path.js';
10+
import * as path from '../../../../../base/common/path.js';
11+
import { OperatingSystem } from '../../../../../base/common/platform.js';
1112
import { URI } from '../../../../../base/common/uri.js';
1213
import { Location } from '../../../../../editor/common/languages.js';
1314
import { ITextModelService } from '../../../../../editor/common/services/resolverService.js';
1415
import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js';
16+
import { IRemoteAgentService } from '../../../../services/remote/common/remoteAgentService.js';
1517
import { getMcpServerMapping } from '../mcpConfigFileUtils.js';
1618
import { IMcpConfigPath, IMcpConfigPathsService } from '../mcpConfigPathsService.js';
1719
import { IMcpConfiguration, mcpConfigurationSection } from '../mcpConfiguration.js';
@@ -37,6 +39,7 @@ export class ConfigMcpDiscovery extends Disposable implements IMcpDiscovery {
3739
@IMcpRegistry private readonly _mcpRegistry: IMcpRegistry,
3840
@ITextModelService private readonly _textModelService: ITextModelService,
3941
@IMcpConfigPathsService private readonly _mcpConfigPathsService: IMcpConfigPathsService,
42+
@IRemoteAgentService private readonly _remoteAgentService: IRemoteAgentService,
4043
) {
4144
super();
4245
}
@@ -100,6 +103,7 @@ export class ConfigMcpDiscovery extends Disposable implements IMcpDiscovery {
100103
const uri = src.path.uri;
101104
return uri && src.getServerToLocationMapping(uri);
102105
}));
106+
const remoteEnv = await this._remoteAgentService.getEnvironment();
103107

104108
for (const [index, src] of this.configSources.entries()) {
105109
const collectionId = `mcp.config.${src.path.id}`;
@@ -116,6 +120,13 @@ export class ConfigMcpDiscovery extends Disposable implements IMcpDiscovery {
116120
}
117121

118122
const configMapping = configMappings[index];
123+
const { isAbsolute, join, sep } = src.path.remoteAuthority && remoteEnv
124+
? (remoteEnv.os === OperatingSystem.Windows ? path.win32 : path.posix) : path;
125+
const fsPathForRemote = (uri: URI) => {
126+
const fsPathLocal = uri.fsPath;
127+
return fsPathLocal.replaceAll(path.sep, sep);
128+
};
129+
119130
const nextDefinitions = Object.entries(value?.servers || {}).map(([name, value]): McpServerDefinition => ({
120131
id: `${collectionId}.${name}`,
121132
label: name,
@@ -132,8 +143,12 @@ export class ConfigMcpDiscovery extends Disposable implements IMcpDiscovery {
132143
cwd: value.cwd
133144
// if the cwd is defined in a workspace folder but not absolute (and not
134145
// a variable or tilde-expansion) then resolve it in the workspace folder
135-
? (!isAbsolute(value.cwd) && !value.cwd.startsWith('~') && !value.cwd.startsWith('${') && src.path.workspaceFolder ? join(src.path.workspaceFolder.uri.fsPath, value.cwd) : value.cwd)
136-
: src.path.workspaceFolder?.uri.fsPath,
146+
? (!isAbsolute(value.cwd) && !value.cwd.startsWith('~') && !value.cwd.startsWith('${') && src.path.workspaceFolder
147+
? join(fsPathForRemote(src.path.workspaceFolder.uri), value.cwd)
148+
: value.cwd)
149+
: src.path.workspaceFolder
150+
? fsPathForRemote(src.path.workspaceFolder.uri)
151+
: undefined,
137152
},
138153
roots: src.path.workspaceFolder ? [src.path.workspaceFolder.uri] : [],
139154
variableReplacement: {

0 commit comments

Comments
 (0)