这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions acp/config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: ghcr.io/humanlayer/agentcontrolplane
newTag: v0.5.0
newName: controller
newTag: "202504151521"
2 changes: 1 addition & 1 deletion acp/config/samples/acp_v1alpha1_claude_task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ metadata:
spec:
agentRef:
name: claude-fetch-agent
message: "Write me a haiku about the character found at https://swapi.dev/api/people/2?"
userMessage: "Write me a haiku about the character found at https://swapi.dev/api/people/2?"
63 changes: 63 additions & 0 deletions acp/internal/adapters/mcp_adapter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package adapters

import (
"k8s.io/apimachinery/pkg/runtime"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

acp "github.com/humanlayer/agentcontrolplane/acp/api/v1alpha1"
)

var _ = Describe("MCP Adapter", func() {
Context("When converting MCP tools to LLM client tools", func() {
It("should correctly format tool names with server prefix", func() {
// Create sample tools with different names
tools := []acp.MCPTool{
{
Name: "fetch",
Description: "Fetches data from URL",
InputSchema: runtime.RawExtension{Raw: []byte(`{"type":"object"}`)},
},
{
Name: "calculate",
Description: "Performs calculations",
InputSchema: runtime.RawExtension{Raw: []byte(`{"type":"object"}`)},
},
}

// Test with a server name different from tool names
By("using a server name different from tool names")
serverName := "server-alpha"
result := ConvertMCPToolsToLLMClientTools(tools, serverName)

// Verify correct naming
Expect(result).To(HaveLen(2))
Expect(result[0].Function.Name).To(Equal("server-alpha__fetch"))
Expect(result[1].Function.Name).To(Equal("server-alpha__calculate"))

// Test with a server name similar to a tool name (the bug scenario)
By("using a server name that contains a tool name")
serverName = "fetch-server"
result = ConvertMCPToolsToLLMClientTools(tools, serverName)

// Verify correct naming - even when server name contains tool name
Expect(result).To(HaveLen(2))
Expect(result[0].Function.Name).To(Equal("fetch-server__fetch"))
Expect(result[1].Function.Name).To(Equal("fetch-server__calculate"))

// Verify the bug case specifically - tool name should never be used as server name
By("ensuring tool name is never used as server name (the bug case)")
for _, tool := range result {
Expect(tool.Function.Name).NotTo(Equal("fetch__fetch"))
Expect(tool.Function.Name).NotTo(Equal("calculate__calculate"))
}
})

It("should handle empty tool list", func() {
serverName := "test-server"
result := ConvertMCPToolsToLLMClientTools([]acp.MCPTool{}, serverName)
Expect(result).To(BeEmpty())
})
})
})
13 changes: 13 additions & 0 deletions acp/internal/adapters/suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package adapters

import (
testing "testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestAdapters(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Adapters Suite")
}
16 changes: 10 additions & 6 deletions acp/internal/controller/task/task_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,16 @@ func (r *TaskReconciler) collectTools(ctx context.Context, agent *acp.Agent) []l
logger := log.FromContext(ctx)
tools := make([]llmclient.Tool, 0)

// Get tools from MCP manager
mcpTools := r.MCPManager.GetToolsForAgent(agent)

// Convert MCP tools to LLM tools
for _, mcpTool := range mcpTools {
tools = append(tools, adapters.ConvertMCPToolsToLLMClientTools([]acp.MCPTool{mcpTool}, mcpTool.Name)...)
// Iterate through each MCP server directly to maintain server-tool association
for _, serverRef := range agent.Spec.MCPServers {
mcpTools, found := r.MCPManager.GetTools(serverRef.Name)
if !found {
logger.Info("Server not found or has no tools", "server", serverRef.Name)
continue
}
// Use the correct server name when converting tools
tools = append(tools, adapters.ConvertMCPToolsToLLMClientTools(mcpTools, serverRef.Name)...)
logger.Info("Added MCP server tools", "server", serverRef.Name, "toolCount", len(mcpTools))
}

// Convert HumanContactChannel tools to LLM tools
Expand Down