@@ -7,11 +7,13 @@ import { equals as arrayEquals } from '../../../../../base/common/arrays.js';
7
7
import { Throttler } from '../../../../../base/common/async.js' ;
8
8
import { Disposable , DisposableStore , IDisposable , MutableDisposable } from '../../../../../base/common/lifecycle.js' ;
9
9
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' ;
11
12
import { URI } from '../../../../../base/common/uri.js' ;
12
13
import { Location } from '../../../../../editor/common/languages.js' ;
13
14
import { ITextModelService } from '../../../../../editor/common/services/resolverService.js' ;
14
15
import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js' ;
16
+ import { IRemoteAgentService } from '../../../../services/remote/common/remoteAgentService.js' ;
15
17
import { getMcpServerMapping } from '../mcpConfigFileUtils.js' ;
16
18
import { IMcpConfigPath , IMcpConfigPathsService } from '../mcpConfigPathsService.js' ;
17
19
import { IMcpConfiguration , mcpConfigurationSection } from '../mcpConfiguration.js' ;
@@ -37,6 +39,7 @@ export class ConfigMcpDiscovery extends Disposable implements IMcpDiscovery {
37
39
@IMcpRegistry private readonly _mcpRegistry : IMcpRegistry ,
38
40
@ITextModelService private readonly _textModelService : ITextModelService ,
39
41
@IMcpConfigPathsService private readonly _mcpConfigPathsService : IMcpConfigPathsService ,
42
+ @IRemoteAgentService private readonly _remoteAgentService : IRemoteAgentService ,
40
43
) {
41
44
super ( ) ;
42
45
}
@@ -100,6 +103,7 @@ export class ConfigMcpDiscovery extends Disposable implements IMcpDiscovery {
100
103
const uri = src . path . uri ;
101
104
return uri && src . getServerToLocationMapping ( uri ) ;
102
105
} ) ) ;
106
+ const remoteEnv = await this . _remoteAgentService . getEnvironment ( ) ;
103
107
104
108
for ( const [ index , src ] of this . configSources . entries ( ) ) {
105
109
const collectionId = `mcp.config.${ src . path . id } ` ;
@@ -116,6 +120,13 @@ export class ConfigMcpDiscovery extends Disposable implements IMcpDiscovery {
116
120
}
117
121
118
122
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
+
119
130
const nextDefinitions = Object . entries ( value ?. servers || { } ) . map ( ( [ name , value ] ) : McpServerDefinition => ( {
120
131
id : `${ collectionId } .${ name } ` ,
121
132
label : name ,
@@ -132,8 +143,12 @@ export class ConfigMcpDiscovery extends Disposable implements IMcpDiscovery {
132
143
cwd : value . cwd
133
144
// if the cwd is defined in a workspace folder but not absolute (and not
134
145
// 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 ,
137
152
} ,
138
153
roots : src . path . workspaceFolder ? [ src . path . workspaceFolder . uri ] : [ ] ,
139
154
variableReplacement : {
0 commit comments