Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
start:
CYCLOPS_MCP_TRANSPORT=sse go run -tags musl ./cmd/mcp-cyclops

build:
go build -o bin ./...

group-imports:
goimports -w .

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ require (
github.com/cyclops-ui/cyclops/cyclops-ctrl v0.0.0-20250428101219-ce60d9962a4a
github.com/joho/godotenv v1.5.1
github.com/mark3labs/mcp-go v0.22.0
github.com/pkg/errors v0.9.1
github.com/xeipuuv/gojsonschema v1.2.0
k8s.io/apiextensions-apiserver v0.32.3
k8s.io/apimachinery v0.32.3
sigs.k8s.io/controller-runtime v0.20.4
Expand Down Expand Up @@ -77,7 +79,6 @@ require (
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc6 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
Expand All @@ -91,7 +92,6 @@ require (
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect
go.opentelemetry.io/otel v1.28.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ github.com/containerd/continuity v0.4.2/go.mod h1:F6PTNCKepoxEaXLQp3wDAjygEnImnZ
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cyclops-ui/cyclops/cyclops-ctrl v0.0.0-20250425140426-3fe1a1ecab1e h1:H2I/WXA7FBfz6VNFdMt3IB2YZtzPbwzmMELdkRuDuRc=
github.com/cyclops-ui/cyclops/cyclops-ctrl v0.0.0-20250425140426-3fe1a1ecab1e/go.mod h1:X9riUJ/32Bs2c3ZK2w1WXxHmZbpn/kh4YaLFICzbPuo=
github.com/cyclops-ui/cyclops/cyclops-ctrl v0.0.0-20250428101219-ce60d9962a4a h1:X0tsu1VGVQzCbfWgIRX6iwBt6uBbvfKu0tWkaJKNJxY=
github.com/cyclops-ui/cyclops/cyclops-ctrl v0.0.0-20250428101219-ce60d9962a4a/go.mod h1:X9riUJ/32Bs2c3ZK2w1WXxHmZbpn/kh4YaLFICzbPuo=
github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg=
Expand Down
28 changes: 27 additions & 1 deletion internal/modules/controller.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package modules

import (
"github.com/pkg/errors"

"github.com/mark3labs/mcp-go/server"
"github.com/xeipuuv/gojsonschema"

"github.com/cyclops-ui/cyclops/cyclops-ctrl/pkg/cluster/k8sclient"
"github.com/cyclops-ui/cyclops/cyclops-ctrl/pkg/template"
"github.com/mark3labs/mcp-go/server"
)

type ModuleController struct {
Expand All @@ -24,3 +28,25 @@ func (m *ModuleController) RegisterModuleTools(mcp *server.MCPServer) {
mcp.AddTool(m.createModuleTool(), m.createModule)
mcp.AddTool(m.updateModuleTool(), m.updateModule)
}

func (m *ModuleController) validateModuleValues(schema []byte, values map[string]interface{}) (bool, error, error) {
schemaLoader := gojsonschema.NewBytesLoader(schema)
valuesLoader := gojsonschema.NewGoLoader(values)

res, err := gojsonschema.Validate(schemaLoader, valuesLoader)
if err != nil {
return false, nil, err
}

if !res.Valid() {
validationErr := errors.New("invalid values for schema")

for _, resultError := range res.Errors() {
validationErr = errors.Wrap(validationErr, resultError.String())
}

return false, validationErr, nil
}

return true, nil, nil
}
14 changes: 14 additions & 0 deletions internal/modules/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ func (m *ModuleController) createModule(_ context.Context, request mcp.CallToolR

values = mapper.DeepMerge(initialValues, values)

template, err := m.templateRepo.GetTemplate(repo, path, version, "", v1alpha1.TemplateSourceType(templateType))
if err != nil {
return nil, err
}

valid, validationError, err := m.validateModuleValues(template.RawSchema, values)
if err != nil {
return nil, err
}

if !valid {
return mcp.NewToolResultError(validationError.Error()), nil
}

valuesBytes, err := json.Marshal(values)
if err != nil {
return nil, err
Expand Down
25 changes: 25 additions & 0 deletions internal/modules/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,31 @@ func (m *ModuleController) updateModule(_ context.Context, request mcp.CallToolR
}

module, err := mapper.UpdateModuleValues(curr, updateValues)

template, err := m.templateRepo.GetTemplate(
module.Spec.TemplateRef.URL,
module.Spec.TemplateRef.Path,
module.Spec.TemplateRef.Version,
module.Status.TemplateResolvedVersion,
module.Spec.TemplateRef.SourceType)
if err != nil {
return nil, err
}

var values map[string]interface{}
if err := json.Unmarshal(module.Spec.Values.Raw, &values); err != nil {
return nil, err
}

valid, validationError, err := m.validateModuleValues(template.RawSchema, values)
if err != nil {
return nil, err
}

if !valid {
return mcp.NewToolResultError(validationError.Error()), nil
}

if err := m.k8sClient.UpdateModule(module); err != nil {
return nil, fmt.Errorf("failed to update module: %w", err)
}
Expand Down