Skip to content

Commit 4fc2371

Browse files
authored
mcp: fix using incorrect remote path format on win->posix remotes (#251458)
* mcp: fix using incorrect remote path format on win->posix remotes Refs #251308 * mcp: fix compilation error with paths and minification Maybe?
1 parent e61520a commit 4fc2371

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

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

Lines changed: 19 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 { posix as pathPosix, win32 as pathWin32, sep as pathSep } from '../../../../../base/common/path.js';
11+
import { isWindows, 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,14 @@ 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 ? pathWin32 : pathPosix)
125+
: (isWindows ? pathWin32 : pathPosix);
126+
const fsPathForRemote = (uri: URI) => {
127+
const fsPathLocal = uri.fsPath;
128+
return fsPathLocal.replaceAll(pathSep, sep);
129+
};
130+
119131
const nextDefinitions = Object.entries(value?.servers || {}).map(([name, value]): McpServerDefinition => ({
120132
id: `${collectionId}.${name}`,
121133
label: name,
@@ -132,8 +144,12 @@ export class ConfigMcpDiscovery extends Disposable implements IMcpDiscovery {
132144
cwd: value.cwd
133145
// if the cwd is defined in a workspace folder but not absolute (and not
134146
// 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,
147+
? (!isAbsolute(value.cwd) && !value.cwd.startsWith('~') && !value.cwd.startsWith('${') && src.path.workspaceFolder
148+
? join(fsPathForRemote(src.path.workspaceFolder.uri), value.cwd)
149+
: value.cwd)
150+
: src.path.workspaceFolder
151+
? fsPathForRemote(src.path.workspaceFolder.uri)
152+
: undefined,
137153
},
138154
roots: src.path.workspaceFolder ? [src.path.workspaceFolder.uri] : [],
139155
variableReplacement: {

0 commit comments

Comments
 (0)