fix mcp system file

This commit is contained in:
2026-03-01 19:53:09 +09:00
parent a46c6d89f0
commit 6d3e233ee2
2 changed files with 24 additions and 2 deletions

View File

@@ -70,9 +70,19 @@ fn get_system_prompt() -> String {
return prompt; 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(file_path) = env::var("CHAT_SYSTEM_FILE") {
if let Ok(content) = fs::read_to_string(&file_path) { 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::<serde_json::Value>(&content) {
if let Some(text) = json["value"]["content"]["text"].as_str() {
if !text.is_empty() {
return text.to_string();
}
}
}
}
return content.trim().to_string(); return content.trim().to_string();
} }
} }

View File

@@ -344,7 +344,19 @@ fn handle_get_character() -> Result<String> {
p p
} else if let Ok(file_path) = env::var("CHAT_SYSTEM_FILE") { } else if let Ok(file_path) = env::var("CHAT_SYSTEM_FILE") {
fs::read_to_string(&file_path) 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::<serde_json::Value>(&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()) .unwrap_or_else(|_| "You are a helpful AI assistant.".to_string())
} else { } else {
"You are a helpful AI assistant.".to_string() "You are a helpful AI assistant.".to_string()