refactor: Enforce strict typed JsonSchema for all MCP tools

This commit is contained in:
Riz Ashraf committed 2026-09-12 22:20:01 +01:00
1 parent 686fea683d
commit 2d3aaed289
31 files changed
+2892 -308

No files matched your search

+30 -36
View File
@@ -1,43 +1,37 @@
import re
import sys
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:
main_path = r"C:\Users\reazul.ashraf\workspace\rust\mcp-memory\server\src\main.rs"
with open(main_path, "r", encoding="utf-8") as f:
content = f.read()
# Add the route
route_code = """
.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"}))
}
}))
"""
# Remove WS code
ws_start = content.find('async fn ws_handler')
if ws_start != -1:
content = content[:ws_start]
# Find where to insert it (after /api/tasks)
if ".route(\"/api/tasks/:id/complete\"" not in content:
content = content.replace(
'.route("/api/tasks", get({',
route_code + '\n .route("/api/tasks", get({'
)
# Remove /ws route
route_idx = content.find('.route("/ws", get(ws_handler))')
if route_idx != -1:
content = content.replace('.route("/ws", get(ws_handler))\n ', '')
with open(main_rs_path, "w", encoding="utf-8") as f:
# Remove WS import
import_idx = content.find('use axum::extract::ws::{WebSocketUpgrade, WebSocket, Message};\n')
if import_idx != -1:
content = content.replace('use axum::extract::ws::{WebSocketUpgrade, WebSocket, Message};\n', '')
# Fix GC task state
gc_start = content.find(' // Background Garbage Collection for old tasks')
if gc_start != -1:
content = content.replace('let state_gc = state_clone.clone();', 'let state_gc = Arc::clone(&state);')
# Fix Git task state and CodeChange fields
git_start = content.find(' // Git Native Sync Background Task')
if git_start != -1:
content = content.replace('let state_git = state_clone.clone();', 'let state_git = Arc::clone(&state);')
content = content.replace('commit_hash: current_id.clone(),', 'git_commit: Some(current_id.clone()),')
content = content.replace('branch: branch,', 'git_branch: Some(branch),')
content = content.replace('files_changed: vec![],', 'file_path: "".to_string(),')
with open(main_path, "w", encoding="utf-8") as f:
f.write(content)
print("Injected /api/tasks/:id/complete route successfully.")
print("Cleaned up WS and fixed main.rs")