@@ -209,7 +209,7 @@ type ServerMatch struct {
209209}
210210
211211// mcpAddTool implements a tool for adding new servers to the registry
212- func (g * Gateway ) createMcpAddTool (configuration Configuration , clientConfig * clientConfig ) * ToolRegistration {
212+ func (g * Gateway ) createMcpAddTool (clientConfig * clientConfig ) * ToolRegistration {
213213 tool := & mcp.Tool {
214214 Name : "mcp-add" ,
215215 Description : "Add a new MCP server to the session. The server must exist in the catalog." ,
@@ -251,7 +251,7 @@ func (g *Gateway) createMcpAddTool(configuration Configuration, clientConfig *cl
251251 serverName := strings .TrimSpace (params .Name )
252252
253253 // Check if server exists in catalog
254- serverConfig , _ , found := configuration .Find (serverName )
254+ _ , _ , found := g . configuration .Find (serverName )
255255 if ! found {
256256 return & mcp.CallToolResult {
257257 Content : []mcp.Content {& mcp.TextContent {
@@ -262,36 +262,34 @@ func (g *Gateway) createMcpAddTool(configuration Configuration, clientConfig *cl
262262
263263 // Append the new server to the current serverNames if not already present
264264 found = false
265- for _ , existing := range configuration .serverNames {
265+ for _ , existing := range g . configuration .serverNames {
266266 if existing == serverName {
267267 found = true
268268 break
269269 }
270270 }
271271 if ! found {
272- configuration .serverNames = append (configuration .serverNames , serverName )
272+ g . configuration .serverNames = append (g . configuration .serverNames , serverName )
273273 }
274274
275275 // Fetch updated secrets for the new server list
276276 if g .configurator != nil {
277277 if fbc , ok := g .configurator .(* FileBasedConfiguration ); ok {
278- updatedSecrets , err := fbc .readDockerDesktopSecrets (ctx , configuration .servers , configuration .serverNames )
278+ updatedSecrets , err := fbc .readDockerDesktopSecrets (ctx , g . configuration .servers , g . configuration .serverNames )
279279 if err == nil {
280- configuration .secrets = updatedSecrets
280+ g . configuration .secrets = updatedSecrets
281281 } else {
282282 log ("Warning: Failed to update secrets:" , err )
283283 }
284284 }
285285 }
286286
287- // Update the current configuration state
288- updatedServerNames := configuration .serverNames
289- if err := g .reloadConfiguration (ctx , configuration , updatedServerNames , clientConfig ); err != nil {
287+ if err := g .reloadServerConfiguration (ctx , serverName , clientConfig ); err != nil {
290288 return nil , fmt .Errorf ("failed to reload configuration: %w" , err )
291289 }
292290
293291 // Register DCR client and start OAuth provider if this is a remote OAuth server
294- if g .McpOAuthDcrEnabled && serverConfig . Spec . IsRemoteOAuthServer () {
292+ if g .McpOAuthDcrEnabled {
295293 // Register DCR client with DD so user can authorize
296294 if err := oauth .RegisterProviderForLazySetup (ctx , serverName ); err != nil {
297295 logf ("Warning: Failed to register OAuth provider for %s: %v" , serverName , err )
@@ -315,7 +313,7 @@ func (g *Gateway) createMcpAddTool(configuration Configuration, clientConfig *cl
315313}
316314
317315// mcpRemoveTool implements a tool for removing servers from the registry
318- func (g * Gateway ) createMcpRemoveTool (_ Configuration , clientConfig * clientConfig ) * ToolRegistration {
316+ func (g * Gateway ) createMcpRemoveTool () * ToolRegistration {
319317 tool := & mcp.Tool {
320318 Name : "mcp-remove" ,
321319 Description : "Remove an MCP server from the registry and reload the configuration. This will disable the server." ,
@@ -369,8 +367,8 @@ func (g *Gateway) createMcpRemoveTool(_ Configuration, clientConfig *clientConfi
369367 g .stopProvider (serverName )
370368 }
371369
372- if err := g .reloadConfiguration (ctx , g . configuration , updatedServerNames , clientConfig ); err != nil {
373- return nil , fmt .Errorf ("failed to reload configuration: %w" , err )
370+ if err := g .removeServerConfiguration (ctx , serverName ); err != nil {
371+ return nil , fmt .Errorf ("failed to remove server configuration: %w" , err )
374372 }
375373
376374 return & mcp.CallToolResult {
@@ -575,7 +573,7 @@ type configValue struct {
575573}
576574
577575// mcpConfigSetTool implements a tool for setting configuration values for MCP servers
578- func (g * Gateway ) createMcpConfigSetTool (configuration Configuration , clientConfig * clientConfig ) * ToolRegistration {
576+ func (g * Gateway ) createMcpConfigSetTool (clientConfig * clientConfig ) * ToolRegistration {
579577 tool := & mcp.Tool {
580578 Name : "mcp-config-set" ,
581579 Description : "Set configuration values for MCP servers. Creates or updates server configuration with the specified key-value pairs." ,
@@ -627,22 +625,22 @@ func (g *Gateway) createMcpConfigSetTool(configuration Configuration, clientConf
627625 configKey := strings .TrimSpace (params .Key )
628626
629627 // Check if server exists in catalog (optional check - we can configure servers that don't exist yet)
630- _ , _ , serverExists := configuration .Find (serverName )
628+ _ , _ , serverExists := g . configuration .Find (serverName )
631629
632630 // Initialize the server's config map if it doesn't exist
633- if configuration .config [serverName ] == nil {
634- configuration .config [serverName ] = make (map [string ]any )
631+ if g . configuration .config [serverName ] == nil {
632+ g . configuration .config [serverName ] = make (map [string ]any )
635633 }
636634
637635 // Set the configuration value
638- oldValue := configuration.config [serverName ][configKey ]
639- configuration.config [serverName ][configKey ] = params .Value
636+ oldValue := g . configuration .config [serverName ][configKey ]
637+ g . configuration .config [serverName ][configKey ] = params .Value
640638
641639 // Log the configuration change
642640 log (fmt .Sprintf (" - Set config for server '%s': %s = %v" , serverName , configKey , params .Value ))
643641
644642 // Reload configuration with current server list to apply changes
645- if err := g .reloadConfiguration (ctx , configuration , configuration . serverNames , clientConfig ); err != nil {
643+ if err := g .reloadServerConfiguration (ctx , serverName , clientConfig ); err != nil {
646644 return nil , fmt .Errorf ("failed to reload configuration: %w" , err )
647645 }
648646
0 commit comments