Agent Mesh
Go a2aa2a-protocolagent-meshagentic-aiinferencemcpmeshmesh-networknetwork-securitynetworking-aip2p-network
refactor(mcp): generalize find_remote_tools' region hint to labels
Antonio Ojea00ee97ef1a18
diff --git a/internal/node/mcp.go b/internal/node/mcp.goindex 8714bfdb..80720b88 100644--- a/internal/node/mcp.go+++ b/internal/node/mcp.go@@ -113,7 +113,7 @@ func NewMCPServer(node *SamNode) *mcp.Server {// Add the find_remote_tools tool.mcp.AddTool(mcpServer, &mcp.Tool{Name: "find_remote_tools",- Description: "Discover MCP tools available on hosted services across the mesh. Returns name + description per tool, plus the provider's region label when known. Optionally narrow by peer_id, service_name, or tool_name (exact tool name; fastest — served from mesh announcements when available). intent is reserved for future ranking and is accepted-but-ignored.",+ Description: "Discover MCP tools available on hosted services across the mesh. Returns name + description per tool, plus the provider's declared labels (e.g. region) when known. Optionally narrow by peer_id, service_name, or tool_name (exact tool name; fastest — served from mesh announcements when available). intent is reserved for future ranking and is accepted-but-ignored.",}, node.handleFindRemoteTools)// Add the describe_remote_tool tool.diff --git a/internal/node/mcp_discovery_test.go b/internal/node/mcp_discovery_test.goindex 76320c5a..85bf2dd5 100644--- a/internal/node/mcp_discovery_test.go+++ b/internal/node/mcp_discovery_test.go@@ -135,11 +135,11 @@ func TestGossipToolRows(t *testing.T) {if len(rows) != 2 {t.Fatalf("rows: got %+v, want 2", rows)}- if rows[0].ToolName != "mcp://reviewer/review_pr" || rows[0].Region != "eu" {+ if rows[0].ToolName != "mcp://reviewer/review_pr" || rows[0].Labels[api.LabelRegion] != "eu" {t.Errorf("row 0: %+v", rows[0])}- if rows[1].Region != "" {- t.Errorf("row 1 should have no region claim: %+v", rows[1])+ if len(rows[1].Labels) != 0 {+ t.Errorf("row 1 should have no labels: %+v", rows[1])}filtered := gossipToolRows(provs, "review_pr", "reviewer")diff --git a/internal/node/mcp_handlers.go b/internal/node/mcp_handlers.goindex 335ce390..a4de03f3 100644--- a/internal/node/mcp_handlers.go+++ b/internal/node/mcp_handlers.go@@ -300,10 +300,10 @@ type remoteToolRow struct {PeerID string `json:"peer_id"`ToolName string `json:"tool_name,omitempty"`Description string `json:"description,omitempty"`- // Region is the provider's operator-declared region claim, when known- // from gossip. A routing hint, not an enforced attribute.- Region string `json:"region,omitempty"`- Error string `json:"error,omitempty"`+ // Labels are the provider's operator-declared labels, when known from+ // gossip (e.g. "region"). A routing hint, not an enforced attribute.+ Labels map[string]string `json:"labels,omitempty"`+ Error string `json:"error,omitempty"`}// handleFindRemoteTools implements the find_remote_tools tool.@@ -378,7 +378,7 @@ func (n *SamNode) handleFindRemoteTools(ctx context.Context, req *mcp.CallToolReif params.ToolName != "" {rows = filterRowsByToolName(rows, params.ToolName)}- n.annotateToolRegions(rows)+ n.annotateToolLabels(rows)return marshalToolRows(rows)}@@ -410,7 +410,7 @@ func gossipToolRows(provs []samdiscovery.Provider, toolName, serviceNameFilter srows = append(rows, remoteToolRow{PeerID: p.PeerID,ToolName: name + "/" + toolName,- Region: p.Labels[api.LabelRegion],+ Labels: p.Labels,})}return rows@@ -432,17 +432,18 @@ func filterRowsByToolName(rows []remoteToolRow, toolName string) []remoteToolRowreturn out}-// annotateToolRegions fills the region hint for peers the gossip view knows.-func (n *SamNode) annotateToolRegions(rows []remoteToolRow) {+// annotateToolLabels fills in the operator-declared labels for peers the+// gossip view knows, when not already known from a fresher source.+func (n *SamNode) annotateToolLabels(rows []remoteToolRow) {if n.Discovery == nil {return}for i := range rows {- if rows[i].Region != "" {+ if len(rows[i].Labels) != 0 {continue}if labels := n.Discovery.PeerLabels(rows[i].PeerID); labels != nil {- rows[i].Region = labels[api.LabelRegion]+ rows[i].Labels = labels}}}