Skip to content

Conversation

@ardaguclu
Copy link
Member

https://github.com/kubernetes/sample-cli-plugin provides a skeleton of how kubernetes tools can be. This PR makes necessary changes to align with sample-cli-plugin. Thanks to that, we'll remove some dependencies from go.mod.

This PR must be no-op.

type MCPServerOptions struct {
Version bool
LogLevel int
SSEPort int
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be string. For the simplicity of this PR, it is better to change the type in a followup PR.

Version bool
LogLevel int
SSEPort int
HttpPort int
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

}

cmd.Flags().BoolVar(&o.Version, "version", o.Version, "Print version information and quit")
cmd.Flags().IntVar(&o.LogLevel, "log-level", o.LogLevel, "Set the log level (from 0 to 9)")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of having a separate log-level flag, we can directly wire the -v in klog.


if m.SSEPort > 0 {
sseServer := mcpServer.ServeSse(m.SSEBaseUrl)
defer func() { _ = sseServer.Shutdown(ctx) }()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't pass ctx anywhere apart from here. I assume that we should pass the context to internal tools.

}
}

if err := mcpServer.ServeStdio(); err != nil && !errors.Is(err, context.Canceled) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we don't pass context in anywhere, it is not possible to get context.Cancelled. We need to wire this.

@ardaguclu
Copy link
Member Author

@manusa would you please have a look at this, when you have a chance?. Thank you.

@ardaguclu
Copy link
Member Author

Checking the failures unit test failures...

@manusa
Copy link
Member

manusa commented Jun 17, 2025

Checking the failures unit test failures...

probably related to the tightly coupling of the cmd outputs and cobra internals.

}

func TestListOutput(t *testing.T) {
t.Run("available", func(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to remove this test. Because in Cobra, there is no easy way to test kubernetes-mcp-server --help. Maybe we don't need to test this anyway?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have what I call test-compulsive disorder (TCD) 😅

Disable/skip the tests that are giving you problems and add a TODO comment, I'll try to fix them at another time

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've successfully added back this test by using captureOutput.

@ardaguclu
Copy link
Member Author

@manusa this is ready for your review, when you have a chance.

@manusa manusa added this to the 0.1.0 milestone Jun 17, 2025 — with automated-tasks
Copy link
Member

@manusa manusa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thx!

@manusa manusa merged commit 2f297fc into containers:main Jun 17, 2025
5 checks passed
@ardaguclu ardaguclu deleted the use-cobra branch June 17, 2025 17:03
Comment on lines +103 to +106
func (m *MCPServerOptions) Complete() error {
m.initializeLogging()

return nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of this method?

Is it to match this plugin structure?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used to initialization steps like kubeconfig, dynamic client, etc. Conceptually, when Run is called, everything should be ready to work.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Complete -> all the initializations are completed
Validate -> everything is validated
Run -> should run the actual command

Copy link
Member Author

@ardaguclu ardaguclu Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That said; these https://github.com/manusa/kubernetes-mcp-server/blob/2c18ca0822b51bf7de8d41baada87475cd446525/pkg/kubernetes-mcp-server/cmd/root.go#L126-L138 can be moved to Complete and Validate

This https://github.com/manusa/kubernetes-mcp-server/blob/2c18ca0822b51bf7de8d41baada87475cd446525/pkg/kubernetes-mcp-server/cmd/root.go#L140-L143 should be a separate command kubernete-mcp-server version instead of --version

and There should be 3 managers -- stdio, sse, the other and Run should execute the requested one mcp.NewServer is nicely wired already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants