Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ internal async Task<HttpResponseMessage> SendHttpRequestAsync(JsonRpcMessage mes
if (response.Content.Headers.ContentType?.MediaType == "application/json")
{
var responseContent = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
rpcResponseOrError = await ProcessMessageAsync(responseContent, rpcRequest, cancellationToken).ConfigureAwait(false);
if (responseContent.Length > 0)
{
rpcResponseOrError = await ProcessMessageAsync(responseContent, rpcRequest, cancellationToken).ConfigureAwait(false);
}
}
else if (response.Content.Headers.ContentType?.MediaType == "text/event-stream")
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,40 @@ public async Task SendMessageAsync_Handles_Accepted_Response()
Assert.True(true);
}

[Fact]
public async Task StreamableHttp_NotificationWithEmptyAcceptedJsonResponse_DoesNotLogParseFailure()
{
var options = new HttpClientTransportOptions
{
Endpoint = new Uri("http://localhost:8080/mcp"),
TransportMode = HttpTransportMode.StreamableHttp,
};

using var mockHttpHandler = new MockHttpHandler();
using var httpClient = new HttpClient(mockHttpHandler);
await using var transport = new HttpClientTransport(options, httpClient, LoggerFactory);

mockHttpHandler.RequestHandler = request =>
{
Assert.Equal(HttpMethod.Post, request.Method);
Assert.Equal("http://localhost:8080/mcp", request.RequestUri?.AbsoluteUri);

return Task.FromResult(new HttpResponseMessage
{
StatusCode = HttpStatusCode.Accepted,
Content = new StringContent("", Encoding.UTF8, "application/json"),
});
};

await using var session = await transport.ConnectAsync(TestContext.Current.CancellationToken);
await session.SendMessageAsync(
new JsonRpcNotification { Method = "notifications/initialized" },
TestContext.Current.CancellationToken);

Assert.DoesNotContain(MockLoggerProvider.LogMessages, log =>
log.Message.Contains("transport message parsing failed", StringComparison.Ordinal));
}

[Fact]
public async Task SendMessageAsync_Throws_HttpRequestException_With_ResponseBody_On_ErrorStatusCode()
{
Expand Down Expand Up @@ -326,4 +360,4 @@ await session.SendMessageAsync(
// Assert - Total GET requests = 1 initial connection + MaxReconnectionAttempts reconnections.
Assert.Equal(1 + MaxReconnectionAttempts, getRequestCount);
}
}
}
Loading