From 6d3e233ee27d92f84379297a59a1e53bc0bc3297 Mon Sep 17 00:00:00 2001 From: syui Date: Sun, 1 Mar 2026 19:53:09 +0900 Subject: [PATCH] fix mcp system file --- src/lms/chat.rs | 12 +++++++++++- src/mcp/mod.rs | 14 +++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/lms/chat.rs b/src/lms/chat.rs index 5ab3f38..a7f14b5 100644 --- a/src/lms/chat.rs +++ b/src/lms/chat.rs @@ -70,9 +70,19 @@ fn get_system_prompt() -> String { return prompt; } - // 2. Try CHAT_SYSTEM_FILE env var (path to file) + // 2. Try CHAT_SYSTEM_FILE env var (path to file, supports .json and .md/.txt) if let Ok(file_path) = env::var("CHAT_SYSTEM_FILE") { if let Ok(content) = fs::read_to_string(&file_path) { + // If JSON, extract value.content.text + if file_path.ends_with(".json") { + if let Ok(json) = serde_json::from_str::(&content) { + if let Some(text) = json["value"]["content"]["text"].as_str() { + if !text.is_empty() { + return text.to_string(); + } + } + } + } return content.trim().to_string(); } } diff --git a/src/mcp/mod.rs b/src/mcp/mod.rs index c7b5801..7e90f63 100644 --- a/src/mcp/mod.rs +++ b/src/mcp/mod.rs @@ -344,7 +344,19 @@ fn handle_get_character() -> Result { p } else if let Ok(file_path) = env::var("CHAT_SYSTEM_FILE") { fs::read_to_string(&file_path) - .map(|c| c.trim().to_string()) + .map(|c| { + // If JSON, extract value.content.text + if file_path.ends_with(".json") { + if let Ok(json) = serde_json::from_str::(&c) { + if let Some(text) = json["value"]["content"]["text"].as_str() { + if !text.is_empty() { + return text.to_string(); + } + } + } + } + c.trim().to_string() + }) .unwrap_or_else(|_| "You are a helpful AI assistant.".to_string()) } else { "You are a helpful AI assistant.".to_string()