Agent Mesh
Go a2aa2a-protocolagent-meshagentic-aiinferencemcpmeshmesh-networknetwork-securitynetworking-aip2p-network
fix: mcp_service - reject a command backend with no command
Fernando Marinoac74055a3f4a
diff --git a/internal/node/mcp_service.go b/internal/node/mcp_service.goindex 0b71bc2c..3d0e5f10 100644--- a/internal/node/mcp_service.go+++ b/internal/node/mcp_service.go@@ -89,6 +89,9 @@ func (m *MCPService) backendTransport() (mcp.Transport, error) {case *api.RegisterServiceRequest_TargetUrl:return &mcp.StreamableClientTransport{Endpoint: x.TargetUrl}, nilcase *api.RegisterServiceRequest_Command:+ if x.Command == nil || len(x.Command.Command) == 0 {+ return nil, fmt.Errorf("missing command for command-backed MCP service %q", m.info.GetName())+ }cmd := exec.Command(x.Command.Command[0], x.Command.Command[1:]...)cmd.Env = os.Environ()for k, v := range x.Command.Env {diff --git a/internal/node/mcp_service_command_test.go b/internal/node/mcp_service_command_test.goindex a5858c4c..d54ab21c 100644--- a/internal/node/mcp_service_command_test.go+++ b/internal/node/mcp_service_command_test.go@@ -202,3 +202,30 @@ func TestMCPService_BackendTransport_ConcurrentCallsDoNotCrossTalk(t *testing.T)t.Error(err)}}++// A RegisterServiceRequest_Command with no command (nil CommandBackend, or+// an empty Command slice) must be rejected with an error, not reach+// x.Command.Command[0] and panic - both are reachable from an external+// RegisterService call, not just a local misconfiguration.+func TestMCPService_BackendTransport_CommandBackendRejectsMissingCommand(t *testing.T) {+ cases := []struct {+ name string+ backend *api.RegisterServiceRequest_Command+ }{+ {"nil CommandBackend", &api.RegisterServiceRequest_Command{Command: nil}},+ {"empty command slice", &api.RegisterServiceRequest_Command{Command: &api.CommandBackend{Command: []string{}}}},+ }+ for _, tc := range cases {+ t.Run(tc.name, func(t *testing.T) {+ m := &MCPService{+ baseService: baseService{+ info: &api.ServiceInfo{Type: api.ServiceType_SERVICE_TYPE_MCP, Name: "broken"},+ backend: tc.backend,+ },+ }+ if _, err := m.backendTransport(); err == nil {+ t.Fatal("backendTransport: got nil error, want an error for a missing command")+ }+ })+ }+}