mcp: use http.ResponseController to ensure writes are flushed (#870)

If the ResponseWriter is a wrapped one (which is quite common when using
middleware to log things like response sizes), the direct cast to
`http.Flusher` doesn't find the flush capability. Instead, use
`http.ResponseController` as introduced in go1.20 which handles
unwrapping to find the base response writer.
This commit is contained in:
Dan McGee 2026-03-31 06:13:16 -05:00 • committed by GitHub
commit d3fd25b68a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1053,9 +1053,9 @@ func (c *streamableServerConn) acquireStream(ctx context.Context, w http.Respons
// Issue #410: the standalone SSE stream is likely not to receive messages
// for a long time. Ensure that headers are flushed.
w.WriteHeader(http.StatusOK)
if f, ok := w.(http.Flusher); ok {
f.Flush()
}
rc := http.NewResponseController(w)
// Ignore returned error as flushing is best-effort.
_ = rc.Flush()
}
for _, data := range toReplay {