Skip to content

Commit 75745b3

Browse files
committed
change name to RawName and have method for Name() that is normalized
1 parent f243dec commit 75745b3

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

cmd/src/mcp_parse.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,15 @@ import (
1414
var _ []byte
1515

1616
type MCPToolDef struct {
17-
Name string `json:"name"`
17+
RawName string `json:"name"`
1818
Description string `json:"description"`
1919
InputSchema Schema `json:"inputSchema"`
2020
OutputSchema Schema `json:"outputSchema"`
2121
}
2222

23-
type InputProperty struct {
24-
Name string
25-
Type string
26-
Description string
27-
ItemType string
23+
func (m *MCPToolDef) Name() string {
24+
name, _ := strings.CutPrefix(m.RawName, "sg_")
25+
return strings.ReplaceAll(name, "_", "-")
2826
}
2927

3028
type Schema struct {
@@ -144,12 +142,6 @@ func (p *Parser) parseProperties(props map[string]json.RawMessage) map[string]Sc
144142
return res
145143
}
146144

147-
// normalizeToolName takes mcp tool names like 'sg_keyword_search' and normalizes it to 'keyword-search"
148-
func normalizeToolName(toolName string) string {
149-
toolName, _ = strings.CutPrefix(toolName, "sg_")
150-
return strings.ReplaceAll(toolName, "_", "-")
151-
}
152-
153145
func LoadMCPToolDefinitions(data []byte) (map[string]*MCPToolDef, error) {
154146
defs := struct {
155147
Tools []struct {
@@ -168,13 +160,16 @@ func LoadMCPToolDefinitions(data []byte) (map[string]*MCPToolDef, error) {
168160
parser := &Parser{}
169161

170162
for _, t := range defs.Tools {
171-
name := normalizeToolName(t.Name)
172-
tools[name] = &MCPToolDef{
173-
Name: t.Name,
163+
def := &MCPToolDef{
164+
RawName: t.Name,
174165
Description: t.Description,
175166
InputSchema: parser.parseRootSchema(t.InputSchema),
176167
OutputSchema: parser.parseRootSchema(t.OutputSchema),
177168
}
169+
170+
// make it so that can find a tool definition by it's original name (RawName) and normalized name (Name())
171+
tools[def.RawName] = def
172+
tools[def.Name()] = def
178173
}
179174

180175
if len(parser.errors) > 0 {

cmd/src/mcp_parse_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,19 @@ func TestLoadMCPToolDefinitions(t *testing.T) {
4242
t.Fatalf("Failed to load tool definitions: %v", err)
4343
}
4444

45+
panic("WILL")
46+
4547
if len(tools) != 1 {
4648
t.Fatalf("Expected 1 tool, got %d", len(tools))
4749
}
4850

49-
tool := tools["test_tool"]
51+
tool := tools["sg_test_tool"]
5052
if tool == nil {
5153
t.Fatal("Tool 'test_tool' not found")
5254
}
5355

54-
if tool.Name != "test_tool" {
55-
t.Errorf("Expected name 'test_tool', got '%s'", tool.Name)
56+
if tool.RawName != "test-tool" {
57+
t.Errorf("Expected name 'test_tool', got '%s'", tool.RawName)
5658
}
5759

5860
inputSchema := tool.InputSchema

0 commit comments

Comments
 (0)