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"});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user