Skip to content

Commit 5b8ae98

Browse files
feat(get-server-tools): add GetTools method for retrieve MCPServer.tools
1 parent 8f5b048 commit 5b8ae98

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
@@ -493,6 +493,30 @@ func (s *MCPServer) SetTools(tools ...ServerTool) {
493493
s.AddTools(tools...)
494494
}
495495

496+
// GetTool retrieves the specified tool
497+
func (s *MCPServer) GetTool(toolName string) *ServerTool {
498+
s.toolsMu.RLock()
499+
defer s.toolsMu.RUnlock()
500+
if tool, ok := s.tools[toolName]; ok {
501+
return &tool
502+
}
503+
return nil
504+
}
505+
506+
func (s *MCPServer) ListTools() map[string]*ServerTool {
507+
s.toolsMu.RLock()
508+
defer s.toolsMu.RUnlock()
509+
if len(s.tools) == 0 {
510+
return nil
511+
}
512+
// Create a copy to prevent external modification
513+
toolsCopy := make(map[string]*ServerTool, len(s.tools))
514+
for name, tool := range s.tools {
515+
toolsCopy[name] = &tool
516+
}
517+
return toolsCopy
518+
}
519+
496520
// DeleteTools removes tools from the server
497521
func (s *MCPServer) DeleteTools(names ...string) {
498522
s.toolsMu.Lock()

0 commit comments

Comments
 (0)