diff --git a/internal/mcp/mcp_parse.go b/internal/mcp/mcp_parse.go index 65aa14fbb1..ce35fc3e4d 100644 --- a/internal/mcp/mcp_parse.go +++ b/internal/mcp/mcp_parse.go @@ -13,7 +13,8 @@ import ( var mcpToolListJSON []byte type ToolDef struct { - Name string `json:"name"` + Name string + RawName string `json:"name"` Description string `json:"description"` InputSchema Schema `json:"inputSchema"` OutputSchema Schema `json:"outputSchema"` @@ -89,13 +90,19 @@ func loadToolDefinitions(data []byte) (map[string]*ToolDef, error) { decoder := &decoder{} for _, t := range defs.Tools { - name := normalizeToolName(t.Name) - tools[name] = &ToolDef{ - Name: t.Name, + // normalize the raw mcp tool name to be without the mcp identifiers + rawName := t.Name + name, _ := strings.CutPrefix(rawName, "sg_") + name = strings.ReplaceAll(name, "_", "-") + + tool := &ToolDef{ + Name: name, + RawName: rawName, Description: t.Description, InputSchema: decoder.decodeRootSchema(t.InputSchema), OutputSchema: decoder.decodeRootSchema(t.OutputSchema), } + tools[tool.Name] = tool } if len(decoder.errors) > 0 { @@ -169,9 +176,3 @@ func (d *decoder) decodeProperties(props map[string]json.RawMessage) map[string] } return res } - -// normalizeToolName takes mcp tool names like 'sg_keyword_search' and normalizes it to 'keyword-search" -func normalizeToolName(toolName string) string { - toolName, _ = strings.CutPrefix(toolName, "sg_") - return strings.ReplaceAll(toolName, "_", "-") -} diff --git a/internal/mcp/mcp_parse_test.go b/internal/mcp/mcp_parse_test.go index 13adcadc03..075d0b0453 100644 --- a/internal/mcp/mcp_parse_test.go +++ b/internal/mcp/mcp_parse_test.go @@ -8,7 +8,7 @@ func TestLoadToolDefinitions(t *testing.T) { toolJSON := []byte(`{ "tools": [ { - "name": "test_tool", + "name": "sg_test_tool", "description": "test description", "inputSchema": { "type": "object", @@ -46,14 +46,13 @@ func TestLoadToolDefinitions(t *testing.T) { t.Fatalf("Expected 1 tool, got %d", len(tools)) } - // Temporary: map keys have normalized names tool := tools["test-tool"] if tool == nil { t.Fatal("Tool 'test_tool' not found") } - if tool.Name != "test_tool" { - t.Errorf("Expected name 'test_tool', got '%s'", tool.Name) + if tool.RawName != "sg_test_tool" { + t.Errorf("Expected name 'sg_test_tool', got '%s'", tool.RawName) } inputSchema := tool.InputSchema