Skip to content

Commit 5162f08

Browse files
sharpninjaCopilot
andcommitted
fix(voice): use ResponseHeadersRead for SSE streaming
HttpClient defaults to buffering the entire response before returning the stream. Using HttpCompletionOption.ResponseHeadersRead allows the client to read SSE events as they arrive from the server, enabling real-time streaming display in the app. Also added server-side diagnostic logging for streaming events. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 4899f3b commit 5162f08

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

src/McpServerManager.Core/Services/McpVoiceConversationService.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,16 @@ public async IAsyncEnumerable<McpVoiceTurnStreamEvent> SubmitTurnStreamingAsync(
107107
HttpResponseMessage? response = null;
108108
try
109109
{
110-
response = await client.PostAsJsonAsync(
111-
$"mcp/voice/session/{Uri.EscapeDataString(sessionId)}/turn/stream",
112-
request,
113-
JsonOptions,
110+
var jsonBody = JsonSerializer.Serialize(request, JsonOptions);
111+
using var content = new StringContent(jsonBody, System.Text.Encoding.UTF8, "application/json");
112+
113+
// ResponseHeadersRead is critical: starts returning stream data immediately
114+
// instead of buffering the entire response
115+
response = await client.SendAsync(
116+
new HttpRequestMessage(HttpMethod.Post,
117+
$"mcp/voice/session/{Uri.EscapeDataString(sessionId)}/turn/stream")
118+
{ Content = content },
119+
HttpCompletionOption.ResponseHeadersRead,
114120
cancellationToken).ConfigureAwait(false);
115121
await EnsureSuccessAsync(response, cancellationToken).ConfigureAwait(false);
116122

0 commit comments

Comments
 (0)