|
| 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 | +}) |
0 commit comments