@@ -9,6 +9,10 @@ import (
99 "strings"
1010 "time"
1111
12+ json "github.com/json-iterator/go"
13+ apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
14+ "k8s.io/apimachinery/pkg/api/errors"
15+
1216 "github.com/cyclops-ui/cyclops/cyclops-ctrl/pkg/template"
1317 "github.com/cyclops-ui/cyclops/cyclops-ctrl/pkg/template/render"
1418
@@ -1011,6 +1015,92 @@ func (m *Modules) GetResource(ctx *gin.Context) {
10111015 ctx .JSON (http .StatusOK , resource )
10121016}
10131017
1018+ func (m * Modules ) InstallMCPServer (ctx * gin.Context ) {
1019+ ctx .Header ("Access-Control-Allow-Origin" , "*" )
1020+
1021+ mcpModuleValues := map [string ]interface {}{
1022+ "replicas" : 1 ,
1023+ "version" : "latest" ,
1024+ }
1025+
1026+ m .telemetryClient .AddonInstall ("mcp-server" )
1027+
1028+ valBytes , err := json .Marshal (mcpModuleValues )
1029+ if err != nil {
1030+ ctx .JSON (http .StatusInternalServerError , gin.H {
1031+ "error" : "Failed to create MCP server module values" ,
1032+ "reason" : err .Error (),
1033+ })
1034+ }
1035+
1036+ mcpServerModule := v1alpha1.Module {
1037+ TypeMeta : metav1.TypeMeta {
1038+ Kind : "Module" ,
1039+ APIVersion : "cyclops-ui.com/v1alpha1" ,
1040+ },
1041+ ObjectMeta : metav1.ObjectMeta {
1042+ Name : "mcp-cyclops" ,
1043+ Labels : map [string ]string {
1044+ v1alpha1 .MCPServerModuleLabel : "true" ,
1045+ v1alpha1 .AddonModuleLabel : "true" ,
1046+ },
1047+ },
1048+ Spec : v1alpha1.ModuleSpec {
1049+ TargetNamespace : "cyclops" ,
1050+ TemplateRef : v1alpha1.TemplateRef {
1051+ URL : "https://github.com/cyclops-ui/templates" ,
1052+ Path : "cyclops-mcp" ,
1053+ Version : "main" ,
1054+ SourceType : "git" ,
1055+ },
1056+ Values : apiextensionsv1.JSON {
1057+ Raw : valBytes ,
1058+ },
1059+ },
1060+ History : make ([]v1alpha1.HistoryEntry , 0 ),
1061+ }
1062+
1063+ if err := m .kubernetesClient .CreateModule (mcpServerModule ); err != nil {
1064+ ctx .JSON (http .StatusInternalServerError , gin.H {
1065+ "error" : "Failed to create Cyclops MCP server module" ,
1066+ "reason" : err .Error (),
1067+ })
1068+ return
1069+ }
1070+
1071+ ctx .Status (http .StatusCreated )
1072+ }
1073+
1074+ func (m * Modules ) MCPServerStatus (ctx * gin.Context ) {
1075+ ctx .Header ("Access-Control-Allow-Origin" , "*" )
1076+
1077+ type MCPServerStatus struct {
1078+ Installed bool `json:"installed"`
1079+ }
1080+
1081+ module , err := m .kubernetesClient .GetModule ("mcp-cyclops" )
1082+ if err != nil {
1083+ if errors .IsNotFound (err ) {
1084+ ctx .JSON (http .StatusOK , MCPServerStatus {Installed : false })
1085+ return
1086+ }
1087+
1088+ ctx .JSON (http .StatusInternalServerError , gin.H {
1089+ "error" : "Failed to check Cyclops MCP server status" ,
1090+ "reason" : err .Error (),
1091+ })
1092+ return
1093+ }
1094+
1095+ if module .Labels == nil {
1096+ ctx .JSON (http .StatusOK , MCPServerStatus {Installed : false })
1097+ return
1098+ }
1099+
1100+ _ , ok := module .Labels [v1alpha1 .MCPServerModuleLabel ]
1101+ ctx .JSON (http .StatusOK , MCPServerStatus {Installed : ok })
1102+ }
1103+
10141104func getTargetGeneration (generation string , module * v1alpha1.Module ) (* v1alpha1.Module , bool ) {
10151105 // no generation specified means current generation
10161106 if len (generation ) == 0 {
0 commit comments