feat: add test to ensure BuildMCPTools skips graph and builtin tools
This commit is contained in:
@@ -34,6 +34,9 @@ func (f *ToolFactory) BuildMCPTools(aiAgent *models.AIAgent) ([]runtimetooling.M
|
|||||||
if toolCode == "" {
|
if toolCode == "" {
|
||||||
toolCode = toolx.BuildMCPToolCode(item.ServerCode, item.ToolName)
|
toolCode = toolx.BuildMCPToolCode(item.ServerCode, item.ToolName)
|
||||||
}
|
}
|
||||||
|
if toolx.ResolveToolSourceType(toolCode) != "mcp" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
serverCode, toolName := toolx.SplitMCPToolCode(toolCode)
|
serverCode, toolName := toolx.SplitMCPToolCode(toolCode)
|
||||||
if serverCode == "" || toolName == "" {
|
if serverCode == "" || toolName == "" {
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package factory
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"cs-agent/internal/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestBuildMCPToolsSkipsGraphAndBuiltinTools(t *testing.T) {
|
||||||
|
aiAgent := &models.AIAgent{
|
||||||
|
AllowedMCPTools: `[
|
||||||
|
{"toolCode":"graph/create_ticket_with_confirmation","serverCode":"graph","toolName":"create_ticket_with_confirmation"},
|
||||||
|
{"toolCode":"builtin/tool_search","serverCode":"builtin","toolName":"tool_search"},
|
||||||
|
{"toolCode":"system/list_agents","serverCode":"system","toolName":"list_agents"}
|
||||||
|
]`,
|
||||||
|
}
|
||||||
|
|
||||||
|
got, err := NewToolFactory().BuildMCPTools(aiAgent)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("BuildMCPTools returned error: %v", err)
|
||||||
|
}
|
||||||
|
if len(got) != 1 {
|
||||||
|
t.Fatalf("expected 1 dynamic mcp tool, got %d: %#v", len(got), got)
|
||||||
|
}
|
||||||
|
if got[0].ToolCode != "system/list_agents" {
|
||||||
|
t.Fatalf("unexpected tool code: %#v", got[0])
|
||||||
|
}
|
||||||
|
if got[0].ServerCode != "system" || got[0].ToolName != "list_agents" {
|
||||||
|
t.Fatalf("unexpected tool identity: %#v", got[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user