ConnectServerDeferred 连接 MCP Server 但使用延迟加载模式 只发现工具并添加到索引,不立即注册到 Registry
(ctx context.Context, serverID string, index *search.ToolIndex)
| 142 | // ConnectServerDeferred 连接 MCP Server 但使用延迟加载模式 |
| 143 | // 只发现工具并添加到索引,不立即注册到 Registry |
| 144 | func (m *MCPManager) ConnectServerDeferred(ctx context.Context, serverID string, index *search.ToolIndex) error { |
| 145 | m.mu.RLock() |
| 146 | server, exists := m.servers[serverID] |
| 147 | m.mu.RUnlock() |
| 148 | |
| 149 | if !exists { |
| 150 | return fmt.Errorf("server not found: %s", serverID) |
| 151 | } |
| 152 | |
| 153 | // 连接并发现工具 |
| 154 | if err := server.Connect(ctx); err != nil { |
| 155 | return fmt.Errorf("connect to server: %w", err) |
| 156 | } |
| 157 | |
| 158 | // 将工具添加到索引(延迟加载模式) |
| 159 | if err := server.IndexToolsToIndex(index); err != nil { |
| 160 | return fmt.Errorf("index tools: %w", err) |
| 161 | } |
| 162 | |
| 163 | return nil |
| 164 | } |
| 165 | |
| 166 | // ConnectAllDeferred 连接所有 MCP Server 使用延迟加载模式 |
| 167 | func (m *MCPManager) ConnectAllDeferred(ctx context.Context, index *search.ToolIndex) error { |
no test coverage detected