Skip to content

Commit bae1fb1

Browse files
committed
change name to RawName and have method for Name() that is normalized
1 parent 2414ed5 commit bae1fb1

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

internal/mcp/mcp_parse.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@ import (
1313
var mcpToolListJSON []byte
1414

1515
type ToolDef struct {
16-
Name string `json:"name"`
16+
RawName string `json:"name"`
1717
Description string `json:"description"`
1818
InputSchema Schema `json:"inputSchema"`
1919
OutputSchema Schema `json:"outputSchema"`
2020
}
2121

22+
func (m *ToolDef) Name() string {
23+
name, _ := strings.CutPrefix(m.RawName, "sg_")
24+
return strings.ReplaceAll(name, "_", "-")
25+
}
26+
2227
type RawSchema struct {
2328
Type string `json:"type"`
2429
Description string `json:"description"`
@@ -98,6 +103,10 @@ func loadToolDefinitions(data []byte) (map[string]*ToolDef, error) {
98103
}
99104
}
100105

106+
// make it so that can find a tool definition by it's original name (RawName) and normalized name (Name())
107+
tools[def.RawName] = def
108+
tools[def.Name()] = def
109+
101110
if len(parser.errors) > 0 {
102111
return tools, errors.Append(nil, parser.errors...)
103112
}
@@ -169,9 +178,3 @@ func (p *parser) parseProperties(props map[string]json.RawMessage) map[string]Sc
169178
}
170179
return res
171180
}
172-
173-
// normalizeToolName takes mcp tool names like 'sg_keyword_search' and normalizes it to 'keyword-search"
174-
func normalizeToolName(toolName string) string {
175-
toolName, _ = strings.CutPrefix(toolName, "sg_")
176-
return strings.ReplaceAll(toolName, "_", "-")
177-
}

internal/mcp/mcp_parse_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,13 @@ func TestLoadToolDefinitions(t *testing.T) {
4646
t.Fatalf("Expected 1 tool, got %d", len(tools))
4747
}
4848

49-
// Temporary: map keys have normalized names
5049
tool := tools["test-tool"]
5150
if tool == nil {
5251
t.Fatal("Tool 'test_tool' not found")
5352
}
5453

55-
if tool.Name != "test_tool" {
56-
t.Errorf("Expected name 'test_tool', got '%s'", tool.Name)
54+
if tool.RawName != "sg_test_tool" {
55+
t.Errorf("Expected name 'sg_test_tool', got '%s'", tool.RawName)
5756
}
5857

5958
inputSchema := tool.InputSchema

0 commit comments

Comments
 (0)