@@ -670,6 +670,56 @@ func TestStreamableHTTP_SessionWithTools(t *testing.T) {
670670 })
671671}
672672
673+ func TestStreamableHTTPServer_WithOptions (t * testing.T ) {
674+ t .Run ("WithStreamableHTTPServer sets httpServer field" , func (t * testing.T ) {
675+ mcpServer := NewMCPServer ("test" , "1.0.0" )
676+ customServer := & http.Server {Addr : ":9999" }
677+ httpServer := NewStreamableHTTPServer (mcpServer , WithStreamableHTTPServer (customServer ))
678+
679+ if httpServer .httpServer != customServer {
680+ t .Errorf ("Expected httpServer to be set to custom server instance, got %v" , httpServer .httpServer )
681+ }
682+ })
683+
684+ t .Run ("Start with conflicting address returns error" , func (t * testing.T ) {
685+ mcpServer := NewMCPServer ("test" , "1.0.0" )
686+ customServer := & http.Server {Addr : ":9999" }
687+ httpServer := NewStreamableHTTPServer (mcpServer , WithStreamableHTTPServer (customServer ))
688+
689+ err := httpServer .Start (":8888" )
690+ if err == nil {
691+ t .Error ("Expected error for conflicting address, got nil" )
692+ } else if ! strings .Contains (err .Error (), "conflicting listen address" ) {
693+ t .Errorf ("Expected error message to contain 'conflicting listen address', got '%s'" , err .Error ())
694+ }
695+ })
696+
697+ t .Run ("Options consistency test" , func (t * testing.T ) {
698+ mcpServer := NewMCPServer ("test" , "1.0.0" )
699+ endpointPath := "/test-mcp"
700+ customServer := & http.Server {}
701+
702+ // Options to test
703+ options := []StreamableHTTPOption {
704+ WithEndpointPath (endpointPath ),
705+ WithStreamableHTTPServer (customServer ),
706+ }
707+
708+ // Apply options multiple times and verify consistency
709+ for i := 0 ; i < 10 ; i ++ {
710+ server := NewStreamableHTTPServer (mcpServer , options ... )
711+
712+ if server .endpointPath != endpointPath {
713+ t .Errorf ("Expected endpointPath %s, got %s" , endpointPath , server .endpointPath )
714+ }
715+
716+ if server .httpServer != customServer {
717+ t .Errorf ("Expected httpServer to match, got %v" , server .httpServer )
718+ }
719+ }
720+ })
721+ }
722+
673723func postJSON (url string , bodyObject any ) (* http.Response , error ) {
674724 jsonBody , _ := json .Marshal (bodyObject )
675725 req , _ := http .NewRequest (http .MethodPost , url , bytes .NewBuffer (jsonBody ))
0 commit comments