| 1 | package agent |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | |
| 6 | "reasonix/internal/plugin" |
| 7 | ) |
| 8 | |
| 9 | // The live-connection view every frontend on one session observes. It is |
| 10 | // deliberately shared: the Host and its processes are shared at the same scope. |
| 11 | |
| 12 | func (s *mcpProxySharedState) markConnected(server string) { |
| 13 | if s == nil { |
| 14 | return |
| 15 | } |
| 16 | s.mu.Lock() |
| 17 | defer s.mu.Unlock() |
| 18 | if s.connected == nil { |
| 19 | s.connected = map[string]bool{} |
| 20 | } |
| 21 | s.connected[server] = true |
| 22 | } |
| 23 | |
| 24 | func (s *mcpProxySharedState) setLiveTools(server string, snap []plugin.CachedTool) { |
| 25 | if s == nil { |
| 26 | return |
| 27 | } |
| 28 | s.mu.Lock() |
| 29 | defer s.mu.Unlock() |
| 30 | if s.liveTools == nil { |
| 31 | s.liveTools = map[string][]plugin.CachedTool{} |
| 32 | } |
| 33 | s.liveTools[server] = snap |
| 34 | if s.connected == nil { |
| 35 | s.connected = map[string]bool{} |
| 36 | } |
| 37 | s.connected[server] = true |
| 38 | } |
| 39 | |
| 40 | func (s *mcpProxySharedState) snapshotLiveTools() map[string][]plugin.CachedTool { |
| 41 | if s == nil { |
| 42 | return nil |
| 43 | } |
| 44 | s.mu.Lock() |
| 45 | defer s.mu.Unlock() |
| 46 | if len(s.liveTools) == 0 { |
| 47 | return nil |
| 48 | } |
| 49 | out := make(map[string][]plugin.CachedTool, len(s.liveTools)) |
| 50 | for k, v := range s.liveTools { |
| 51 | out[k] = append([]plugin.CachedTool(nil), v...) |
| 52 | } |
| 53 | return out |
| 54 | } |
| 55 | |
| 56 | func (s *mcpProxySharedState) clearServer(server string) { |
| 57 | if s == nil { |
| 58 | return |
| 59 | } |
| 60 | s.mu.Lock() |
| 61 | delete(s.connected, strings.TrimSpace(server)) |
| 62 | delete(s.liveTools, strings.TrimSpace(server)) |
| 63 | s.mu.Unlock() |
| 64 | } |
| 65 |