Add IsSelf flag to identify tendrils server node
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
22
mcp.go
22
mcp.go
@@ -76,7 +76,11 @@ func (t *Tendrils) mcpListNodes(ctx context.Context, req mcp.CallToolRequest) (*
|
|||||||
nodeType = "unknown"
|
nodeType = "unknown"
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.WriteString(fmt.Sprintf("• %s [%s]\n", name, nodeType))
|
if node.IsSelf {
|
||||||
|
sb.WriteString(fmt.Sprintf("• %s [%s] ← THIS SERVER\n", name, nodeType))
|
||||||
|
} else {
|
||||||
|
sb.WriteString(fmt.Sprintf("• %s [%s]\n", name, nodeType))
|
||||||
|
}
|
||||||
|
|
||||||
for _, iface := range node.Interfaces {
|
for _, iface := range node.Interfaces {
|
||||||
sb.WriteString(fmt.Sprintf(" - %s", iface.MAC))
|
sb.WriteString(fmt.Sprintf(" - %s", iface.MAC))
|
||||||
@@ -150,6 +154,9 @@ func formatNodeDetails(node *Node, links []*Link) string {
|
|||||||
if node.Type != "" {
|
if node.Type != "" {
|
||||||
sb.WriteString(fmt.Sprintf("Type: %s\n", node.Type))
|
sb.WriteString(fmt.Sprintf("Type: %s\n", node.Type))
|
||||||
}
|
}
|
||||||
|
if node.IsSelf {
|
||||||
|
sb.WriteString("This Server: YES (tendrils is running here)\n")
|
||||||
|
}
|
||||||
if node.Unreachable {
|
if node.Unreachable {
|
||||||
sb.WriteString("Status: UNREACHABLE\n")
|
sb.WriteString("Status: UNREACHABLE\n")
|
||||||
}
|
}
|
||||||
@@ -297,7 +304,11 @@ func (t *Tendrils) mcpSearchNodes(ctx context.Context, req mcp.CallToolRequest)
|
|||||||
nodeType = "unknown"
|
nodeType = "unknown"
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.WriteString(fmt.Sprintf("• %s [%s]\n", name, nodeType))
|
if node.IsSelf {
|
||||||
|
sb.WriteString(fmt.Sprintf("• %s [%s] ← THIS SERVER\n", name, nodeType))
|
||||||
|
} else {
|
||||||
|
sb.WriteString(fmt.Sprintf("• %s [%s]\n", name, nodeType))
|
||||||
|
}
|
||||||
for _, iface := range node.Interfaces {
|
for _, iface := range node.Interfaces {
|
||||||
sb.WriteString(fmt.Sprintf(" - %s", iface.MAC))
|
sb.WriteString(fmt.Sprintf(" - %s", iface.MAC))
|
||||||
if len(iface.IPs) > 0 {
|
if len(iface.IPs) > 0 {
|
||||||
@@ -339,6 +350,7 @@ func (t *Tendrils) mcpGetTopology(ctx context.Context, req mcp.CallToolRequest)
|
|||||||
|
|
||||||
typeCounts := map[string]int{}
|
typeCounts := map[string]int{}
|
||||||
var unreachable int
|
var unreachable int
|
||||||
|
var selfNode *Node
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
nodeType := string(node.Type)
|
nodeType := string(node.Type)
|
||||||
if nodeType == "" {
|
if nodeType == "" {
|
||||||
@@ -348,11 +360,17 @@ func (t *Tendrils) mcpGetTopology(ctx context.Context, req mcp.CallToolRequest)
|
|||||||
if node.Unreachable {
|
if node.Unreachable {
|
||||||
unreachable++
|
unreachable++
|
||||||
}
|
}
|
||||||
|
if node.IsSelf {
|
||||||
|
selfNode = node
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var sb strings.Builder
|
var sb strings.Builder
|
||||||
sb.WriteString("Network Topology Summary\n")
|
sb.WriteString("Network Topology Summary\n")
|
||||||
sb.WriteString("========================\n\n")
|
sb.WriteString("========================\n\n")
|
||||||
|
if selfNode != nil {
|
||||||
|
sb.WriteString(fmt.Sprintf("This server: %s\n", selfNode.DisplayName()))
|
||||||
|
}
|
||||||
sb.WriteString(fmt.Sprintf("Total nodes: %d\n", len(nodes)))
|
sb.WriteString(fmt.Sprintf("Total nodes: %d\n", len(nodes)))
|
||||||
sb.WriteString(fmt.Sprintf("Total links: %d\n", len(links)))
|
sb.WriteString(fmt.Sprintf("Total links: %d\n", len(links)))
|
||||||
sb.WriteString(fmt.Sprintf("Active errors: %d\n", len(errors)))
|
sb.WriteString(fmt.Sprintf("Active errors: %d\n", len(errors)))
|
||||||
|
|||||||
@@ -200,6 +200,9 @@ func (t *Tendrils) populateLocalAddresses() {
|
|||||||
t.nodes.Update(target, netIface.HardwareAddr, ips, netIface.Name, hostname, "local")
|
t.nodes.Update(target, netIface.HardwareAddr, ips, netIface.Name, hostname, "local")
|
||||||
if target == nil {
|
if target == nil {
|
||||||
target = t.nodes.GetByMAC(netIface.HardwareAddr)
|
target = t.nodes.GetByMAC(netIface.HardwareAddr)
|
||||||
|
if target != nil {
|
||||||
|
target.IsSelf = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
types.go
1
types.go
@@ -494,6 +494,7 @@ type Node struct {
|
|||||||
Unreachable bool `json:"unreachable,omitempty"`
|
Unreachable bool `json:"unreachable,omitempty"`
|
||||||
Avoid bool `json:"avoid,omitempty"`
|
Avoid bool `json:"avoid,omitempty"`
|
||||||
InConfig bool `json:"in_config,omitempty"`
|
InConfig bool `json:"in_config,omitempty"`
|
||||||
|
IsSelf bool `json:"is_self,omitempty"`
|
||||||
errors *ErrorTracker
|
errors *ErrorTracker
|
||||||
pollTrigger chan struct{}
|
pollTrigger chan struct{}
|
||||||
cancelFunc context.CancelFunc
|
cancelFunc context.CancelFunc
|
||||||
|
|||||||
Reference in New Issue
Block a user