@@ -21,6 +21,7 @@ import (
2121 "github.com/docker/cagent/pkg/tools"
2222 "github.com/docker/cagent/pkg/tools/builtin"
2323 "github.com/docker/cagent/pkg/tools/mcp"
24+ "gopkg.in/yaml.v3"
2425)
2526
2627// LoadTeams loads all agent teams from the given directory or file path
@@ -262,15 +263,38 @@ func getToolsForAgent(a *latest.AgentConfig, parentDir string, sharedTools map[s
262263 t = append (t , builtin .NewFilesystemTool ([]string {wd }, builtin .WithAllowedTools (toolset .Tools )))
263264
264265 case toolset .Type == "mcp" && toolset .Ref != "" :
265- serverName := strings .TrimPrefix (toolset .Ref , "docker:" )
266-
267266 env , err := toolsetEnv (toolset .Env , append (absEnvFiles , toolset .Envfiles ... ), parentDir )
268267 if err != nil {
269268 return nil , err
270269 }
271270
271+ serverName := strings .TrimPrefix (toolset .Ref , "docker:" )
272+ args := []string {"mcp" , "gateway" , "run" , "--servers=" + serverName }
273+
274+ if toolset .Config != nil {
275+ serverConfig := map [string ]any {
276+ serverName : toolset .Config ,
277+ }
278+
279+ file , err := os .CreateTemp ("" , "mcp-config-*.yaml" )
280+ if err != nil {
281+ return nil , fmt .Errorf ("failed to create temp file: %w" , err )
282+ }
283+ // TODO(dga): Delete the temp file after use.
284+
285+ if err := yaml .NewEncoder (file ).Encode (serverConfig ); err != nil {
286+ return nil , fmt .Errorf ("failed to write config to temp file: %w" , err )
287+ }
288+
289+ args = append (args , "--config=" + file .Name ())
290+ }
291+
292+ // Isolate ourselves from the global MCP Gateway config by always using the docker MCP catalog.
293+ // This improves shareability of agent configs.
294+ args = append (args , "--catalog=https://desktop.docker.com/mcp/catalog/v2/catalog.yaml" )
295+
272296 // TODO(dga): If the server's docker image had the right annotations, we could run it directly with `docker run` or with the MCP gateway as a go library.
273- t = append (t , mcp .NewToolsetCommand ("docker" , [] string { "mcp" , "gateway" , "run" , "--servers=" + serverName } , env , toolset .Tools ))
297+ t = append (t , mcp .NewToolsetCommand ("docker" , args , env , toolset .Tools ))
274298
275299 case toolset .Type == "mcp" && toolset .Command != "" :
276300 // Expand env first because it's used when expanding command and args.
0 commit comments