返回 DeepSeek-Reasonix
host_queries.go
根目录 / internal / plugin / host_queries.go
1 package plugin
2
3 import (
4 "sort"
5 "strings"
6
7 "reasonix/internal/tool"
8 )
9
10 // Prompts returns every MCP prompt discovered across connected servers.
11 func (h *Host) Prompts() []Prompt {
12 h.mu.RLock()
13 defer h.mu.RUnlock()
14 return append([]Prompt(nil), h.prompts...)
15 }
16
17 // Resources returns every MCP resource discovered across connected servers.
18 func (h *Host) Resources() []Resource {
19 h.mu.RLock()
20 defer h.mu.RUnlock()
21 return append([]Resource(nil), h.resources...)
22 }
23
24 // ServerNames returns the connected servers' names, in connection order.
25 // CachedTools returns the already-listed live adapters for a connected server
26 // without issuing tools/list.
27 func (h *Host) CachedTools(name string) ([]tool.Tool, bool) {
28 if h == nil {
29 return nil, false
30 }
31 c := h.lookupClient(name)
32 if c == nil {
33 return nil, false
34 }
35 return c.cachedTools()
36 }
37
38 func (h *Host) ServerNames() []string {
39 h.mu.RLock()
40 defer h.mu.RUnlock()
41 names := make([]string, len(h.clients))
42 for i, c := range h.clients {
43 names[i] = c.name
44 }
45 return names
46 }
47
48 // Failures returns configured MCP servers that failed to connect.
49 func (h *Host) Failures() []Failure {
50 h.mu.RLock()
51 defer h.mu.RUnlock()
52 out := make([]Failure, len(h.failures))
53 copy(out, h.failures)
54 return out
55 }
56
57 // ConnectingServers returns server names whose startup handshake is currently in
58 // flight. It is intentionally status-only: connected clients and failures remain
59 // the source of truth for ready/issue states.
60 func (h *Host) ConnectingServers() []string {
61 h.spawningMu.Lock()
62 defer h.spawningMu.Unlock()
63 names := make(map[string]struct{}, len(h.spawning))
64 for key, attempt := range h.spawning {
65 name := key
66 if attempt != nil && strings.TrimSpace(attempt.server) != "" {
67 name = attempt.server
68 }
69 names[name] = struct{}{}
70 }
71 out := make([]string, 0, len(names))
72 for name := range names {
73 out = append(out, name)
74 }
75 sort.Strings(out)
76 return out
77 }
78
78 lines GO