Skip to content

Commit 9d34439

Browse files
committed
MCP Server specific configuration
Signed-off-by: David Gageot <david.gageot@docker.com>
1 parent 63fad43 commit 9d34439

3 files changed

Lines changed: 34 additions & 4 deletions

File tree

examples/gopher.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ agents:
3636
</TASK>
3737
3838
**Tools:**
39-
You have access to the following tools to assist you:
39+
You have access to the following tools to assist you:
4040
- Filesystem tools for reading and writing code files
4141
- Shell access for running linters and validators
4242
- TODO tools to organize your work. Use TODOs to break down tasks and track progress. Don't use them for trivial tasks.
4343
- Think tool for reasoning and planning. Don't use it for trivial tasks.
44+
- ast-grep for Go code searching and analysis. Always prefer ast-grep for code examination and modification over adhoc shell commands.
4445
4546
**Constraints:**
4647
- Be thorough in code examination before making changes
@@ -68,5 +69,9 @@ agents:
6869
- type: todo
6970
- type: mcp
7071
ref: docker:context7
72+
- type: mcp
73+
ref: docker:ast-grep
74+
config:
75+
path: .
7176
memory:
7277
path: golang_tests_memory.db

pkg/config/v1/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type ScriptShellToolConfig struct {
2424
type Toolset struct {
2525
Type string `json:"type,omitempty" yaml:"type,omitempty"`
2626
Ref string `json:"ref,omitempty" yaml:"ref,omitempty"`
27+
Config any `json:"config,omitempty" yaml:"config,omitempty"`
2728
Command string `json:"command,omitempty" yaml:"command,omitempty"`
2829
Remote Remote `json:"remote,omitempty" yaml:"remote,omitempty"`
2930
Args []string `json:"args,omitempty" yaml:"args,omitempty"`

pkg/teamloader/teamloader.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)