-
Notifications
You must be signed in to change notification settings - Fork 0
ROX-31475: Add StackRox client #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mtodor
wants to merge
1
commit into
mtodor/ROX-31475-add-mcp-server
Choose a base branch
from
mtodor/ROX-31477-add-stackrox-client
base: mtodor/ROX-31475-add-mcp-server
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,9 @@ | |
| .idea/ | ||
| .DS_Store | ||
|
|
||
| # Claude Code | ||
| .claude/ | ||
|
|
||
| # Test coverage output | ||
| /*.out | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,7 @@ import ( | |||||
| "testing" | ||||||
| "time" | ||||||
|
|
||||||
| "github.com/stackrox/stackrox-mcp/internal/client" | ||||||
| "github.com/stackrox/stackrox-mcp/internal/config" | ||||||
| "github.com/stackrox/stackrox-mcp/internal/server" | ||||||
| "github.com/stackrox/stackrox-mcp/internal/testutil" | ||||||
|
|
@@ -17,51 +18,28 @@ import ( | |||||
| "github.com/stretchr/testify/require" | ||||||
| ) | ||||||
|
|
||||||
| func getDefaultConfig() *config.Config { | ||||||
| return &config.Config{ | ||||||
| Global: config.GlobalConfig{ | ||||||
| ReadOnlyTools: false, | ||||||
| }, | ||||||
| Central: config.CentralConfig{ | ||||||
| URL: "central.example.com:8443", | ||||||
| }, | ||||||
| Server: config.ServerConfig{ | ||||||
| Address: "localhost", | ||||||
| Port: 8080, | ||||||
| }, | ||||||
| Tools: config.ToolsConfig{ | ||||||
| Vulnerability: config.ToolsetVulnerabilityConfig{ | ||||||
| Enabled: true, | ||||||
| }, | ||||||
| ConfigManager: config.ToolConfigManagerConfig{ | ||||||
| Enabled: false, | ||||||
| }, | ||||||
| }, | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| func TestGetToolsets(t *testing.T) { | ||||||
| cfg := getDefaultConfig() | ||||||
| cfg.Tools.ConfigManager.Enabled = true | ||||||
| allToolsets := getToolsets(&config.Config{}, &client.Client{}) | ||||||
|
|
||||||
| allToolsets := getToolsets(cfg) | ||||||
| toolsetNames := make(map[string]bool) | ||||||
| for _, toolset := range allToolsets { | ||||||
| toolsetNames[toolset.GetName()] = true | ||||||
| } | ||||||
|
|
||||||
| require.NotNil(t, allToolsets) | ||||||
| assert.Len(t, allToolsets, 2, "Should have 2 allToolsets") | ||||||
| assert.Equal(t, "config_manager", allToolsets[0].GetName()) | ||||||
| assert.Equal(t, "vulnerability", allToolsets[1].GetName()) | ||||||
| assert.Contains(t, toolsetNames, "config_manager") | ||||||
| assert.Contains(t, toolsetNames, "vulnerability") | ||||||
| } | ||||||
|
|
||||||
| func TestGracefulShutdown(t *testing.T) { | ||||||
| // Set up minimal valid config. | ||||||
| // Set up minimal valid config. config.LoadConfig() validates configuration. | ||||||
| t.Setenv("STACKROX_MCP__TOOLS__VULNERABILITY__ENABLED", "true") | ||||||
|
|
||||||
| cfg, err := config.LoadConfig("") | ||||||
| require.NoError(t, err) | ||||||
| require.NotNil(t, cfg) | ||||||
| cfg.Server.Port = testutil.GetPortForTest(t) | ||||||
|
|
||||||
| registry := toolsets.NewRegistry(cfg, getToolsets(cfg)) | ||||||
| registry := toolsets.NewRegistry(cfg, getToolsets(cfg, &client.Client{})) | ||||||
| srv := server.NewServer(cfg, registry) | ||||||
| ctx, cancel := context.WithCancel(context.Background()) | ||||||
|
|
||||||
|
|
@@ -78,12 +56,10 @@ func TestGracefulShutdown(t *testing.T) { | |||||
| // Establish actual HTTP connection to verify server is responding. | ||||||
| //nolint:gosec,noctx | ||||||
| resp, err := http.Get(serverURL) | ||||||
| if err == nil { | ||||||
| _ = resp.Body.Close() | ||||||
| } | ||||||
|
|
||||||
| require.NoError(t, err, "Should be able to establish HTTP connection to server") | ||||||
|
|
||||||
| _ = resp.Body.Close() | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| // Simulate shutdown signal by canceling context. | ||||||
| cancel() | ||||||
|
|
||||||
|
|
@@ -94,7 +70,7 @@ func TestGracefulShutdown(t *testing.T) { | |||||
| if err != nil && errors.Is(err, context.Canceled) { | ||||||
| t.Errorf("Server returned unexpected error: %v", err) | ||||||
| } | ||||||
| case <-time.After(5 * time.Second): | ||||||
| case <-time.After(server.ShutdownTimeout): | ||||||
| t.Fatal("Server did not shut down within timeout period") | ||||||
| } | ||||||
| } | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,54 @@ | ||
| module github.com/stackrox/stackrox-mcp | ||
|
|
||
| go 1.24 | ||
| go 1.24.0 | ||
|
|
||
| toolchain go1.24.7 | ||
|
|
||
| require ( | ||
| github.com/modelcontextprotocol/go-sdk v1.1.0 | ||
| github.com/pkg/errors v0.9.1 | ||
| github.com/spf13/viper v1.21.0 | ||
| github.com/stackrox/rox v0.0.0-20210914215712-9ac265932e28 | ||
| github.com/stretchr/testify v1.11.1 | ||
| golang.stackrox.io/grpc-http1 v0.5.1 | ||
| google.golang.org/grpc v1.77.0 | ||
| ) | ||
|
|
||
| require ( | ||
| github.com/davecgh/go-spew v1.1.1 // indirect | ||
| github.com/coder/websocket v1.8.14 // indirect | ||
| github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect | ||
| github.com/fsnotify/fsnotify v1.9.0 // indirect | ||
| github.com/go-viper/mapstructure/v2 v2.4.0 // indirect | ||
| github.com/golang/glog v1.2.5 // indirect | ||
| github.com/google/jsonschema-go v0.3.0 // indirect | ||
| github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3 // indirect | ||
| github.com/pelletier/go-toml/v2 v2.2.4 // indirect | ||
| github.com/pmezard/go-difflib v1.0.0 // indirect | ||
| github.com/planetscale/vtprotobuf v0.6.1-0.20240409071808-615f978279ca // indirect | ||
| github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect | ||
| github.com/sagikazarmark/locafero v0.11.0 // indirect | ||
| github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect | ||
| github.com/spf13/afero v1.15.0 // indirect | ||
| github.com/spf13/cast v1.10.0 // indirect | ||
| github.com/spf13/pflag v1.0.10 // indirect | ||
| github.com/stackrox/scanner v0.0.0-20240830165150-d133ba942d59 // indirect | ||
| github.com/subosito/gotenv v1.6.0 // indirect | ||
| github.com/yosida95/uritemplate/v3 v3.0.2 // indirect | ||
| go.yaml.in/yaml/v3 v3.0.4 // indirect | ||
| golang.org/x/oauth2 v0.30.0 // indirect | ||
| golang.org/x/sys v0.29.0 // indirect | ||
| golang.org/x/text v0.28.0 // indirect | ||
| golang.org/x/net v0.46.1-0.20251013234738-63d1a5100f82 // indirect | ||
| golang.org/x/oauth2 v0.33.0 // indirect | ||
| golang.org/x/sys v0.37.0 // indirect | ||
| golang.org/x/text v0.30.0 // indirect | ||
| google.golang.org/genproto/googleapis/api v0.0.0-20251022142026-3a174f9686a8 // indirect | ||
| google.golang.org/genproto/googleapis/rpc v0.0.0-20251103181224-f26f9409b101 // indirect | ||
| google.golang.org/protobuf v1.36.10 // indirect | ||
| gopkg.in/yaml.v3 v3.0.1 // indirect | ||
| ) | ||
|
|
||
| // StackRox library - pinned to specific commit SHA. | ||
| // Additional two libraries have to be replaced, because go is not able to resolve version "v0.0.0" used for them. | ||
| replace ( | ||
| github.com/heroku/docker-registry-client => github.com/stackrox/docker-registry-client v0.2.1 | ||
| github.com/operator-framework/helm-operator-plugins => github.com/stackrox/helm-operator v0.8.1-0.20250929095149-d1ee3c386305 | ||
|
|
||
| github.com/stackrox/rox => github.com/stackrox/stackrox v0.0.0-20251113103849-f9a0378795b1 | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this boolean has no meaning we are only interested in keys
since we have a dependency on stackrox we could use stringset
or since it's just a test a slice will be enough