-
Notifications
You must be signed in to change notification settings - Fork 0
ROX-31474: Add MCP server stack #4
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-31474-add-config
Choose a base branch
from
mtodor/ROX-31475-add-mcp-server
base: mtodor/ROX-31474-add-config
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
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 |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "net" | ||
| "net/http" | ||
| "strconv" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stackrox/stackrox-mcp/internal/config" | ||
| "github.com/stackrox/stackrox-mcp/internal/server" | ||
| "github.com/stackrox/stackrox-mcp/internal/testutil" | ||
| "github.com/stackrox/stackrox-mcp/internal/toolsets" | ||
| "github.com/stretchr/testify/assert" | ||
| "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(cfg) | ||
|
|
||
| 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()) | ||
| } | ||
|
|
||
| func TestGracefulShutdown(t *testing.T) { | ||
| // Set up minimal valid config. | ||
| 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)) | ||
| srv := server.NewServer(cfg, registry) | ||
| ctx, cancel := context.WithCancel(context.Background()) | ||
|
|
||
| errChan := make(chan error, 1) | ||
|
|
||
| go func() { | ||
| errChan <- srv.Start(ctx) | ||
| }() | ||
|
|
||
| serverURL := "http://" + net.JoinHostPort(cfg.Server.Address, strconv.Itoa(cfg.Server.Port)) | ||
| err = testutil.WaitForServerReady(serverURL, 3*time.Second) | ||
| require.NoError(t, err, "Server should start within timeout") | ||
|
|
||
| // 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") | ||
|
|
||
| // Simulate shutdown signal by canceling context. | ||
| cancel() | ||
|
|
||
| // Wait for server to shut down. | ||
| select { | ||
| case err := <-errChan: | ||
| // Server should shut down cleanly (either nil or context.Canceled). | ||
| if err != nil && errors.Is(err, context.Canceled) { | ||
| t.Errorf("Server returned unexpected error: %v", err) | ||
| } | ||
| case <-time.After(5 * time.Second): | ||
| 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
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
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.
maybe when not provided we should use
git describe --tags --abbrev=10 --dirty --longinstead? So development builds will have commit informationUh oh!
There was an error while loading. Please reload this page.
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.
@janisz This does not work for me:
For local dev, we could use:
git rev-parse --short HEAD- but on tag builds, we could get tag info from CI environment. Any better ideas?