Skip to content

Commit e32acd2

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

File tree

2 files changed

+445
-0
lines changed

2 files changed

+445
-0
lines changed

server/server.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,28 @@ func (s *MCPServer) SetTools(tools ...ServerTool) {
493493
s.AddTools(tools...)
494494
}
495495

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

0 commit comments

Comments
 (0)