feat!: base-url is optional

BREAKING CHANGE:
mandatory `sse-public-host` CLI option has been renamed to `sse-base-url`
and is now optional.

Users are expected to provide it using the port if necessary:
--sse-base-url http://localhost:8080
This commit is contained in:
Marc Nuri
2025-03-20 07:02:07 +01:00
parent 3cc4f32ca0
commit b0cd15e7ae
2 changed files with 8 additions and 5 deletions

View File

@@ -45,7 +45,7 @@ Kubernetes Model Context Protocol (MCP) server
var sseServer *server.SSEServer
if ssePort := viper.GetInt("sse-port"); ssePort > 0 {
sseServer = mcpServer.ServeSse(viper.GetString("sse-public-host"), ssePort)
sseServer = mcpServer.ServeSse(viper.GetString("sse-base-url"))
if err := sseServer.Start(fmt.Sprintf(":%d", ssePort)); err != nil {
panic(err)
}
@@ -62,7 +62,7 @@ Kubernetes Model Context Protocol (MCP) server
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")
rootCmd.Flags().StringP("sse-base-url", "", "", "SSE public base URL to use when sending the endpoint message (e.g. https://example.com)")
_ = viper.BindPFlags(rootCmd.Flags())
}

View File

@@ -1,7 +1,6 @@
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"
@@ -49,8 +48,12 @@ 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, server.WithBaseURL(fmt.Sprintf("http://%s:%d", publicHost, port)))
func (s *Server) ServeSse(baseUrl string) *server.SSEServer {
options := make([]server.SSEOption, 0)
if baseUrl != "" {
options = append(options, server.WithBaseURL(baseUrl))
}
return server.NewSSEServer(s.server, options...)
}
func NewTextResult(content string, err error) *mcp.CallToolResult {