Skip to content

Commit 31dcefd

Browse files
committed
change name to RawName and have method for Name() that is normalized
1 parent fb74076 commit 31dcefd

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

internal/mcp/mcp_parse.go

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

1414
type ToolDef struct {
15-
Name string `json:"name"`
16-
Description string `json:"description"`
17-
InputSchema SchemaObject `json:"inputSchema"`
18-
OutputSchema SchemaObject `json:"outputSchema"`
15+
RawName string `json:"name"`
16+
Description string `json:"description"`
17+
InputSchema Schema `json:"inputSchema"`
18+
OutputSchema Schema `json:"outputSchema"`
19+
}
20+
21+
func (m *ToolDef) Name() string {
22+
name, _ := strings.CutPrefix(m.RawName, "sg_")
23+
return strings.ReplaceAll(name, "_", "-")
1924
}
2025

2126
type RawSchema struct {
@@ -93,6 +98,10 @@ func loadToolDefinitions(data []byte) (map[string]*ToolDef, error) {
9398
}
9499
}
95100

101+
// make it so that can find a tool definition by it's original name (RawName) and normalized name (Name())
102+
tools[def.RawName] = def
103+
tools[def.Name()] = def
104+
96105
if len(decoder.errors) > 0 {
97106
return tools, errors.Append(nil, decoder.errors...)
98107
}
@@ -162,9 +171,3 @@ func (d *decoder) decodeProperties(props map[string]json.RawMessage) map[string]
162171
}
163172
return res
164173
}
165-
166-
// normalizeToolName takes mcp tool names like 'sg_keyword_search' and normalizes it to 'keyword-search"
167-
func normalizeToolName(toolName string) string {
168-
toolName, _ = strings.CutPrefix(toolName, "sg_")
169-
return strings.ReplaceAll(toolName, "_", "-")
170-
}

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)