Skip to content

Commit eb5a874

Browse files
authored
Merge pull request #75 from AdjectiveAllison/allison/eng-1215-acp-mcp-tool-naming-bug
Allison/eng 1215 acp mcp tool naming bug
2 parents d72af16 + 35f56ed commit eb5a874

File tree

5 files changed

+89
-9
lines changed

5 files changed

+89
-9
lines changed

acp/config/manager/kustomization.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1
44
kind: Kustomization
55
images:
66
- name: controller
7-
newName: ghcr.io/humanlayer/agentcontrolplane
8-
newTag: v0.5.0
7+
newName: controller
8+
newTag: "202504151521"

acp/config/samples/acp_v1alpha1_claude_task.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ metadata:
55
spec:
66
agentRef:
77
name: claude-fetch-agent
8-
message: "Write me a haiku about the character found at https://swapi.dev/api/people/2?"
8+
userMessage: "Write me a haiku about the character found at https://swapi.dev/api/people/2?"
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package adapters
2+
3+
import (
4+
"k8s.io/apimachinery/pkg/runtime"
5+
6+
. "github.com/onsi/ginkgo/v2"
7+
. "github.com/onsi/gomega"
8+
9+
acp "github.com/humanlayer/agentcontrolplane/acp/api/v1alpha1"
10+
)
11+
12+
var _ = Describe("MCP Adapter", func() {
13+
Context("When converting MCP tools to LLM client tools", func() {
14+
It("should correctly format tool names with server prefix", func() {
15+
// Create sample tools with different names
16+
tools := []acp.MCPTool{
17+
{
18+
Name: "fetch",
19+
Description: "Fetches data from URL",
20+
InputSchema: runtime.RawExtension{Raw: []byte(`{"type":"object"}`)},
21+
},
22+
{
23+
Name: "calculate",
24+
Description: "Performs calculations",
25+
InputSchema: runtime.RawExtension{Raw: []byte(`{"type":"object"}`)},
26+
},
27+
}
28+
29+
// Test with a server name different from tool names
30+
By("using a server name different from tool names")
31+
serverName := "server-alpha"
32+
result := ConvertMCPToolsToLLMClientTools(tools, serverName)
33+
34+
// Verify correct naming
35+
Expect(result).To(HaveLen(2))
36+
Expect(result[0].Function.Name).To(Equal("server-alpha__fetch"))
37+
Expect(result[1].Function.Name).To(Equal("server-alpha__calculate"))
38+
39+
// Test with a server name similar to a tool name (the bug scenario)
40+
By("using a server name that contains a tool name")
41+
serverName = "fetch-server"
42+
result = ConvertMCPToolsToLLMClientTools(tools, serverName)
43+
44+
// Verify correct naming - even when server name contains tool name
45+
Expect(result).To(HaveLen(2))
46+
Expect(result[0].Function.Name).To(Equal("fetch-server__fetch"))
47+
Expect(result[1].Function.Name).To(Equal("fetch-server__calculate"))
48+
49+
// Verify the bug case specifically - tool name should never be used as server name
50+
By("ensuring tool name is never used as server name (the bug case)")
51+
for _, tool := range result {
52+
Expect(tool.Function.Name).NotTo(Equal("fetch__fetch"))
53+
Expect(tool.Function.Name).NotTo(Equal("calculate__calculate"))
54+
}
55+
})
56+
57+
It("should handle empty tool list", func() {
58+
serverName := "test-server"
59+
result := ConvertMCPToolsToLLMClientTools([]acp.MCPTool{}, serverName)
60+
Expect(result).To(BeEmpty())
61+
})
62+
})
63+
})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package adapters
2+
3+
import (
4+
testing "testing"
5+
6+
. "github.com/onsi/ginkgo/v2"
7+
. "github.com/onsi/gomega"
8+
)
9+
10+
func TestAdapters(t *testing.T) {
11+
RegisterFailHandler(Fail)
12+
RunSpecs(t, "Adapters Suite")
13+
}

acp/internal/controller/task/task_controller.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,16 @@ func (r *TaskReconciler) collectTools(ctx context.Context, agent *acp.Agent) []l
358358
logger := log.FromContext(ctx)
359359
tools := make([]llmclient.Tool, 0)
360360

361-
// Get tools from MCP manager
362-
mcpTools := r.MCPManager.GetToolsForAgent(agent)
363-
364-
// Convert MCP tools to LLM tools
365-
for _, mcpTool := range mcpTools {
366-
tools = append(tools, adapters.ConvertMCPToolsToLLMClientTools([]acp.MCPTool{mcpTool}, mcpTool.Name)...)
361+
// Iterate through each MCP server directly to maintain server-tool association
362+
for _, serverRef := range agent.Spec.MCPServers {
363+
mcpTools, found := r.MCPManager.GetTools(serverRef.Name)
364+
if !found {
365+
logger.Info("Server not found or has no tools", "server", serverRef.Name)
366+
continue
367+
}
368+
// Use the correct server name when converting tools
369+
tools = append(tools, adapters.ConvertMCPToolsToLLMClientTools(mcpTools, serverRef.Name)...)
370+
logger.Info("Added MCP server tools", "server", serverRef.Name, "toolCount", len(mcpTools))
367371
}
368372

369373
// Convert HumanContactChannel tools to LLM tools

0 commit comments

Comments
 (0)