5
5
"fmt"
6
6
"github.com/manusa/kubernetes-mcp-server/pkg/mcp"
7
7
"github.com/manusa/kubernetes-mcp-server/pkg/version"
8
+ "github.com/mark3labs/mcp-go/server"
8
9
"github.com/spf13/cobra"
9
10
"github.com/spf13/viper"
10
11
"golang.org/x/net/context"
@@ -22,6 +23,15 @@ Kubernetes Model Context Protocol (MCP) server
22
23
# shows version information
23
24
kubernetes-mcp-server --version
24
25
26
+ # start STDIO server
27
+ kubernetes-mcp-server
28
+
29
+ # start a SSE server on port 8080
30
+ kubernetes-mcp-server --sse-port 8080
31
+
32
+ # start a SSE server on port 8080 with a public host of example.com
33
+ kubernetes-mcp-server --sse-port 8080 --sse-public-host example.com
34
+
25
35
# TODO: add more examples` ,
26
36
Run : func (cmd * cobra.Command , args []string ) {
27
37
if viper .GetBool ("version" ) {
@@ -32,14 +42,27 @@ Kubernetes Model Context Protocol (MCP) server
32
42
if err != nil {
33
43
panic (err )
34
44
}
45
+
46
+ var sseServer * server.SSEServer
47
+ if ssePort := viper .GetInt ("sse-port" ); ssePort > 0 {
48
+ sseServer = mcpServer .ServeSse (viper .GetString ("sse-public-host" ), ssePort )
49
+ if err := sseServer .Start (fmt .Sprintf (":%d" , ssePort )); err != nil {
50
+ panic (err )
51
+ }
52
+ }
35
53
if err := mcpServer .ServeStdio (); err != nil && ! errors .Is (err , context .Canceled ) {
36
54
panic (err )
37
55
}
56
+ if sseServer != nil {
57
+ _ = sseServer .Shutdown (cmd .Context ())
58
+ }
38
59
},
39
60
}
40
61
41
62
func init () {
42
63
rootCmd .Flags ().BoolP ("version" , "v" , false , "Print version information and quit" )
64
+ rootCmd .Flags ().IntP ("sse-port" , "" , 0 , "Start a SSE server on the specified port" )
65
+ rootCmd .Flags ().StringP ("sse-public-host" , "" , "localhost" , "SSE Public host to use in the server" )
43
66
_ = viper .BindPFlags (rootCmd .Flags ())
44
67
}
45
68
0 commit comments