mirror of
https://github.com/openshift/openshift-mcp-server.git
synced 2025-10-17 14:27:48 +03:00
feat: SSE support
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/manusa/kubernetes-mcp-server/pkg/mcp"
|
||||
"github.com/manusa/kubernetes-mcp-server/pkg/version"
|
||||
"github.com/mark3labs/mcp-go/server"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"golang.org/x/net/context"
|
||||
@@ -22,6 +23,15 @@ Kubernetes Model Context Protocol (MCP) server
|
||||
# shows version information
|
||||
kubernetes-mcp-server --version
|
||||
|
||||
# start STDIO server
|
||||
kubernetes-mcp-server
|
||||
|
||||
# start a SSE server on port 8080
|
||||
kubernetes-mcp-server --sse-port 8080
|
||||
|
||||
# start a SSE server on port 8080 with a public host of example.com
|
||||
kubernetes-mcp-server --sse-port 8080 --sse-public-host example.com
|
||||
|
||||
# TODO: add more examples`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if viper.GetBool("version") {
|
||||
@@ -32,14 +42,27 @@ Kubernetes Model Context Protocol (MCP) server
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var sseServer *server.SSEServer
|
||||
if ssePort := viper.GetInt("sse-port"); ssePort > 0 {
|
||||
sseServer = mcpServer.ServeSse(viper.GetString("sse-public-host"), ssePort)
|
||||
if err := sseServer.Start(fmt.Sprintf(":%d", ssePort)); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
if err := mcpServer.ServeStdio(); err != nil && !errors.Is(err, context.Canceled) {
|
||||
panic(err)
|
||||
}
|
||||
if sseServer != nil {
|
||||
_ = sseServer.Shutdown(cmd.Context())
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.Flags().BoolP("version", "v", false, "Print version information and quit")
|
||||
rootCmd.Flags().IntP("sse-port", "", 0, "Start a SSE server on the specified port")
|
||||
rootCmd.Flags().StringP("sse-public-host", "", "localhost", "SSE Public host to use in the server")
|
||||
_ = viper.BindPFlags(rootCmd.Flags())
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mcp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/manusa/kubernetes-mcp-server/pkg/kubernetes"
|
||||
"github.com/manusa/kubernetes-mcp-server/pkg/version"
|
||||
"github.com/mark3labs/mcp-go/mcp"
|
||||
@@ -48,6 +49,10 @@ func (s *Server) ServeStdio() error {
|
||||
return server.ServeStdio(s.server)
|
||||
}
|
||||
|
||||
func (s *Server) ServeSse(publicHost string, port int) *server.SSEServer {
|
||||
return server.NewSSEServer(s.server, fmt.Sprintf("http://%s:%d", publicHost, port))
|
||||
}
|
||||
|
||||
func NewTextResult(content string, err error) *mcp.CallToolResult {
|
||||
if err != nil {
|
||||
return &mcp.CallToolResult{
|
||||
|
||||
Reference in New Issue
Block a user