use rmcp::model::{CallToolResult, ContentBlock, ErrorData, MetaObject};
#[must_use]
pub(crate) fn summary_cursor_conflict(summary: Option<bool>, cursor: Option<&str>) -> bool {
summary == Some(true) && cursor.is_some()
}
#[derive(Debug, Clone, Copy, serde::Serialize)]
#[serde(rename_all = "camelCase")]
struct ErrorMeta {
error_category: &'static str,
is_retryable: bool,
suggested_action: &'static str,
}
#[must_use]
pub(crate) fn error_meta(
category: &'static str,
is_retryable: bool,
suggested_action: &'static str,
) -> serde_json::Value {
serde_json::to_value(ErrorMeta {
error_category: category,
is_retryable,
suggested_action,
})
.unwrap_or_default()
}
#[must_use]
pub(crate) fn err_to_tool_result(e: ErrorData) -> CallToolResult {
let mut result =
CallToolResult::error(vec![ContentBlock::text(e.message)]).with_meta(Some(no_cache_meta()));
if let Some(data) = e.data {
result.structured_content = Some(data);
}
result
}
pub(crate) fn no_cache_meta() -> MetaObject {
let mut m = serde_json::Map::new();
m.insert(
"cache_hint".to_string(),
serde_json::Value::String("no-cache".to_string()),
);
MetaObject(m)
}