Skip to content

Agent Mesh

address review comments

Antonio Ojeadaf2bf70372c
diff --git a/cmd/sam-node/mcp_handlers.go b/cmd/sam-node/mcp_handlers.go
index a5e5c0f1..1d6ccd30 100644
--- a/cmd/sam-node/mcp_handlers.go
+++ b/cmd/sam-node/mcp_handlers.go
@@ -351,7 +351,7 @@ func (n *SamNode) fetchRemoteToolCatalogue(ctx context.Context, targetPeer peer.
}
listRes, err := session.ListTools(ctx, nil)
- if err == nil {
+ if err == nil && listRes != nil {
for _, t := range listRes.Tools {
t.Name = svc.Name + "." + t.Name
if !strings.Contains(t.Name, ".") {
@@ -482,6 +482,9 @@ func (n *SamNode) handleDescribeRemoteTool(ctx context.Context, req *mcp.CallToo
if err != nil {
return nil, nil, err
}
+ if listRes == nil {
+ return nil, nil, fmt.Errorf("list tools response was nil")
+ }
for _, t := range listRes.Tools {
if t.Name == actualToolName {
diff --git a/cmd/sam-node/stdio_bridge.go b/cmd/sam-node/stdio_bridge.go
index bee2a464..1a7a6837 100644
--- a/cmd/sam-node/stdio_bridge.go
+++ b/cmd/sam-node/stdio_bridge.go
@@ -87,7 +87,10 @@ func (b *StdioBridge) ServeHTTP(w http.ResponseWriter, r *http.Request) {
select {
case <-ctx.Done():
return
- case line := <-ch:
+ case line, ok := <-ch:
+ if !ok {
+ return
+ }
if _, err := fmt.Fprintf(w, "data: %s\n\n", line); err != nil {
logger.Errorf("Failed to write to SSE client: %v", err)
return
@@ -141,7 +144,10 @@ func (b *StdioBridge) ServeHTTP(w http.ResponseWriter, r *http.Request) {
select {
case <-ctx.Done():
return
- case line := <-ch:
+ case line, ok := <-ch:
+ if !ok {
+ return
+ }
var respMsg map[string]any
if err := json.Unmarshal([]byte(line), &respMsg); err == nil {
if respID, ok := respMsg["id"]; ok && fmt.Sprintf("%v", respID) == fmt.Sprintf("%v", reqID) {