@@ -348,6 +348,10 @@ pub enum ElicitationError {
348
348
/// No response content was provided by the user
349
349
#[ error( "No response content provided" ) ]
350
350
NoContent ,
351
+
352
+ /// Client does not support elicitation capability
353
+ #[ error( "Client does not support elicitation - capability not declared during initialization" ) ]
354
+ CapabilityNotSupported ,
351
355
}
352
356
353
357
impl Peer < RoleServer > {
@@ -367,6 +371,19 @@ impl Peer<RoleServer> {
367
371
// ELICITATION CONVENIENCE METHODS
368
372
// =============================================================================
369
373
374
+ /// Check if the client supports elicitation capability
375
+ ///
376
+ /// Returns true if the client declared elicitation capability during initialization,
377
+ /// false otherwise. According to MCP 2025-06-18 specification, clients that support
378
+ /// elicitation MUST declare the capability during initialization.
379
+ pub fn supports_elicitation ( & self ) -> bool {
380
+ if let Some ( client_info) = self . peer_info ( ) {
381
+ client_info. capabilities . elicitation . is_some ( )
382
+ } else {
383
+ false
384
+ }
385
+ }
386
+
370
387
/// Request structured data from the user using a custom JSON schema.
371
388
///
372
389
/// This is the most flexible elicitation method, allowing you to request
@@ -410,7 +427,12 @@ impl Peer<RoleServer> {
410
427
& self ,
411
428
message : impl Into < String > ,
412
429
schema : & crate :: model:: JsonObject ,
413
- ) -> Result < Option < serde_json:: Value > , ServiceError > {
430
+ ) -> Result < Option < serde_json:: Value > , ElicitationError > {
431
+ // Check if client supports elicitation capability
432
+ if !self . supports_elicitation ( ) {
433
+ return Err ( ElicitationError :: CapabilityNotSupported ) ;
434
+ }
435
+
414
436
let response = self
415
437
. create_elicitation ( CreateElicitationRequestParam {
416
438
message : message. into ( ) ,
@@ -493,6 +515,11 @@ impl Peer<RoleServer> {
493
515
where
494
516
T : schemars:: JsonSchema + for < ' de > serde:: Deserialize < ' de > ,
495
517
{
518
+ // Check if client supports elicitation capability
519
+ if !self . supports_elicitation ( ) {
520
+ return Err ( ElicitationError :: CapabilityNotSupported ) ;
521
+ }
522
+
496
523
// Generate schema automatically from type
497
524
let schema = crate :: handler:: server:: tool:: schema_for_type :: < T > ( ) ;
498
525
0 commit comments