@@ -1342,14 +1342,15 @@ impl Peer<RoleClient> {
13421342 let result = match result {
13431343 Ok ( result) => result,
13441344 Err ( error) => {
1345+ if uses_cursor {
1346+ self . invalidate_prompt_cache ( ) . await ;
1347+ return Err ( error) ;
1348+ }
13451349 if let Some ( ServerResult :: ListPromptsResult ( result) ) =
13461350 self . stale_cached_response ( & cache_key) . await
13471351 {
13481352 return Ok ( result) ;
13491353 }
1350- if uses_cursor {
1351- self . invalidate_prompt_cache ( ) . await ;
1352- }
13531354 return Err ( error) ;
13541355 }
13551356 } ;
@@ -1391,15 +1392,16 @@ impl Peer<RoleClient> {
13911392 let result = match result {
13921393 Ok ( result) => result,
13931394 Err ( error) => {
1395+ if uses_cursor {
1396+ self . invalidate_cached_responses ( RESOURCE_LIST_CACHE_PREFIX )
1397+ . await ;
1398+ return Err ( error) ;
1399+ }
13941400 if let Some ( ServerResult :: ListResourcesResult ( result) ) =
13951401 self . stale_cached_response ( & cache_key) . await
13961402 {
13971403 return Ok ( result) ;
13981404 }
1399- if uses_cursor {
1400- self . invalidate_cached_responses ( RESOURCE_LIST_CACHE_PREFIX )
1401- . await ;
1402- }
14031405 return Err ( error) ;
14041406 }
14051407 } ;
@@ -1443,15 +1445,16 @@ impl Peer<RoleClient> {
14431445 let result = match result {
14441446 Ok ( result) => result,
14451447 Err ( error) => {
1448+ if uses_cursor {
1449+ self . invalidate_cached_responses ( RESOURCE_TEMPLATE_LIST_CACHE_PREFIX )
1450+ . await ;
1451+ return Err ( error) ;
1452+ }
14461453 if let Some ( ServerResult :: ListResourceTemplatesResult ( result) ) =
14471454 self . stale_cached_response ( & cache_key) . await
14481455 {
14491456 return Ok ( result) ;
14501457 }
1451- if uses_cursor {
1452- self . invalidate_cached_responses ( RESOURCE_TEMPLATE_LIST_CACHE_PREFIX )
1453- . await ;
1454- }
14551458 return Err ( error) ;
14561459 }
14571460 } ;
@@ -1502,14 +1505,15 @@ impl Peer<RoleClient> {
15021505 let result = match result {
15031506 Ok ( result) => result,
15041507 Err ( error) => {
1508+ if uses_cursor {
1509+ self . invalidate_tool_cache ( ) . await ;
1510+ return Err ( error) ;
1511+ }
15051512 if let Some ( ServerResult :: ListToolsResult ( result) ) =
15061513 self . stale_cached_response ( & cache_key) . await
15071514 {
15081515 return Ok ( result) ;
15091516 }
1510- if uses_cursor {
1511- self . invalidate_tool_cache ( ) . await ;
1512- }
15131517 return Err ( error) ;
15141518 }
15151519 } ;
@@ -2064,21 +2068,30 @@ mod tests {
20642068 }
20652069
20662070 #[ tokio:: test]
2067- async fn private_entries_are_isolated_between_client_peers ( ) {
2068- let first = disconnected_peer ( ) ;
2069- let second = disconnected_peer ( ) ;
2071+ async fn private_entries_are_isolated_between_authorization_partitions ( ) {
2072+ let peer = disconnected_peer ( ) ;
20702073 let key = list_response_cache_key ( TOOL_LIST_CACHE_PREFIX , & None ) ;
2071- first
2072- . cache_response (
2073- key. clone ( ) ,
2074- ServerResult :: ListToolsResult ( tools_result ( Some ( 5_000 ) , Some ( CacheScope :: Private ) ) ) ,
2075- Some ( 5_000 ) ,
2076- Some ( CacheScope :: Private ) ,
2077- )
2078- . await ;
20792074
2080- assert ! ( first. cached_response( & key) . await . is_some( ) ) ;
2081- assert ! ( second. cached_response( & key) . await . is_none( ) ) ;
2075+ peer. set_response_cache_config (
2076+ ClientCacheConfig :: default ( ) . with_private_partition ( "auth-a" ) ,
2077+ )
2078+ . await ;
2079+ peer. cache_response (
2080+ key. clone ( ) ,
2081+ ServerResult :: ListToolsResult ( tools_result ( Some ( 5_000 ) , Some ( CacheScope :: Private ) ) ) ,
2082+ Some ( 5_000 ) ,
2083+ Some ( CacheScope :: Private ) ,
2084+ )
2085+ . await ;
2086+ assert ! ( peer. cached_response( & key) . await . is_some( ) ) ;
2087+
2088+ // Switching to a different authorization context must not expose the
2089+ // first partition's private entry.
2090+ peer. set_response_cache_config (
2091+ ClientCacheConfig :: default ( ) . with_private_partition ( "auth-b" ) ,
2092+ )
2093+ . await ;
2094+ assert ! ( peer. cached_response( & key) . await . is_none( ) ) ;
20822095 }
20832096
20842097 #[ tokio:: test]
0 commit comments