Skip to content

Commit 0a7d3ff

Browse files
jexpYuan325
andauthored
fix: #419 TLS https URL for SSE endpoint (#420)
Fixes that in SSL deployments, e.g. on k8s or cloud run the SSE endpoint was statically returning `http:` not a scheme based on request TLS attribute. Fixes #419 --------- Co-authored-by: Yuan <45984206+Yuan325@users.noreply.github.com>
1 parent cf96745 commit 0a7d3ff

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎internal/server/mcp.go‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,17 @@ func sseHandler(s *Server, w http.ResponseWriter, r *http.Request) {
126126
s.sseManager.add(sessionId, session)
127127
defer s.sseManager.remove(sessionId)
128128

129+
// https scheme formatting if (forwarded) request is a TLS request
130+
proto := r.Header.Get("X-Forwarded-Proto")
131+
if (proto == "") {
132+
if r.TLS == nil {
133+
proto = "http"
134+
} else {
135+
proto = "https"
136+
}
137+
}
129138
// send initial endpoint event
130-
messageEndpoint := fmt.Sprintf("http://%s/mcp?sessionId=%s", r.Host, sessionId)
139+
messageEndpoint := fmt.Sprintf("%s://%s/mcp?sessionId=%s", proto, r.Host, sessionId)
131140
s.logger.DebugContext(ctx, fmt.Sprintf("sending endpoint event: %s", messageEndpoint))
132141
fmt.Fprintf(w, "event: endpoint\ndata: %s\n\n", messageEndpoint)
133142
flusher.Flush()

0 commit comments

Comments
 (0)