Skip to content

Commit 30adde0

Browse files
committed
change name to RawName and have method for Name() that is normalized
1 parent a48bc5a commit 30adde0

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
@@ -13,17 +13,15 @@ import (
1313
var mcpToolListJSON []byte
1414

1515
type MCPToolDef 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-
type InputProperty struct {
23-
Name string
24-
Type string
25-
Description string
26-
ItemType string
22+
func (m *MCPToolDef) Name() string {
23+
name, _ := strings.CutPrefix(m.RawName, "sg_")
24+
return strings.ReplaceAll(name, "_", "-")
2725
}
2826

2927
type Schema struct {
@@ -143,12 +141,6 @@ func (p *Parser) parseProperties(props map[string]json.RawMessage) map[string]Sc
143141
return res
144142
}
145143

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

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

179174
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)