Skip to content

Commit 10c82f7

Browse files
authored
refactor(toolsets): renamed Profile to Toolset (#309)
As a prior step to providing support for toolsets this change repurposes the current work in profiles which partially aligns with the toolsets expected features Signed-off-by: Marc Nuri <[email protected]>
1 parent 467e7e6 commit 10c82f7

File tree

8 files changed

+84
-84
lines changed

8 files changed

+84
-84
lines changed

pkg/http/http_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (c *httpContext) beforeEach(t *testing.T) {
8787
}
8888
c.StaticConfig.Port = fmt.Sprintf("%d", ln.Addr().(*net.TCPAddr).Port)
8989
mcpServer, err := mcp.NewServer(mcp.Configuration{
90-
Profile: mcp.Profiles[0],
90+
Toolset: mcp.Toolsets[0],
9191
StaticConfig: c.StaticConfig,
9292
})
9393
if err != nil {

pkg/kubernetes-mcp-server/cmd/root.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type MCPServerOptions struct {
5757
HttpPort int
5858
SSEBaseUrl string
5959
Kubeconfig string
60-
Profile string
60+
Toolset string
6161
ListOutput string
6262
ReadOnly bool
6363
DisableDestructive bool
@@ -77,7 +77,7 @@ type MCPServerOptions struct {
7777
func NewMCPServerOptions(streams genericiooptions.IOStreams) *MCPServerOptions {
7878
return &MCPServerOptions{
7979
IOStreams: streams,
80-
Profile: "full",
80+
Toolset: "full",
8181
ListOutput: "table",
8282
StaticConfig: &config.StaticConfig{},
8383
}
@@ -107,15 +107,15 @@ func NewMCPServer(streams genericiooptions.IOStreams) *cobra.Command {
107107

108108
cmd.Flags().BoolVar(&o.Version, "version", o.Version, "Print version information and quit")
109109
cmd.Flags().IntVar(&o.LogLevel, "log-level", o.LogLevel, "Set the log level (from 0 to 9)")
110-
cmd.Flags().StringVar(&o.ConfigPath, "config", o.ConfigPath, "Path of the config file. Each profile has its set of defaults.")
110+
cmd.Flags().StringVar(&o.ConfigPath, "config", o.ConfigPath, "Path of the config file.")
111111
cmd.Flags().IntVar(&o.SSEPort, "sse-port", o.SSEPort, "Start a SSE server on the specified port")
112112
cmd.Flag("sse-port").Deprecated = "Use --port instead"
113113
cmd.Flags().IntVar(&o.HttpPort, "http-port", o.HttpPort, "Start a streamable HTTP server on the specified port")
114114
cmd.Flag("http-port").Deprecated = "Use --port instead"
115115
cmd.Flags().StringVar(&o.Port, "port", o.Port, "Start a streamable HTTP and SSE HTTP server on the specified port (e.g. 8080)")
116116
cmd.Flags().StringVar(&o.SSEBaseUrl, "sse-base-url", o.SSEBaseUrl, "SSE public base URL to use when sending the endpoint message (e.g. https://example.com)")
117117
cmd.Flags().StringVar(&o.Kubeconfig, "kubeconfig", o.Kubeconfig, "Path to the kubeconfig file to use for authentication")
118-
cmd.Flags().StringVar(&o.Profile, "profile", o.Profile, "MCP profile to use (one of: "+strings.Join(mcp.ProfileNames, ", ")+")")
118+
cmd.Flags().StringVar(&o.Toolset, "toolset", o.Toolset, "MCP toolset to use (one of: "+strings.Join(mcp.ToolsetNames, ", ")+")")
119119
cmd.Flags().StringVar(&o.ListOutput, "list-output", o.ListOutput, "Output format for resource list operations (one of: "+strings.Join(output.Names, ", ")+"). Defaults to table.")
120120
cmd.Flags().BoolVar(&o.ReadOnly, "read-only", o.ReadOnly, "If true, only tools annotated with readOnlyHint=true are exposed")
121121
cmd.Flags().BoolVar(&o.DisableDestructive, "disable-destructive", o.DisableDestructive, "If true, tools annotated with destructiveHint=true are disabled")
@@ -237,17 +237,17 @@ func (m *MCPServerOptions) Validate() error {
237237
}
238238

239239
func (m *MCPServerOptions) Run() error {
240-
profile := mcp.ProfileFromString(m.Profile)
241-
if profile == nil {
242-
return fmt.Errorf("invalid profile name: %s, valid names are: %s", m.Profile, strings.Join(mcp.ProfileNames, ", "))
240+
toolset := mcp.ToolsetFromString(m.Toolset)
241+
if toolset == nil {
242+
return fmt.Errorf("invalid toolset name: %s, valid names are: %s", m.Toolset, strings.Join(mcp.ToolsetNames, ", "))
243243
}
244244
listOutput := output.FromString(m.StaticConfig.ListOutput)
245245
if listOutput == nil {
246246
return fmt.Errorf("invalid output name: %s, valid names are: %s", m.StaticConfig.ListOutput, strings.Join(output.Names, ", "))
247247
}
248248
klog.V(1).Info("Starting kubernetes-mcp-server")
249249
klog.V(1).Infof(" - Config: %s", m.ConfigPath)
250-
klog.V(1).Infof(" - Profile: %s", profile.GetName())
250+
klog.V(1).Infof(" - Toolset: %s", toolset.GetName())
251251
klog.V(1).Infof(" - ListOutput: %s", listOutput.GetName())
252252
klog.V(1).Infof(" - Read-only mode: %t", m.StaticConfig.ReadOnly)
253253
klog.V(1).Infof(" - Disable destructive tools: %t", m.StaticConfig.DisableDestructive)
@@ -291,7 +291,7 @@ func (m *MCPServerOptions) Run() error {
291291
}
292292

293293
mcpServer, err := mcp.NewServer(mcp.Configuration{
294-
Profile: profile,
294+
Toolset: toolset,
295295
ListOutput: listOutput,
296296
StaticConfig: m.StaticConfig,
297297
})

pkg/kubernetes-mcp-server/cmd/root_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,32 +129,32 @@ func TestConfig(t *testing.T) {
129129
})
130130
}
131131

132-
func TestProfile(t *testing.T) {
132+
func TestToolset(t *testing.T) {
133133
t.Run("available", func(t *testing.T) {
134134
ioStreams, _ := testStream()
135135
rootCmd := NewMCPServer(ioStreams)
136136
rootCmd.SetArgs([]string{"--help"})
137137
o, err := captureOutput(rootCmd.Execute) // --help doesn't use logger/klog, cobra prints directly to stdout
138-
if !strings.Contains(o, "MCP profile to use (one of: full) ") {
139-
t.Fatalf("Expected all available profiles, got %s %v", o, err)
138+
if !strings.Contains(o, "MCP toolset to use (one of: full) ") {
139+
t.Fatalf("Expected all available toolsets, got %s %v", o, err)
140140
}
141141
})
142142
t.Run("default", func(t *testing.T) {
143143
ioStreams, out := testStream()
144144
rootCmd := NewMCPServer(ioStreams)
145145
rootCmd.SetArgs([]string{"--version", "--log-level=1"})
146-
if err := rootCmd.Execute(); !strings.Contains(out.String(), "- Profile: full") {
147-
t.Fatalf("Expected profile 'full', got %s %v", out, err)
146+
if err := rootCmd.Execute(); !strings.Contains(out.String(), "- Toolset: full") {
147+
t.Fatalf("Expected toolset 'full', got %s %v", out, err)
148148
}
149149
})
150-
t.Run("set with --profile", func(t *testing.T) {
150+
t.Run("set with --toolset", func(t *testing.T) {
151151
ioStreams, out := testStream()
152152
rootCmd := NewMCPServer(ioStreams)
153-
rootCmd.SetArgs([]string{"--version", "--log-level=1", "--profile", "full"}) // TODO: change by some non-default profile
153+
rootCmd.SetArgs([]string{"--version", "--log-level=1", "--toolset", "full"}) // TODO: change by some non-default toolset
154154
_ = rootCmd.Execute()
155-
expected := `(?m)\" - Profile\: full\"`
155+
expected := `(?m)\" - Toolset\: full\"`
156156
if m, err := regexp.MatchString(expected, out.String()); !m || err != nil {
157-
t.Fatalf("Expected profile to be %s, got %s %v", expected, out.String(), err)
157+
t.Fatalf("Expected toolset to be %s, got %s %v", expected, out.String(), err)
158158
}
159159
})
160160
}

pkg/mcp/common_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func TestMain(m *testing.M) {
103103
}
104104

105105
type mcpContext struct {
106-
profile Profile
106+
toolset Toolset
107107
listOutput output.Output
108108
logLevel int
109109

@@ -126,8 +126,8 @@ func (c *mcpContext) beforeEach(t *testing.T) {
126126
c.ctx, c.cancel = context.WithCancel(t.Context())
127127
c.tempDir = t.TempDir()
128128
c.withKubeConfig(nil)
129-
if c.profile == nil {
130-
c.profile = &FullProfile{}
129+
if c.toolset == nil {
130+
c.toolset = &Full{}
131131
}
132132
if c.listOutput == nil {
133133
c.listOutput = output.Yaml
@@ -149,7 +149,7 @@ func (c *mcpContext) beforeEach(t *testing.T) {
149149
klog.SetLogger(textlogger.NewLogger(textlogger.NewConfig(textlogger.Verbosity(c.logLevel), textlogger.Output(&c.logBuffer))))
150150
// MCP Server
151151
if c.mcpServer, err = NewServer(Configuration{
152-
Profile: c.profile,
152+
Toolset: c.toolset,
153153
ListOutput: c.listOutput,
154154
StaticConfig: c.staticConfig,
155155
}); err != nil {
@@ -188,7 +188,7 @@ func (c *mcpContext) afterEach() {
188188
}
189189

190190
func testCase(t *testing.T, test func(c *mcpContext)) {
191-
testCaseWithContext(t, &mcpContext{profile: &FullProfile{}}, test)
191+
testCaseWithContext(t, &mcpContext{toolset: &Full{}}, test)
192192
}
193193

194194
func testCaseWithContext(t *testing.T, mcpCtx *mcpContext, test func(c *mcpContext)) {

pkg/mcp/mcp.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type ContextKey string
2424
const TokenScopesContextKey = ContextKey("TokenScopesContextKey")
2525

2626
type Configuration struct {
27-
Profile Profile
27+
Toolset Toolset
2828
ListOutput output.Output
2929

3030
StaticConfig *config.StaticConfig
@@ -89,7 +89,7 @@ func (s *Server) reloadKubernetesClient() error {
8989
}
9090
s.k = k
9191
applicableTools := make([]server.ServerTool, 0)
92-
for _, tool := range s.configuration.Profile.GetTools(s) {
92+
for _, tool := range s.configuration.Toolset.GetTools(s) {
9393
if !s.configuration.isToolApplicable(tool) {
9494
continue
9595
}

pkg/mcp/profiles.go

Lines changed: 0 additions & 54 deletions
This file was deleted.

pkg/mcp/toolsets.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package mcp
2+
3+
import (
4+
"slices"
5+
6+
"github.com/mark3labs/mcp-go/server"
7+
)
8+
9+
type Toolset interface {
10+
GetName() string
11+
GetDescription() string
12+
GetTools(s *Server) []server.ServerTool
13+
}
14+
15+
var Toolsets = []Toolset{
16+
&Full{},
17+
}
18+
19+
var ToolsetNames []string
20+
21+
func ToolsetFromString(name string) Toolset {
22+
for _, toolset := range Toolsets {
23+
if toolset.GetName() == name {
24+
return toolset
25+
}
26+
}
27+
return nil
28+
}
29+
30+
type Full struct{}
31+
32+
func (p *Full) GetName() string {
33+
return "full"
34+
}
35+
func (p *Full) GetDescription() string {
36+
return "Complete toolset with all tools and extended outputs"
37+
}
38+
func (p *Full) GetTools(s *Server) []server.ServerTool {
39+
return slices.Concat(
40+
s.initConfiguration(),
41+
s.initEvents(),
42+
s.initNamespaces(),
43+
s.initPods(),
44+
s.initResources(),
45+
s.initHelm(),
46+
)
47+
}
48+
49+
func init() {
50+
ToolsetNames = make([]string, 0)
51+
for _, toolset := range Toolsets {
52+
ToolsetNames = append(ToolsetNames, toolset.GetName())
53+
}
54+
}

pkg/mcp/profiles_test.go renamed to pkg/mcp/toolsets_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/mark3labs/mcp-go/mcp"
99
)
1010

11-
func TestFullProfileTools(t *testing.T) {
11+
func TestFullToolsetTools(t *testing.T) {
1212
expectedNames := []string{
1313
"configuration_view",
1414
"events_list",
@@ -29,7 +29,7 @@ func TestFullProfileTools(t *testing.T) {
2929
"resources_create_or_update",
3030
"resources_delete",
3131
}
32-
mcpCtx := &mcpContext{profile: &FullProfile{}}
32+
mcpCtx := &mcpContext{toolset: &Full{}}
3333
testCaseWithContext(t, mcpCtx, func(c *mcpContext) {
3434
tools, err := c.mcpClient.ListTools(c.ctx, mcp.ListToolsRequest{})
3535
t.Run("ListTools returns tools", func(t *testing.T) {
@@ -53,9 +53,9 @@ func TestFullProfileTools(t *testing.T) {
5353
})
5454
}
5555

56-
func TestFullProfileToolsInOpenShift(t *testing.T) {
56+
func TestFullToolsetToolsInOpenShift(t *testing.T) {
5757
mcpCtx := &mcpContext{
58-
profile: &FullProfile{},
58+
toolset: &Full{},
5959
before: inOpenShift,
6060
after: inOpenShiftClear,
6161
}

0 commit comments

Comments
 (0)