1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//! Cache hints for list-results under MCP 2026-07-28.
use serde::{Deserialize, Serialize};
/// Suggested scope at which a list-result may be cached.
///
/// Carried alongside `ttl_ms` on list-result structs (tools, prompts,
/// resources, resource templates) under `proto-2026-07-28-rc`. The
/// server announces the scope; the client (or any caching middleware)
/// decides whether to honor it.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
#[non_exhaustive]
pub enum CacheScope {
/// Cache is valid for the lifetime of the MCP session.
Session,
/// Cache is valid for the lifetime of the underlying transport connection.
Connection,
/// Cache is valid for the lifetime of this specific client.
Client,
}
#[cfg(test)]
mod tests {
use super::CacheScope;
use serde_json::json;
#[test]
fn roundtrips_each_variant() {
for (v, s) in [
(CacheScope::Session, "session"),
(CacheScope::Connection, "connection"),
(CacheScope::Client, "client"),
] {
let j = serde_json::to_value(v).unwrap();
assert_eq!(j, json!(s));
let back: CacheScope = serde_json::from_value(j).unwrap();
assert_eq!(back, v);
}
}
}