Files
mcp-memory/fix_route.py
T

50 lines
2.0 KiB
Python

import re
main_rs_path = r"C:\Users\reazul.ashraf\workspace\rust\mcp-memory\server\src\main.rs"
with open(main_rs_path, "r", encoding="utf-8") as f:
content = f.read()
# Replace the broken route
old_route = r""" .route("/api/tasks/:id/complete", post({
let state_clone = app_state.handler.state.clone();
move |axum::extract::Path(id): axum::extract::Path<String>| async move {
if let Ok(mut tasks) = state_clone.tasks.write() {
let mut found = false;
for t in tasks.iter_mut() {
if t.id == id {
t.status = "completed".to_string();
found = true;
break;
}
}
if found {
let _ = state_clone.flush_store();
return axum::Json(serde_json::json!({"status": "success"}));
}
}
axum::Json(serde_json::json!({"status": "not_found"}))
}
}))"""
new_route = """ .route("/api/tasks/:id/complete", post({
let state_clone = app_state.handler.state.clone();
move |axum::extract::Path(id): axum::extract::Path<String>| async move {
state_clone.tasks.modify(|tasks| {
for t in tasks.iter_mut() {
if t.id == id {
t.status = "completed".to_string();
break;
}
}
});
axum::Json(serde_json::json!({"status": "success"}))
}
}))"""
content = content.replace(old_route, new_route)
with open(main_rs_path, "w", encoding="utf-8") as f:
f.write(content)
print("Replaced route.")