-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.go
More file actions
67 lines (55 loc) · 2.11 KB
/
Copy pathapp.go
File metadata and controls
67 lines (55 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Package app contains the main application logic for the stackrox-mcp server.
// This is separated from the main package to allow tests to run the server in-process.
package app
import (
"context"
"io"
"log/slog"
"os"
"os/signal"
"syscall"
"github.com/pkg/errors"
"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/toolsets"
toolsetConfig "github.com/stackrox/stackrox-mcp/internal/toolsets/config"
toolsetViolations "github.com/stackrox/stackrox-mcp/internal/toolsets/violations"
toolsetVulnerability "github.com/stackrox/stackrox-mcp/internal/toolsets/vulnerability"
)
// GetToolsets initializes and returns all available toolsets.
func GetToolsets(cfg *config.Config, c *client.Client) []toolsets.Toolset {
return []toolsets.Toolset{
toolsetConfig.NewToolset(cfg, c),
toolsetVulnerability.NewToolset(cfg, c),
toolsetViolations.NewToolset(cfg, c),
}
}
// Run executes the MCP server with the given configuration and I/O streams.
func Run(ctx context.Context, cfg *config.Config, stdin io.ReadCloser, stdout io.WriteCloser) error {
// Log full configuration with sensitive data redacted.
slog.Info("Configuration loaded successfully", "config", cfg.Redacted())
// Create a cancellable context for the entire server lifecycle
ctx, cancel := context.WithCancel(ctx)
defer cancel()
// Set up signal handling for graceful shutdown.
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
go func() {
<-sigChan
slog.Info("Received shutdown signal")
cancel()
}()
stackroxClient, err := client.NewClient(&cfg.Central)
if err != nil {
return errors.Wrap(err, "failed to create client")
}
registry := toolsets.NewRegistry(cfg, GetToolsets(cfg, stackroxClient))
srv := server.NewServer(cfg, registry)
err = stackroxClient.Connect(ctx)
if err != nil {
return errors.Wrap(err, "failed to connect to central")
}
slog.Info("Starting StackRox MCP server")
return errors.Wrap(srv.Start(ctx, stdin, stdout), "failed to start server")
}