use uptrakit_shared_macros::wire_safe_enum;
wire_safe_enum! {
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum McpScope {
Read => "mcp:read",
Write => "mcp:write",
}
parse_error = ParseMcpScopeError("invalid mcp scope");
}
impl McpScope {
pub const KNOWN_VARIANTS: &'static [McpScope] = &[McpScope::Read, McpScope::Write];
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn known_variants_round_trip_via_as_str() {
for v in McpScope::KNOWN_VARIANTS {
let s = v.as_str();
let parsed = McpScope::from(s.to_string());
assert_eq!(*v, parsed);
}
}
#[test]
fn unknown_scope_round_trips_via_other() {
let s = "mcp:custom:future";
let scope = McpScope::from(s.to_string());
assert_eq!(scope, McpScope::Other(s.to_string()));
assert_eq!(scope.as_str(), s);
}
#[test]
fn deserialize_infallible_for_unknown_string() {
let json = r#""mcp:future_scope""#;
let scope: McpScope = serde_json::from_str(json).expect("deserialise must succeed");
assert!(matches!(scope, McpScope::Other(_)));
}
}