Skip to content

Agent Mesh

address reviews

Antonio Ojea8b6cc847a4e8
diff --git a/cmd/sam-node/mcp_handlers.go b/cmd/sam-node/mcp_handlers.go
index 1d6ccd30..fa57b796 100644
--- a/cmd/sam-node/mcp_handlers.go
+++ b/cmd/sam-node/mcp_handlers.go
@@ -332,7 +332,7 @@ func (n *SamNode) fetchRemoteToolCatalogue(ctx context.Context, targetPeer peer.
var rows []remoteToolRow
for _, svc := range services {
- if svc.Type != api.ServiceType_SERVICE_TYPE_MCP {
+ if svc == nil || svc.Type != api.ServiceType_SERVICE_TYPE_MCP {
continue
}
@@ -353,6 +353,9 @@ func (n *SamNode) fetchRemoteToolCatalogue(ctx context.Context, targetPeer peer.
listRes, err := session.ListTools(ctx, nil)
if err == nil && listRes != nil {
for _, t := range listRes.Tools {
+ if t == nil {
+ continue
+ }
t.Name = svc.Name + "." + t.Name
if !strings.Contains(t.Name, ".") {
continue
diff --git a/cmd/sam-node/mcp_handlers_test.go b/cmd/sam-node/mcp_handlers_test.go
index 6299522e..f1d1e56a 100644
--- a/cmd/sam-node/mcp_handlers_test.go
+++ b/cmd/sam-node/mcp_handlers_test.go
@@ -431,7 +431,7 @@ func TestFetchRemoteToolCatalogue_AuthRejected(t *testing.T) {
if err != nil {
t.Fatal(err)
}
-
+
// Create a biscuit that DOES NOT allow "summarizer", only "some_other_service".
// By baseline rules, it will STILL allow the catalog fetch.
if err := buildAndSaveCustomBiscuit(nodeA, rootPrivEd, []string{"some_other_service"}); err != nil {
diff --git a/cmd/sam-node/stdio_bridge.go b/cmd/sam-node/stdio_bridge.go
index 1a7a6837..14c892d4 100644
--- a/cmd/sam-node/stdio_bridge.go
+++ b/cmd/sam-node/stdio_bridge.go
@@ -148,13 +148,15 @@ func (b *StdioBridge) ServeHTTP(w http.ResponseWriter, r *http.Request) {
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) {
- w.Header().Set("Content-Type", "application/json")
- w.WriteHeader(http.StatusOK)
- _, _ = w.Write([]byte(line))
- return
+ if len(line) > 0 && line[0] == '{' {
+ 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) {
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+ _, _ = w.Write([]byte(line))
+ return
+ }
}
}
}
diff --git a/tests/integration/datapath_test.go b/tests/integration/datapath_test.go
index 9b8907b0..26b22e44 100644
--- a/tests/integration/datapath_test.go
+++ b/tests/integration/datapath_test.go
@@ -116,16 +116,20 @@ func TestIntegrationStdioDatapath(t *testing.T) {
// Test Streamable HTTP (http-first mode)
// Send message via POST and expect the response in the HTTP response body
testMessage := `{"jsonrpc":"2.0","method":"ping","id":1}`
- postReq, _ := http.NewRequest("POST", postURL, bytes.NewBufferString(testMessage))
- postReq.Header.Set("Authorization", "Bearer "+apiToken)
- postReq.Header.Set("Content-Type", "application/json")
- postReq.Header.Set("Accept", "application/json")
var postResp *http.Response
for i := 0; i < 3; i++ {
+ postReq, _ := http.NewRequest("POST", postURL, bytes.NewBufferString(testMessage))
+ postReq.Header.Set("Authorization", "Bearer "+apiToken)
+ postReq.Header.Set("Content-Type", "application/json")
+ postReq.Header.Set("Accept", "application/json")
+
postResp, err = client.Do(postReq)
- if err == nil && postResp.StatusCode == http.StatusOK {
- break
+ if err == nil {
+ if postResp.StatusCode == http.StatusOK {
+ break
+ }
+ _ = postResp.Body.Close()
}
t.Logf("POST Attempt %d failed: %v, status: %v", i+1, err, postResp)
time.Sleep(1 * time.Second)