Skip to content

Commit 2300366

Browse files
feat(get-server-tools): add GetTool method for retrieve MCPServer.tools (#437)
1 parent 3d1bfca commit 2300366

File tree

2 files changed

+571
-0
lines changed

2 files changed

+571
-0
lines changed

server/server.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,30 @@ func (s *MCPServer) SetTools(tools ...ServerTool) {
591591
s.AddTools(tools...)
592592
}
593593

594+
// GetTool retrieves the specified tool
595+
func (s *MCPServer) GetTool(toolName string) *ServerTool {
596+
s.toolsMu.RLock()
597+
defer s.toolsMu.RUnlock()
598+
if tool, ok := s.tools[toolName]; ok {
599+
return &tool
600+
}
601+
return nil
602+
}
603+
604+
func (s *MCPServer) ListTools() map[string]*ServerTool {
605+
s.toolsMu.RLock()
606+
defer s.toolsMu.RUnlock()
607+
if len(s.tools) == 0 {
608+
return nil
609+
}
610+
// Create a copy to prevent external modification
611+
toolsCopy := make(map[string]*ServerTool, len(s.tools))
612+
for name, tool := range s.tools {
613+
toolsCopy[name] = &tool
614+
}
615+
return toolsCopy
616+
}
617+
594618
// DeleteTools removes tools from the server
595619
func (s *MCPServer) DeleteTools(names ...string) {
596620
s.toolsMu.Lock()

0 commit comments

Comments
 (0)