@@ -254,16 +254,9 @@ func (s *SSEServer) handleSSE(w http.ResponseWriter, r *http.Request) {
254
254
}
255
255
}
256
256
}()
257
- // Use either just the path or the complete URL based on configuration.
258
- // This prevents issues with clients that concatenate the base URL themselves.
259
- messageEndpoint := s .messageEndpoint
260
- if s .useFullURLForMessageEndpoint {
261
- messageEndpoint = s .CompleteMessageEndpoint ()
262
- }
263
- messageEndpoint = fmt .Sprintf ("%s?sessionId=%s" , messageEndpoint , sessionID )
264
257
265
258
// Send the initial endpoint event
266
- fmt .Fprintf (w , "event: endpoint\n data: %s\r \n \r \n " , messageEndpoint )
259
+ fmt .Fprintf (w , "event: endpoint\n data: %s\r \n \r \n " , s . GetMessageEndpointForClient ( sessionID ) )
267
260
flusher .Flush ()
268
261
269
262
// Main event loop - this runs in the HTTP handler goroutine
@@ -280,6 +273,16 @@ func (s *SSEServer) handleSSE(w http.ResponseWriter, r *http.Request) {
280
273
}
281
274
}
282
275
276
+ // GetMessageEndpointForClient returns the appropriate message endpoint URL with session ID
277
+ // based on the useFullURLForMessageEndpoint configuration.
278
+ func (s * SSEServer ) GetMessageEndpointForClient (sessionID string ) string {
279
+ messageEndpoint := s .messageEndpoint
280
+ if s .useFullURLForMessageEndpoint {
281
+ messageEndpoint = s .CompleteMessageEndpoint ()
282
+ }
283
+ return fmt .Sprintf ("%s?sessionId=%s" , messageEndpoint , sessionID )
284
+ }
285
+
283
286
// handleMessage processes incoming JSON-RPC messages from clients and sends responses
284
287
// back through both the SSE connection and HTTP response.
285
288
func (s * SSEServer ) handleMessage (w http.ResponseWriter , r * http.Request ) {
0 commit comments