feat: Add dynamic output dialect formatting (XML/Markdown) via MCP configuration
This commit is contained in:
1 parent
ffb316a6e3
commit
faf4532992
2 files changed
+24
-2
No files matched your search
+22
-2
@@ -573,6 +573,21 @@ impl MemoryHandler {
|
||||
Some(crate::mcp::success(id, payload))
|
||||
}
|
||||
"initialize" => {
|
||||
if let Some(params) = req.get("params") {
|
||||
if let Some(client_info) = params.get("clientInfo") {
|
||||
if let Some(name) = client_info.get("name").and_then(|n| n.as_str()) {
|
||||
let dialect = if name.to_lowercase().contains("claude") {
|
||||
"xml".to_string()
|
||||
} else {
|
||||
"markdown".to_string()
|
||||
};
|
||||
if let Ok(mut write_guard) = self.state.dialect.write() {
|
||||
*write_guard = dialect;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let init = rmcp::model::InitializeResult::new(
|
||||
rmcp::model::ServerCapabilities::builder()
|
||||
.enable_tools()
|
||||
@@ -765,10 +780,15 @@ impl MemoryHandler {
|
||||
|
||||
match result {
|
||||
Ok(text) => {
|
||||
let mut content_obj = serde_json::json!({"type": "text", "text": &text});
|
||||
let formatted_text = match self.state.dialect.read().map(|d| d.clone()) {
|
||||
Ok(d) if d == "xml" => format!("<tool_output>\n{}\n</tool_output>", text),
|
||||
_ => text.clone(),
|
||||
};
|
||||
|
||||
let mut content_obj = serde_json::json!({"type": "text", "text": &formatted_text});
|
||||
|
||||
// Heuristic: If response is large (e.g. > 4000 chars), inject cache_control for Prompt Caching
|
||||
if text.len() > 4000 {
|
||||
if formatted_text.len() > 4000 {
|
||||
content_obj["cacheControl"] = serde_json::json!({"type": "ephemeral"});
|
||||
}
|
||||
|
||||
|
||||
@@ -133,6 +133,7 @@ pub struct MemoryState {
|
||||
pub event_bus_tx: tokio::sync::broadcast::Sender<GenericEvent>,
|
||||
pub ollama: Arc<crate::ollama::OllamaClient>,
|
||||
pub clipboard_cache: Arc<tokio::sync::RwLock<ClipboardCacheState>>,
|
||||
pub dialect: std::sync::RwLock<String>,
|
||||
}
|
||||
|
||||
impl MemoryState {
|
||||
@@ -206,6 +207,7 @@ impl MemoryState {
|
||||
activity_tx: tokio::sync::broadcast::channel(100).0,
|
||||
event_bus_tx: tokio::sync::broadcast::channel(1000).0,
|
||||
clipboard_cache: Arc::new(tokio::sync::RwLock::new(ClipboardCacheState::default())),
|
||||
dialect: std::sync::RwLock::new("markdown".to_string()),
|
||||
};
|
||||
|
||||
// Normalize pre-existing graph entity and relation types
|
||||
|
||||
Reference in new issue
Block a user