Skip to content

Commit e489bb2

Browse files
dabasjayantJayant Dabas
andauthored
fix(logs): sanitize strings and print the log message sent by mcp server (#2205)
* sanitize log level and data * ouput server logs to user for transparency and progress tracking * allow notification data to accept both string and json objects * disable notification output to stdout --------- Co-authored-by: Jayant Dabas <[email protected]>
1 parent 264c308 commit e489bb2

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

crates/chat-cli/src/mcp_client/client.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,12 @@ where
379379
let level = params
380380
.as_ref()
381381
.and_then(|p| p.get("level"))
382-
.and_then(|v| serde_json::to_string(v).ok());
383-
let data = params
384-
.as_ref()
385-
.and_then(|p| p.get("data"))
386-
.and_then(|v| serde_json::to_string(v).ok());
382+
.and_then(|v| v.as_str())
383+
.map(|s| s.to_string());
384+
let data = params.as_ref().and_then(|p| p.get("data")).map(|v| match v {
385+
serde_json::Value::String(s) => s.clone(),
386+
_ => serde_json::to_string_pretty(v).unwrap_or_default(),
387+
});
387388
if let (Some(level), Some(data)) = (level, data) {
388389
match level.to_lowercase().as_str() {
389390
"error" => {

0 commit comments

Comments
 (0)