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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//! Annotations types for the MCP protocol
use serde::{Deserialize, Serialize};
use super::Role;
/// Optional annotations for the client. The client can use annotations to inform how objects are used or displayed.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct Annotations {
/// Describes who the intended customer of this object or data is.
///
/// It can include multiple entries to indicate content useful for multiple audiences (e.g., `["user", "assistant"]`).
#[serde(skip_serializing_if = "Option::is_none")]
pub audience: Option<Vec<Role>>,
/// Describes how important this data is for operating the server.
///
/// A value of 1 means "most important," and indicates that the data is
/// effectively required, while 0 means "least important," and indicates that
/// the data is entirely optional.
#[serde(skip_serializing_if = "Option::is_none")]
pub priority: Option<f64>,
}
impl Annotations {
/// Create new empty annotations
pub fn new() -> Self {
Self::default()
}
/// Create new annotations with audience
pub fn with_audience(audience: Vec<Role>) -> Self {
Self {
audience: Some(audience),
priority: None,
}
}
/// Create new annotations with priority
pub fn with_priority(priority: f64) -> Self {
// Clamp priority between 0 and 1
let priority = priority.max(0.0).min(1.0);
Self {
audience: None,
priority: Some(priority),
}
}
/// Create new annotations with audience and priority
pub fn with_audience_and_priority(audience: Vec<Role>, priority: f64) -> Self {
// Clamp priority between 0 and 1
let priority = priority.max(0.0).min(1.0);
Self {
audience: Some(audience),
priority: Some(priority),
}
}
/// Add an audience role to the annotations
pub fn add_audience(&mut self, role: Role) {
if let Some(audience) = &mut self.audience {
audience.push(role);
} else {
self.audience = Some(vec![role]);
}
}
/// Set the priority of the annotations
pub fn set_priority(&mut self, priority: f64) {
// Clamp priority between 0 and 1
let priority = priority.max(0.0).min(1.0);
self.priority = Some(priority);
}
}