@@ -32,23 +32,34 @@ public async Task MapMcp_ThrowsInvalidOperationException_IfWithHttpTransportIsNo
32
32
Assert . StartsWith ( "You must call WithHttpTransport()" , exception . Message ) ;
33
33
}
34
34
35
- [ Fact ]
36
- public async Task Allows_Customizing_Route ( )
35
+ [ Theory ]
36
+ [ InlineData ( "/mcp" ) ]
37
+ [ InlineData ( "/mcp/secondary" ) ]
38
+ public async Task Allows_Customizing_Route ( string pattern )
37
39
{
38
40
Builder . Services . AddMcpServer ( ) . WithHttpTransport ( ) ;
39
41
await using var app = Builder . Build ( ) ;
40
42
41
- app . MapMcp ( "/mcp" ) ;
43
+ app . MapMcp ( pattern ) ;
42
44
43
45
await app . StartAsync ( TestContext . Current . CancellationToken ) ;
44
46
45
- using var response = await HttpClient . GetAsync ( "http://localhost/mcp /sse" , HttpCompletionOption . ResponseHeadersRead , TestContext . Current . CancellationToken ) ;
47
+ using var response = await HttpClient . GetAsync ( $ "http://localhost{ pattern } /sse", HttpCompletionOption . ResponseHeadersRead , TestContext . Current . CancellationToken ) ;
46
48
response . EnsureSuccessStatusCode ( ) ;
49
+ using var sseStream = await response . Content . ReadAsStreamAsync ( TestContext . Current . CancellationToken ) ;
50
+ using var sseStreamReader = new StreamReader ( sseStream , System . Text . Encoding . UTF8 ) ;
51
+ var eventLine = await sseStreamReader . ReadLineAsync ( TestContext . Current . CancellationToken ) ;
52
+ var dataLine = await sseStreamReader . ReadLineAsync ( TestContext . Current . CancellationToken ) ;
53
+ Assert . NotNull ( eventLine ) ;
54
+ Assert . Equal ( "event: endpoint" , eventLine ) ;
55
+ Assert . NotNull ( dataLine ) ;
56
+ Assert . Equal ( $ "data: { pattern } /message", dataLine [ ..dataLine . IndexOf ( '?' ) ] ) ;
47
57
}
48
58
49
59
[ Theory ]
50
60
[ InlineData ( "/a" , "/a/sse" ) ]
51
61
[ InlineData ( "/a/" , "/a/sse" ) ]
62
+ [ InlineData ( "/a/b" , "/a/b/sse" ) ]
52
63
public async Task CanConnect_WithMcpClient_AfterCustomizingRoute ( string routePattern , string requestPath )
53
64
{
54
65
Builder . Services . AddMcpServer ( options =>
0 commit comments