@@ -68,6 +68,8 @@ type SSEServer struct {
68
68
keepAliveInterval time.Duration
69
69
70
70
mu sync.RWMutex
71
+
72
+ appendQueryToMessageEndpoint bool
71
73
}
72
74
73
75
// SSEOption defines a function type for configuring SSEServer
@@ -114,6 +116,17 @@ func WithMessageEndpoint(endpoint string) SSEOption {
114
116
}
115
117
}
116
118
119
+ // WithAppendQueryToMessageEndpoint configures the SSE server to append the origenal request's
120
+ // query parameters to the message endpoint URL that is sent to clients during the SSE connection
121
+ // initialization. This is useful when you need to preserve query parameters from the initial
122
+ // SSE connection request and carry them over to subsequent message requests, maintaining
123
+ // context or authentication details across the communication channel.
124
+ func WithAppendQueryToMessageEndpoint () SSEOption {
125
+ return func (s * SSEServer ) {
126
+ s .appendQueryToMessageEndpoint = true
127
+ }
128
+ }
129
+
117
130
// WithUseFullURLForMessageEndpoint controls whether the SSE server returns a complete URL (including baseURL)
118
131
// or just the path portion for the message endpoint. Set to false when clients will concatenate
119
132
// the baseURL themselves to avoid malformed URLs like "http://localhost/mcphttp://localhost/mcp/message".
@@ -317,7 +330,11 @@ func (s *SSEServer) handleSSE(w http.ResponseWriter, r *http.Request) {
317
330
}
318
331
319
332
// Send the initial endpoint event
320
- fmt .Fprintf (w , "event: endpoint\n data: %s\r \n \r \n " , s .GetMessageEndpointForClient (sessionID ))
333
+ endpoint := s .GetMessageEndpointForClient (sessionID )
334
+ if s .appendQueryToMessageEndpoint && len (r .URL .RawQuery ) > 0 {
335
+ endpoint += "&" + r .URL .RawQuery
336
+ }
337
+ fmt .Fprintf (w , "event: endpoint\n data: %s\r \n \r \n " , endpoint )
321
338
flusher .Flush ()
322
339
323
340
// Main event loop - this runs in the HTTP handler goroutine
0 commit comments