@@ -119,19 +119,15 @@ export class McpResourcePickHelper {
119
119
const cts = new CancellationTokenSource ( ) ;
120
120
121
121
const vars : Record < string , string | string [ ] > = { } ;
122
- for ( const variable of todo ) {
123
- vars [ variable . name ] = `$${ variable . name . toUpperCase ( ) } ` ;
124
- }
125
-
126
122
quickInput . totalSteps = todo . length ;
127
123
quickInput . ignoreFocusOut = true ;
128
124
129
- const initialCompletions = todo . map ( variable => rt . complete ( variable . name , '' , cts . token ) ) ;
125
+ const initialCompletions = todo . map ( variable => rt . complete ( variable . name , '' , { } , cts . token ) ) ;
130
126
131
127
try {
132
128
for ( let i = 0 ; i < todo . length ; i ++ ) {
133
129
const variable = todo [ i ] ;
134
- const resolved = await this . _promptForTemplateValue ( quickInput , variable , initialCompletions [ i ] , rt . template . resolve ( vars ) , rt ) ;
130
+ const resolved = await this . _promptForTemplateValue ( quickInput , variable , initialCompletions [ i ] , vars , rt ) ;
135
131
if ( resolved === undefined ) {
136
132
return undefined ;
137
133
}
@@ -144,11 +140,18 @@ export class McpResourcePickHelper {
144
140
}
145
141
}
146
142
147
- private _promptForTemplateValue ( input : IQuickPick < IQuickPickItem > , variable : IUriTemplateVariable , initialCompletions : Promise < string [ ] > , uriSoFar : string , rt : IMcpResourceTemplate ) : Promise < string | undefined > {
143
+ private _promptForTemplateValue ( input : IQuickPick < IQuickPickItem > , variable : IUriTemplateVariable , initialCompletions : Promise < string [ ] > , variablesSoFar : Record < string , string | string [ ] > , rt : IMcpResourceTemplate ) : Promise < string | undefined > {
148
144
const store = new DisposableStore ( ) ;
149
145
const completions = new Map < string , Promise < string [ ] > > ( [ [ '' , initialCompletions ] ] ) ;
150
146
151
- let placeholder = localize ( 'mcp.resource.template.placeholder' , "Value for ${0} in {1}" , variable . name . toUpperCase ( ) , uriSoFar . replaceAll ( '%24' , '$' ) ) ;
147
+ const variablesWithPlaceholders = { ...variablesSoFar } ;
148
+ for ( const variable of rt . template . components . flatMap ( c => typeof c === 'object' ? c . variables : [ ] ) ) {
149
+ if ( ! variablesWithPlaceholders . hasOwnProperty ( variable . name ) ) {
150
+ variablesWithPlaceholders [ variable . name ] = `$${ variable . name . toUpperCase ( ) } ` ;
151
+ }
152
+ }
153
+
154
+ let placeholder = localize ( 'mcp.resource.template.placeholder' , "Value for ${0} in {1}" , variable . name . toUpperCase ( ) , rt . template . resolve ( variablesWithPlaceholders ) . replaceAll ( '%24' , '$' ) ) ;
152
155
if ( variable . optional ) {
153
156
placeholder += ' (' + localize ( 'mcp.resource.template.optional' , "Optional" ) + ')' ;
154
157
}
@@ -174,7 +177,7 @@ export class McpResourcePickHelper {
174
177
const inputValue = input . value ;
175
178
let promise = completions . get ( inputValue ) ;
176
179
if ( ! promise ) {
177
- promise = rt . complete ( variable . name , inputValue , changeCancellation . token ) ;
180
+ promise = rt . complete ( variable . name , inputValue , variablesSoFar , changeCancellation . token ) ;
178
181
completions . set ( inputValue , promise ) ;
179
182
}
180
183
@@ -240,6 +243,7 @@ export class McpResourcePickHelper {
240
243
} ) ( ) ,
241
244
server . resourceTemplates ( cts . token ) . then ( templates => {
242
245
writeInto . unshift ( ...templates ) ;
246
+ onChange ( servers ) ;
243
247
} ) . catch ( ( ) => {
244
248
// no templat support, not rare
245
249
} ) ,
0 commit comments