Skip to content

Commit c6f4e76

Browse files
author
Buf Generate
committed
fix java mcp message endpoint
1 parent 38225de commit c6f4e76

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

server/sse.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,16 +254,9 @@ func (s *SSEServer) handleSSE(w http.ResponseWriter, r *http.Request) {
254254
}
255255
}
256256
}()
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)
264257

265258
// Send the initial endpoint event
266-
fmt.Fprintf(w, "event: endpoint\ndata: %s\r\n\r\n", messageEndpoint)
259+
fmt.Fprintf(w, "event: endpoint\ndata: %s\r\n\r\n", s.GetMessageEndpointForClient(sessionID))
267260
flusher.Flush()
268261

269262
// Main event loop - this runs in the HTTP handler goroutine
@@ -280,6 +273,16 @@ func (s *SSEServer) handleSSE(w http.ResponseWriter, r *http.Request) {
280273
}
281274
}
282275

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+
283286
// handleMessage processes incoming JSON-RPC messages from clients and sends responses
284287
// back through both the SSE connection and HTTP response.
285288
func (s *SSEServer) handleMessage(w http.ResponseWriter, r *http.Request) {

0 commit comments

Comments
 (0)