Skip to main content

agenterra_rmcp/handler/server/wrapper/
json.rs

1use serde::Serialize;
2
3use crate::model::IntoContents;
4
5/// Json wrapper
6///
7/// This is used to tell the SDK to serialize the inner value into json
8pub struct Json<T>(pub T);
9
10impl<T> IntoContents for Json<T>
11where
12    T: Serialize,
13{
14    fn into_contents(self) -> Vec<crate::model::Content> {
15        let result = crate::model::Content::json(self.0);
16        debug_assert!(
17            result.is_ok(),
18            "Json wrapped content should be able to serialized into json"
19        );
20        match result {
21            Ok(content) => vec![content],
22            Err(e) => {
23                tracing::error!("failed to convert json content: {e}");
24                vec![]
25            }
26        }
27    }
28}