From bb535b62b0e72afc3e8a7e6e0d63eb04e03da4ab Mon Sep 17 00:00:00 2001 From: Riz Ashraf Date: Sun, 27 Sep 2026 10:10:30 +0100 Subject: [PATCH] Add delete_context_workspace tool --- server/src/handlers/workspaces.rs | 35 +++++++++++++++++++++++++++++++ server/src/router.rs | 1 + server/src/search.rs | 6 ++++-- server/src/tools.rs | 10 +++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/server/src/handlers/workspaces.rs b/server/src/handlers/workspaces.rs index cbac188..930425e 100644 --- a/server/src/handlers/workspaces.rs +++ b/server/src/handlers/workspaces.rs @@ -277,6 +277,41 @@ impl McpTool for ListContextWorkspacesHandler { } } +pub struct DeleteContextWorkspaceHandler; + +#[async_trait] +impl McpTool for DeleteContextWorkspaceHandler { + fn name(&self) -> &'static str { + "delete_context_workspace" + } + + fn schema(&self) -> Value { + crate::mcp::tool_def::( + "delete_context_workspace", + "Delete a saved context workspace", + ) + } + + async fn execute(&self, args: Value, state: Arc) -> Result { + let req: crate::tools::DeleteContextWorkspaceTool = + serde_json::from_value(args).map_err(|e| e.to_string())?; + + let mut found = false; + state.context_workspaces.modify(|ws| { + if let Some(pos) = ws.iter().position(|w| w.namespace == req.namespace && w.name == req.name) { + ws.remove(pos); + found = true; + } + }); + + if found { + Ok("Context workspace deleted successfully".to_string()) + } else { + Err("Context workspace not found".to_string()) + } + } +} + pub struct AddPrChecklistItemHandler; #[async_trait] diff --git a/server/src/router.rs b/server/src/router.rs index c54d6d8..6e533e8 100644 --- a/server/src/router.rs +++ b/server/src/router.rs @@ -97,6 +97,7 @@ impl MemoryHandler { register!(workspaces::SaveContextWorkspaceHandler); register!(workspaces::LoadContextWorkspaceHandler); register!(workspaces::ListContextWorkspacesHandler); + register!(workspaces::DeleteContextWorkspaceHandler); register!(workspaces::AddPrChecklistItemHandler); register!(workspaces::GetPrChecklistHandler); register!(workspaces::ClearPrChecklistHandler); diff --git a/server/src/search.rs b/server/src/search.rs index da69dcb..5fff764 100644 --- a/server/src/search.rs +++ b/server/src/search.rs @@ -249,7 +249,7 @@ impl MemoryIndex { } pub fn delete_all(&self) { - if let Ok(mut writer) = self.writer.lock() { + if let Ok(writer) = self.writer.lock() { let _ = writer.delete_all_documents(); self.needs_commit.store(true, std::sync::atomic::Ordering::SeqCst); } @@ -258,7 +258,7 @@ impl MemoryIndex { pub fn add_task_sync(&self, t: &Task) { println!("add_task_sync called for task: {}", t.id); if let Ok(writer) = self.writer.lock() { - let res = writer.add_document(doc!( + let _res = writer.add_document(doc!( self.id_field => t.id.as_str(), self.title_field => t.title.as_str(), self.body_field => t.description.as_str(), @@ -348,6 +348,8 @@ mod tests { context: "Test context".to_string(), decision: "Test decision".to_string(), consequence: "Test consequence".to_string(), + status: "accepted".to_string(), + supersedes: None, timestamp: 0, }; let _ = index.index_adr(&adr).await.unwrap(); diff --git a/server/src/tools.rs b/server/src/tools.rs index 486b477..0aa1e6b 100644 --- a/server/src/tools.rs +++ b/server/src/tools.rs @@ -547,6 +547,16 @@ pub struct ListContextWorkspacesTool { pub namespace: Option, } +/// Delete a saved context workspace. +#[derive(Debug, Deserialize, Serialize, JsonSchema)] +pub struct DeleteContextWorkspaceTool { + /// The namespace of the workspace. + #[serde(default = "crate::models::default_namespace")] + pub namespace: String, + /// The name of the workspace to delete. + pub name: String, +} + /// Search across all memory stores (Graph, Tasks, Snippets, ADRs, etc.). /// Highly recommended for discovery. Supports Lucene query syntax. #[derive(Debug, Deserialize, Serialize, JsonSchema)]