55	"flag" 
66	"fmt" 
77	"github.com/manusa/kubernetes-mcp-server/pkg/mcp" 
8+ 	"github.com/manusa/kubernetes-mcp-server/pkg/output" 
89	"github.com/manusa/kubernetes-mcp-server/pkg/version" 
910	"github.com/mark3labs/mcp-go/server" 
1011	"github.com/spf13/cobra" 
@@ -46,8 +47,14 @@ Kubernetes Model Context Protocol (MCP) server
4647			fmt .Printf ("Invalid profile name: %s, valid names are: %s\n " , viper .GetString ("profile" ), strings .Join (mcp .ProfileNames , ", " ))
4748			os .Exit (1 )
4849		}
50+ 		o  :=  output .FromString (viper .GetString ("output" ))
51+ 		if  o  ==  nil  {
52+ 			fmt .Printf ("Invalid output name: %s, valid names are: %s\n " , viper .GetString ("output" ), strings .Join (output .Names , ", " ))
53+ 			os .Exit (1 )
54+ 		}
4955		klog .V (1 ).Info ("Starting kubernetes-mcp-server" )
5056		klog .V (1 ).Infof (" - Profile: %s" , profile .GetName ())
57+ 		klog .V (1 ).Infof (" - Output: %s" , o .GetName ())
5158		klog .V (1 ).Infof (" - Read-only mode: %t" , viper .GetBool ("read-only" ))
5259		klog .V (1 ).Infof (" - Disable destructive tools: %t" , viper .GetBool ("disable-destructive" ))
5360		if  viper .GetBool ("version" ) {
@@ -56,6 +63,7 @@ Kubernetes Model Context Protocol (MCP) server
5663		}
5764		mcpServer , err  :=  mcp .NewSever (mcp.Configuration {
5865			Profile :            profile ,
66+ 			Output :             o ,
5967			ReadOnly :           viper .GetBool ("read-only" ),
6068			DisableDestructive : viper .GetBool ("disable-destructive" ),
6169			Kubeconfig :         viper .GetString ("kubeconfig" ),
@@ -121,14 +129,21 @@ func (p *profileFlag) Type() string {
121129	return  "profile" 
122130}
123131
124- func  init () {
132+ // flagInit initializes the flags for the root command. 
133+ // Exposed for testing purposes. 
134+ func  flagInit () {
125135	rootCmd .Flags ().BoolP ("version" , "v" , false , "Print version information and quit" )
126136	rootCmd .Flags ().IntP ("log-level" , "" , 0 , "Set the log level (from 0 to 9)" )
127137	rootCmd .Flags ().IntP ("sse-port" , "" , 0 , "Start a SSE server on the specified port" )
128138	rootCmd .Flags ().StringP ("sse-base-url" , "" , "" , "SSE public base URL to use when sending the endpoint message (e.g. https://example.com)" )
129139	rootCmd .Flags ().StringP ("kubeconfig" , "" , "" , "Path to the kubeconfig file to use for authentication" )
130- 	rootCmd .Flags ().String ("profile" , "full" , "MCP profile to use (one of: " + strings .Join (mcp .ProfileNames , ", " )+ ")" )
140+ 	rootCmd .Flags ().String ("profile" , "full" , "MCP profile to use (one of: " + strings .Join (mcp .ProfileNames , ", " )+ ") default is full" )
141+ 	rootCmd .Flags ().String ("output" , "yaml" , "Output format for resources (one of: " + strings .Join (output .Names , ", " )+ ") default is yaml" )
131142	rootCmd .Flags ().Bool ("read-only" , false , "If true, only tools annotated with readOnlyHint=true are exposed" )
132143	rootCmd .Flags ().Bool ("disable-destructive" , false , "If true, tools annotated with destructiveHint=true are disabled" )
133144	_  =  viper .BindPFlags (rootCmd .Flags ())
134145}
146+ 
147+ func  init () {
148+ 	flagInit ()
149+ }
0 commit comments