@@ -136,6 +136,26 @@ public async Task RootsRequest_Fails_WithInvalidOperationException()
136136 Assert . Equal ( "Server to client requests are not supported in stateless mode." , toolContent . Text ) ;
137137 }
138138
139+ [ Fact ]
140+ public async Task ElicitRequest_Fails_WithInvalidOperationException ( )
141+ {
142+ await StartAsync ( ) ;
143+
144+ var mcpClientOptions = new McpClientOptions ( ) ;
145+ mcpClientOptions . Capabilities = new ( ) ;
146+ mcpClientOptions . Capabilities . Elicitation ??= new ( ) ;
147+ mcpClientOptions . Capabilities . Elicitation . ElicitationHandler = ( _ , _ ) =>
148+ {
149+ throw new UnreachableException ( ) ;
150+ } ;
151+
152+ await using var client = await ConnectMcpClientAsync ( mcpClientOptions ) ;
153+
154+ var toolResponse = await client . CallToolAsync ( "testElicitationErrors" , cancellationToken : TestContext . Current . CancellationToken ) ;
155+ var toolContent = Assert . Single ( toolResponse . Content ) ;
156+ Assert . Equal ( "Server to client requests are not supported in stateless mode." , toolContent . Text ) ;
157+ }
158+
139159 [ Fact ]
140160 public async Task UnsolicitedNotification_Fails_WithInvalidOperationException ( )
141161 {
@@ -206,6 +226,21 @@ public static async Task<string> TestRootsErrors(IMcpServer server)
206226 return ex . Message ;
207227 }
208228
229+ [ McpServerTool ( Name = "testElicitationErrors" ) ]
230+ public static async Task < string > TestElicitationErrors ( IMcpServer server )
231+ {
232+ const string expectedElicitationErrorMessage = "Elicitation is not supported in stateless mode." ;
233+
234+ // Even when the client has elicitation support, it should not be advertised in stateless mode.
235+ Assert . Null ( server . ClientCapabilities ) ;
236+
237+ var requestElicitationEx = Assert . Throws < InvalidOperationException > ( ( ) => server . ElicitAsync ( new ( ) ) ) ;
238+ Assert . Equal ( expectedElicitationErrorMessage , requestElicitationEx . Message ) ;
239+
240+ var ex = await Assert . ThrowsAsync < InvalidOperationException > ( ( ) => server . SendRequestAsync ( new JsonRpcRequest { Method = RequestMethods . ElicitationCreate } ) ) ;
241+ return ex . Message ;
242+ }
243+
209244 [ McpServerTool ( Name = "testScope" ) ]
210245 public static string ? TestScope ( ScopedService scopedService ) => scopedService . State ;
211246
0 commit comments