From 48e1e69fde3342da5306af47c69efe76cae55765 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Wed, 4 Feb 2026 11:42:07 -0800 Subject: [PATCH] Add IsSelf flag to identify tendrils server node Co-Authored-By: Claude Opus 4.5 --- mcp.go | 22 ++++++++++++++++++++-- tendrils.go | 3 +++ types.go | 1 + 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/mcp.go b/mcp.go index 7d13f7e..7351538 100644 --- a/mcp.go +++ b/mcp.go @@ -76,7 +76,11 @@ func (t *Tendrils) mcpListNodes(ctx context.Context, req mcp.CallToolRequest) (* 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 { sb.WriteString(fmt.Sprintf(" - %s", iface.MAC)) @@ -150,6 +154,9 @@ func formatNodeDetails(node *Node, links []*Link) string { if 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 { sb.WriteString("Status: UNREACHABLE\n") } @@ -297,7 +304,11 @@ func (t *Tendrils) mcpSearchNodes(ctx context.Context, req mcp.CallToolRequest) 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 { sb.WriteString(fmt.Sprintf(" - %s", iface.MAC)) if len(iface.IPs) > 0 { @@ -339,6 +350,7 @@ func (t *Tendrils) mcpGetTopology(ctx context.Context, req mcp.CallToolRequest) typeCounts := map[string]int{} var unreachable int + var selfNode *Node for _, node := range nodes { nodeType := string(node.Type) if nodeType == "" { @@ -348,11 +360,17 @@ func (t *Tendrils) mcpGetTopology(ctx context.Context, req mcp.CallToolRequest) if node.Unreachable { unreachable++ } + if node.IsSelf { + selfNode = node + } } var sb strings.Builder sb.WriteString("Network Topology Summary\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 links: %d\n", len(links))) sb.WriteString(fmt.Sprintf("Active errors: %d\n", len(errors))) diff --git a/tendrils.go b/tendrils.go index c396cb2..d30bef6 100644 --- a/tendrils.go +++ b/tendrils.go @@ -200,6 +200,9 @@ func (t *Tendrils) populateLocalAddresses() { t.nodes.Update(target, netIface.HardwareAddr, ips, netIface.Name, hostname, "local") if target == nil { target = t.nodes.GetByMAC(netIface.HardwareAddr) + if target != nil { + target.IsSelf = true + } } } } diff --git a/types.go b/types.go index ab9e48a..6a81c55 100644 --- a/types.go +++ b/types.go @@ -494,6 +494,7 @@ type Node struct { Unreachable bool `json:"unreachable,omitempty"` Avoid bool `json:"avoid,omitempty"` InConfig bool `json:"in_config,omitempty"` + IsSelf bool `json:"is_self,omitempty"` errors *ErrorTracker pollTrigger chan struct{} cancelFunc context.CancelFunc