@@ -40,12 +40,18 @@ Kubernetes Model Context Protocol (MCP) server
4040  # TODO: add more examples` ,
4141	Run : func (cmd  * cobra.Command , args  []string ) {
4242		initLogging ()
43- 		klog .V (5 ).Infof ("Starting kubernetes-mcp-server" )
43+ 		profile  :=  mcp .ProfileFromString (viper .GetString ("profile" ))
44+ 		if  profile  ==  nil  {
45+ 			fmt .Printf ("Invalid profile name: %s, valid names are: %s\n " , viper .GetString ("profile" ), mcp .ProfileNames )
46+ 			os .Exit (1 )
47+ 		}
48+ 		klog .V (1 ).Infof ("Starting kubernetes-mcp-server with profile: %s" , profile .GetName ())
4449		if  viper .GetBool ("version" ) {
4550			fmt .Println (version .Version )
4651			return 
4752		}
4853		mcpServer , err  :=  mcp .NewSever (mcp.Configuration {
54+ 			Profile :    profile ,
4955			Kubeconfig : viper .GetString ("kubeconfig" ),
5056		})
5157		if  err  !=  nil  {
@@ -70,27 +76,51 @@ Kubernetes Model Context Protocol (MCP) server
7076	},
7177}
7278
73- func  init () {
74- 	rootCmd .Flags ().BoolP ("version" , "v" , false , "Print version information and quit" )
75- 	rootCmd .Flags ().IntP ("log-level" , "" , 0 , "Set the log level (from 0 to 9)" )
76- 	rootCmd .Flags ().IntP ("sse-port" , "" , 0 , "Start a SSE server on the specified port" )
77- 	rootCmd .Flags ().StringP ("sse-base-url" , "" , "" , "SSE public base URL to use when sending the endpoint message (e.g. https://example.com)" )
78- 	rootCmd .Flags ().StringP ("kubeconfig" , "" , "" , "Path to the kubeconfig file to use for authentication" )
79- 	_  =  viper .BindPFlags (rootCmd .Flags ())
80- }
81- 
8279func  Execute () {
8380	if  err  :=  rootCmd .Execute (); err  !=  nil  {
84- 		panic (err )
81+ 		klog .Errorf ("Failed to execute command: %s" , err )
82+ 		os .Exit (1 )
8583	}
8684}
8785
8886func  initLogging () {
89- 	logger  :=  textlogger .NewLogger (textlogger .NewConfig (textlogger .Output (os .Stdout )))
90- 	klog .SetLoggerWithOptions (logger )
9187	flagSet  :=  flag .NewFlagSet ("kubernetes-mcp-server" , flag .ContinueOnError )
9288	klog .InitFlags (flagSet )
89+ 	loggerOptions  :=  []textlogger.ConfigOption {textlogger .Output (os .Stdout )}
9390	if  logLevel  :=  viper .GetInt ("log-level" ); logLevel  >=  0  {
91+ 		loggerOptions  =  append (loggerOptions , textlogger .Verbosity (logLevel ))
9492		_  =  flagSet .Parse ([]string {"--v" , strconv .Itoa (logLevel )})
9593	}
94+ 	logger  :=  textlogger .NewLogger (textlogger .NewConfig (loggerOptions ... ))
95+ 	klog .SetLoggerWithOptions (logger )
96+ }
97+ 
98+ type  profileFlag  struct  {
99+ 	mcp.Profile 
100+ }
101+ 
102+ func  (p  * profileFlag ) String () string  {
103+ 	return  p .GetName ()
104+ }
105+ 
106+ func  (p  * profileFlag ) Set (v  string ) error  {
107+ 	p .Profile  =  mcp .ProfileFromString (v )
108+ 	if  p .Profile  !=  nil  {
109+ 		return  nil 
110+ 	}
111+ 	return  fmt .Errorf ("invalid profile name: %s, valid names are: %s" , v , mcp .ProfileNames )
112+ }
113+ 
114+ func  (p  * profileFlag ) Type () string  {
115+ 	return  "profile" 
116+ }
117+ 
118+ func  init () {
119+ 	rootCmd .Flags ().BoolP ("version" , "v" , false , "Print version information and quit" )
120+ 	rootCmd .Flags ().IntP ("log-level" , "" , 0 , "Set the log level (from 0 to 9)" )
121+ 	rootCmd .Flags ().IntP ("sse-port" , "" , 0 , "Start a SSE server on the specified port" )
122+ 	rootCmd .Flags ().StringP ("sse-base-url" , "" , "" , "SSE public base URL to use when sending the endpoint message (e.g. https://example.com)" )
123+ 	rootCmd .Flags ().StringP ("kubeconfig" , "" , "" , "Path to the kubeconfig file to use for authentication" )
124+ 	rootCmd .Flags ().Var (& profileFlag {& mcp.FullProfile {}}, "profile" , "MCP profile to use" )
125+ 	_  =  viper .BindPFlags (rootCmd .Flags ())
96126}
0 commit comments