Skip to content

Commit 8a38cd8

Browse files
committed
reduce duplicate read write tool loops
Signed-off-by: hungran <26101787+hungran@users.noreply.github.com>
1 parent 20d248c commit 8a38cd8

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

pkg/toolsets/toolsets.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,22 +107,21 @@ func (t *Toolset) RegisterTools(s *server.MCPServer, prefix string) {
107107
if !t.Enabled {
108108
return
109109
}
110-
for _, tool := range t.readTools {
110+
registerToolWithPrefix := func(tool server.ServerTool) {
111111
toolToRegister := tool.Tool
112112
if prefix != "" {
113113
// Create a new tool with the prefixed name
114114
toolToRegister = createToolWithPrefixedName(tool.Tool, prefix)
115115
}
116116
s.AddTool(toolToRegister, tool.Handler)
117117
}
118+
119+
for _, tool := range t.readTools {
120+
registerToolWithPrefix(tool)
121+
}
118122
if !t.readOnly {
119123
for _, tool := range t.writeTools {
120-
toolToRegister := tool.Tool
121-
if prefix != "" {
122-
// Create a new tool with the prefixed name
123-
toolToRegister = createToolWithPrefixedName(tool.Tool, prefix)
124-
}
125-
s.AddTool(toolToRegister, tool.Handler)
124+
registerToolWithPrefix(tool)
126125
}
127126
}
128127
}

0 commit comments

Comments
 (0)