@@ -2,6 +2,7 @@ package mcp
2
2
3
3
import (
4
4
"encoding/json"
5
+ "errors"
5
6
"fmt"
6
7
"os"
7
8
"path/filepath"
@@ -86,7 +87,7 @@ func ParseMCPClient(clientStr string) (MCPClient, error) {
86
87
clientStr = strings .ToLower (clientStr )
87
88
client := MCPClient (clientStr )
88
89
if ! slices .Contains (ValidClients , client ) {
89
- return "" , fmt .Errorf ("invalid MCP client: %q. Valid MCP clients are: %v" , client , ValidClients )
90
+ return "" , fmt .Errorf ("invalid MCP client: %q. Valid MCP clients are %v" , clientStr , ValidClients )
90
91
}
91
92
return client , nil
92
93
}
@@ -240,48 +241,25 @@ func handleVSCodeConfig(configPath string) error {
240
241
existingData = make (map [string ]interface {})
241
242
}
242
243
243
- // Check if mcp section exists
244
- mcpData , ok := existingData ["mcp " ]
244
+ // Check if "servers" section exists
245
+ serversSection , ok := existingData ["servers " ]
245
246
if ! ok {
246
- // Create new mcp section
247
- existingData ["mcp" ] = map [string ]interface {}{
248
- "servers" : map [string ]interface {}{
249
- "defang" : config ,
250
- },
251
- }
252
- } else {
253
- // Update existing mcp section
254
- mcpMap , ok := mcpData .(map [string ]interface {})
255
- if ! ok {
256
- mcpMap = make (map [string ]interface {})
257
- }
258
-
259
- serversData , ok := mcpMap ["servers" ]
260
- if ! ok {
261
- mcpMap ["servers" ] = map [string ]interface {}{
262
- "defang" : config ,
263
- }
264
- } else {
265
- serversMap , ok := serversData .(map [string ]interface {})
266
- if ! ok {
267
- serversMap = make (map [string ]interface {})
268
- }
269
-
270
- // Add or update the Defang MCP server config
271
- serversMap ["defang" ] = config
272
-
273
- mcpMap ["servers" ] = serversMap
274
- }
247
+ // Create new "servers" section
248
+ existingData ["servers" ] = map [string ]interface {}{}
249
+ serversSection = existingData ["servers" ]
250
+ }
275
251
276
- existingData ["mcp" ] = mcpMap
252
+ if mcpMap , ok := serversSection .(map [string ]interface {}); ok {
253
+ mcpMap ["defang" ] = config
254
+ existingData ["servers" ] = mcpMap
255
+ } else {
256
+ return errors .New ("failed to assert 'servers' section as map[string]interface{}" )
277
257
}
278
258
} else {
279
259
// File doesn't exist, create a new config with minimal settings
280
260
existingData = map [string ]interface {}{
281
- "mcp" : map [string ]interface {}{
282
- "servers" : map [string ]interface {}{
283
- "defang" : config ,
284
- },
261
+ "servers" : map [string ]interface {}{
262
+ "defang" : config ,
285
263
},
286
264
}
287
265
}
@@ -351,11 +329,10 @@ func handleStandardConfig(configPath string) error {
351
329
return nil
352
330
}
353
331
354
- func SetupClient (clientValue string ) error {
355
- client , err := ParseMCPClient (clientValue )
332
+ func SetupClient (clientStr string ) error {
333
+ client , err := ParseMCPClient (clientStr )
356
334
if err != nil {
357
- // cast the client string to MCPClient
358
- return fmt .Errorf ("invalid MCP client: %q. Valid MCP clients are: %v" , client , ValidClients )
335
+ return err
359
336
}
360
337
361
338
track .Evt ("MCP Setup Client: " , track .P ("client" , client ))
0 commit comments