Skip to content

Commit 783768f

Browse files
authored
Merge pull request #1053 from dgageot/better-toolnames
Better tool names for MCP and A2A
2 parents 70db978 + 19bcac1 commit 783768f

File tree

8 files changed

+27
-21
lines changed

8 files changed

+27
-21
lines changed

cmd/root/mcp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (f *mcpFlags) runMCPCommand(cmd *cobra.Command, args []string) error {
4848
ctx := cmd.Context()
4949
agentFilename := args[0]
5050

51-
if f.http {
51+
if f.http || f.port != 0 {
5252
ln, err := server.Listen(ctx, fmt.Sprintf(":%d", f.port))
5353
if err != nil {
5454
return fmt.Errorf("failed to bind to port %d: %w", f.port, err)

examples/tic-tac-toe.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ agents:
4646
- type: shell
4747
- type: filesystem
4848
- type: a2a
49-
name: player_blue
5049
url: http://localhost:8080/
5150
- type: a2a
52-
name: player_red
5351
url: http://localhost:8081/
5452

5553
# BLUE Player

pkg/a2a/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ func Run(ctx context.Context, agentFilename, agentName string, runConfig *config
5757
Name: name,
5858
Description: adkAgent.Description(),
5959
Skills: []a2a.AgentSkill{{
60-
ID: name,
61-
Name: "main",
60+
ID: fmt.Sprintf("%s_%s", name, agentName),
61+
Name: agentName,
6262
Description: adkAgent.Description(),
6363
Tags: []string{"llm", "cagent"},
6464
}},

pkg/config/latest/validate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ func (t *Toolset) validate() error {
6969
if t.URL != "" && t.Type != "a2a" {
7070
return errors.New("url can only be used with type 'a2a'")
7171
}
72-
if t.Name != "" && t.Type != "a2a" {
73-
return errors.New("name can only be used with type 'a2a'")
72+
if t.Name != "" && (t.Type != "mcp" && t.Type != "a2a") {
73+
return errors.New("name can only be used with type 'mcp' or 'a2a'")
7474
}
7575

7676
switch t.Type {

pkg/teamloader/registry.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ func createMCPTool(ctx context.Context, toolset latest.Toolset, _ string, runCon
195195

196196
// TODO(dga): until the MCP Gateway supports oauth with cagent, we fetch the remote url and directly connect to it.
197197
if serverSpec.Type == "remote" {
198-
return mcp.NewRemoteToolset(serverSpec.Remote.URL, serverSpec.Remote.TransportType, nil), nil
198+
return mcp.NewRemoteToolset(toolset.Name, serverSpec.Remote.URL, serverSpec.Remote.TransportType, nil), nil
199199
}
200200

201-
return mcp.NewGatewayToolset(ctx, mcpServerName, toolset.Config, runConfig.EnvProvider(), runConfig.WorkingDir)
201+
return mcp.NewGatewayToolset(ctx, toolset.Name, mcpServerName, toolset.Config, runConfig.EnvProvider(), runConfig.WorkingDir)
202202
}
203203

204204
if toolset.Command != "" {
@@ -207,7 +207,7 @@ func createMCPTool(ctx context.Context, toolset latest.Toolset, _ string, runCon
207207
return nil, fmt.Errorf("failed to expand the tool's environment variables: %w", err)
208208
}
209209
env = append(env, os.Environ()...)
210-
return mcp.NewToolsetCommand(toolset.Command, toolset.Args, env, runConfig.WorkingDir), nil
210+
return mcp.NewToolsetCommand(toolset.Name, toolset.Command, toolset.Args, env, runConfig.WorkingDir), nil
211211
}
212212

213213
if toolset.Remote.URL != "" {
@@ -221,7 +221,7 @@ func createMCPTool(ctx context.Context, toolset latest.Toolset, _ string, runCon
221221
headers[k] = expanded
222222
}
223223

224-
return mcp.NewRemoteToolset(toolset.Remote.URL, toolset.Remote.TransportType, headers), nil
224+
return mcp.NewRemoteToolset(toolset.Name, toolset.Remote.URL, toolset.Remote.TransportType, headers), nil
225225
}
226226

227227
return nil, fmt.Errorf("mcp toolset requires either ref, command, or remote configuration")

pkg/tools/a2a/a2a.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ func (t *Toolset) Tools(_ context.Context) ([]tools.Tool, error) {
7878

7979
result := make([]tools.Tool, 0, len(skills))
8080
for _, skill := range skills {
81-
name := t.name
82-
if name == "" {
83-
name = skill.ID
84-
}
81+
name := skill.ID
8582
if name == "" {
8683
name = skill.Name
8784
}
85+
if t.name != "" {
86+
name = fmt.Sprintf("%s_%s", t.name, name)
87+
}
8888
name = sanitizeToolName(name)
8989

9090
result = append(result, tools.Tool{

pkg/tools/mcp/gateway.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type GatewayToolset struct {
2222

2323
var _ tools.ToolSet = (*GatewayToolset)(nil)
2424

25-
func NewGatewayToolset(ctx context.Context, mcpServerName string, config any, envProvider environment.Provider, cwd string) (*GatewayToolset, error) {
25+
func NewGatewayToolset(ctx context.Context, name, mcpServerName string, config any, envProvider environment.Provider, cwd string) (*GatewayToolset, error) {
2626
slog.Debug("Creating MCP Gateway toolset", "name", mcpServerName)
2727

2828
// Check which secrets (env vars) are required by the MCP server.
@@ -55,7 +55,7 @@ func NewGatewayToolset(ctx context.Context, mcpServerName string, config any, en
5555
}
5656

5757
return &GatewayToolset{
58-
cmdToolset: NewToolsetCommand("docker", args, nil, cwd),
58+
cmdToolset: NewToolsetCommand(name, "docker", args, nil, cwd),
5959
cleanUp: func() error {
6060
return errors.Join(os.Remove(fileSecrets), os.Remove(fileConfig))
6161
},

pkg/tools/mcp/mcp.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type mcpClient interface {
3030

3131
// Toolset represents a set of MCP tools
3232
type Toolset struct {
33+
name string
3334
mcpClient mcpClient
3435
logID string
3536
instructions string
@@ -39,20 +40,22 @@ type Toolset struct {
3940
var _ tools.ToolSet = (*Toolset)(nil)
4041

4142
// NewToolsetCommand creates a new MCP toolset from a command.
42-
func NewToolsetCommand(command string, args, env []string, cwd string) *Toolset {
43+
func NewToolsetCommand(name, command string, args, env []string, cwd string) *Toolset {
4344
slog.Debug("Creating Stdio MCP toolset", "command", command, "args", args)
4445

4546
return &Toolset{
47+
name: name,
4648
mcpClient: newStdioCmdClient(command, args, env, cwd),
4749
logID: command,
4850
}
4951
}
5052

5153
// NewRemoteToolset creates a new MCP toolset from a remote MCP Server.
52-
func NewRemoteToolset(url, transport string, headers map[string]string) *Toolset {
54+
func NewRemoteToolset(name, url, transport string, headers map[string]string) *Toolset {
5355
slog.Debug("Creating Remote MCP toolset", "url", url, "transport", transport, "headers", headers)
5456

5557
return &Toolset{
58+
name: name,
5659
mcpClient: newRemoteClient(url, transport, headers, NewInMemoryTokenStore(), false),
5760
logID: url,
5861
}
@@ -139,8 +142,13 @@ func (ts *Toolset) Tools(ctx context.Context) ([]tools.Tool, error) {
139142
return nil, err
140143
}
141144

145+
name := t.Name
146+
if ts.name != "" {
147+
name = fmt.Sprintf("%s_%s", ts.name, name)
148+
}
149+
142150
tool := tools.Tool{
143-
Name: t.Name,
151+
Name: name,
144152
Description: t.Description,
145153
Parameters: t.InputSchema,
146154
OutputSchema: t.OutputSchema,
@@ -151,7 +159,7 @@ func (ts *Toolset) Tools(ctx context.Context) ([]tools.Tool, error) {
151159
}
152160
toolsList = append(toolsList, tool)
153161

154-
slog.Debug("Added MCP tool", "tool", t.Name)
162+
slog.Debug("Added MCP tool", "tool", name)
155163
}
156164

157165
slog.Debug("Listed MCP tools", "count", len(toolsList))

0 commit comments

Comments
 (0)