Skip to content

Commit 28ae9cd

Browse files
committed
PR feedback: Move test to StreamableHttpServerConformanceTests
1 parent f668f65 commit 28ae9cd

File tree

2 files changed

+13
-25
lines changed

2 files changed

+13
-25
lines changed

tests/ModelContextProtocol.AspNetCore.Tests/MapMcpStreamableHttpTests.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -547,29 +547,4 @@ public async Task DisposeAsync_DoesNotHang_WhenOwnsSessionIsFalse_WithUnsolicite
547547
// Dispose should still not hang
548548
await client.DisposeAsync().AsTask().WaitAsync(TimeSpan.FromSeconds(10), TestContext.Current.CancellationToken);
549549
}
550-
551-
[Fact]
552-
public async Task PostWithoutSessionId_NonInitializeRequest_Returns400()
553-
{
554-
Assert.SkipWhen(Stateless, "Stateless mode allows any request without a session ID.");
555-
556-
Builder.Services.AddMcpServer().WithHttpTransport();
557-
558-
await using var app = Builder.Build();
559-
app.MapMcp();
560-
561-
await app.StartAsync(TestContext.Current.CancellationToken);
562-
563-
// Send a tools/call without a session ID. This should be rejected.
564-
HttpClient.DefaultRequestHeaders.Accept.Add(new("application/json"));
565-
HttpClient.DefaultRequestHeaders.Accept.Add(new("text/event-stream"));
566-
567-
var content = new StringContent(
568-
"""{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}""",
569-
System.Text.Encoding.UTF8,
570-
"application/json");
571-
572-
using var response = await HttpClient.PostAsync("http://localhost:5000/", content, TestContext.Current.CancellationToken);
573-
Assert.Equal(System.Net.HttpStatusCode.BadRequest, response.StatusCode);
574-
}
575550
}

tests/ModelContextProtocol.AspNetCore.Tests/StreamableHttpServerConformanceTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,15 @@ public async Task PostRequest_IsNotFound_WithUnrecognizedSessionId()
175175
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
176176
}
177177

178+
[Fact]
179+
public async Task PostWithoutSessionId_NonInitializeRequest_Returns400()
180+
{
181+
await StartAsync();
182+
183+
using var response = await HttpClient.PostAsync("", JsonContent(ListToolsRequest), TestContext.Current.CancellationToken);
184+
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
185+
}
186+
178187
[Fact]
179188
public async Task InitializeRequest_Matches_CustomRoute()
180189
{
@@ -660,6 +669,10 @@ private static async Task<JsonRpcResponse> AssertSingleSseResponseAsync(HttpResp
660669
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"IntegrationTestClient","version":"1.0.0"}}}
661670
""";
662671

672+
private static string ListToolsRequest => """
673+
{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}
674+
""";
675+
663676
private long _lastRequestId = 1;
664677
private string EchoRequest
665678
{

0 commit comments

Comments
 (0)