@@ -18,6 +18,7 @@ use tracing_subscriber::EnvFilter;
1818const TEST_IMAGE_DATA : & str = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==" ;
1919// Small base64-encoded WAV (silence)
2020const TEST_AUDIO_DATA : & str = "UklGRiQAAABXQVZFZm10IBAAAAABAAEARKwAAIhYAQACABAAZGF0YQAAAAA=" ;
21+ const CACHE_TTL_MS : u64 = 60_000 ;
2122
2223/// Helper to convert a serde_json::Value (must be an object) into a JsonObject
2324fn json_object ( v : Value ) -> JsonObject {
@@ -45,7 +46,7 @@ impl ConformanceServer {
4546impl ServerHandler for ConformanceServer {
4647 async fn initialize (
4748 & self ,
48- _request : InitializeRequestParams ,
49+ request : InitializeRequestParams ,
4950 _cx : RequestContext < RoleServer > ,
5051 ) -> Result < InitializeResult , ErrorData > {
5152 Ok ( InitializeResult :: new (
@@ -56,6 +57,7 @@ impl ServerHandler for ConformanceServer {
5657 . enable_logging ( )
5758 . build ( ) ,
5859 )
60+ . with_protocol_version ( request. protocol_version )
5961 . with_server_info ( Implementation :: new ( "rust-conformance-server" , "0.1.0" ) )
6062 . with_instructions ( "Rust MCP conformance test server" ) )
6163 }
@@ -206,7 +208,9 @@ impl ServerHandler for ConformanceServer {
206208 Ok ( ListToolsResult {
207209 tools,
208210 ..Default :: default ( )
209- } )
211+ }
212+ . with_ttl_ms ( CACHE_TTL_MS )
213+ . with_cache_scope ( CacheScope :: Public ) )
210214 }
211215
212216 async fn call_tool (
@@ -549,7 +553,9 @@ impl ServerHandler for ConformanceServer {
549553 . with_mime_type( "image/png" ) ,
550554 ] ,
551555 ..Default :: default ( )
552- } )
556+ }
557+ . with_ttl_ms ( CACHE_TTL_MS )
558+ . with_cache_scope ( CacheScope :: Public ) )
553559 }
554560
555561 async fn read_resource (
@@ -600,7 +606,13 @@ impl ServerHandler for ConformanceServer {
600606 }
601607 }
602608 } ;
603- result. map ( Into :: into)
609+ result
610+ . map ( |result| {
611+ result
612+ . with_ttl_ms ( CACHE_TTL_MS )
613+ . with_cache_scope ( CacheScope :: Public )
614+ } )
615+ . map ( Into :: into)
604616 }
605617
606618 async fn list_resource_templates (
@@ -615,7 +627,9 @@ impl ServerHandler for ConformanceServer {
615627 . with_mime_type( "application/json" ) ,
616628 ] ,
617629 ..Default :: default ( )
618- } )
630+ }
631+ . with_ttl_ms ( CACHE_TTL_MS )
632+ . with_cache_scope ( CacheScope :: Public ) )
619633 }
620634
621635 async fn subscribe (
@@ -674,7 +688,9 @@ impl ServerHandler for ConformanceServer {
674688 ) ,
675689 ] ,
676690 ..Default :: default ( )
677- } )
691+ }
692+ . with_ttl_ms ( CACHE_TTL_MS )
693+ . with_cache_scope ( CacheScope :: Public ) )
678694 }
679695
680696 async fn get_prompt (
@@ -782,7 +798,10 @@ async fn main() -> anyhow::Result<()> {
782798 tracing:: info!( "Starting conformance server on {}" , bind_addr) ;
783799
784800 let server = ConformanceServer :: new ( ) ;
785- let config = StreamableHttpServerConfig :: default ( ) ;
801+ let stateless = std:: env:: var_os ( "STATELESS" ) . is_some ( ) ;
802+ let config = StreamableHttpServerConfig :: default ( )
803+ . with_stateful_mode ( !stateless)
804+ . with_json_response ( stateless) ;
786805 let service = StreamableHttpService :: new (
787806 move || Ok ( server. clone ( ) ) ,
788807 LocalSessionManager :: default ( ) . into ( ) ,
0 commit comments