RegisterToolDeferred 延迟注册单个工具(按需激活时调用)
(toolName string)
| 155 | |
| 156 | // RegisterToolDeferred 延迟注册单个工具(按需激活时调用) |
| 157 | func (s *MCPServer) RegisterToolDeferred(toolName string) error { |
| 158 | s.mu.RLock() |
| 159 | defer s.mu.RUnlock() |
| 160 | |
| 161 | // 查找对应的 MCP 工具 |
| 162 | for _, mcpTool := range s.tools { |
| 163 | fullName := fmt.Sprintf("%s:%s", s.serverID, mcpTool.Name) |
| 164 | if fullName == toolName { |
| 165 | // 创建工具工厂并注册 |
| 166 | factory := ToolFactory(s.client, mcpTool) |
| 167 | s.registry.Register(toolName, factory) |
| 168 | return nil |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | return fmt.Errorf("tool not found: %s", toolName) |
| 173 | } |
| 174 | |
| 175 | // IndexToolsToIndex 将工具添加到工具索引(延迟加载模式) |
| 176 | func (s *MCPServer) IndexToolsToIndex(index *search.ToolIndex) error { |
no test coverage detected