Add delete_context_workspace tool

This commit is contained in:
Riz Ashraf committed 2026-09-27 10:10:30 +01:00
1 parent 0699b603c1
commit bb535b62b0
4 files changed
+50 -2

No files matched your search

+35
View File
@@ -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::<crate::tools::DeleteContextWorkspaceTool>(
"delete_context_workspace",
"Delete a saved context workspace",
)
}
async fn execute(&self, args: Value, state: Arc<MemoryState>) -> Result<String, String> {
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; pub struct AddPrChecklistItemHandler;
#[async_trait] #[async_trait]
+1
View File
@@ -97,6 +97,7 @@ impl MemoryHandler {
register!(workspaces::SaveContextWorkspaceHandler); register!(workspaces::SaveContextWorkspaceHandler);
register!(workspaces::LoadContextWorkspaceHandler); register!(workspaces::LoadContextWorkspaceHandler);
register!(workspaces::ListContextWorkspacesHandler); register!(workspaces::ListContextWorkspacesHandler);
register!(workspaces::DeleteContextWorkspaceHandler);
register!(workspaces::AddPrChecklistItemHandler); register!(workspaces::AddPrChecklistItemHandler);
register!(workspaces::GetPrChecklistHandler); register!(workspaces::GetPrChecklistHandler);
register!(workspaces::ClearPrChecklistHandler); register!(workspaces::ClearPrChecklistHandler);
+4 -2
View File
@@ -249,7 +249,7 @@ impl MemoryIndex {
} }
pub fn delete_all(&self) { 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(); let _ = writer.delete_all_documents();
self.needs_commit.store(true, std::sync::atomic::Ordering::SeqCst); self.needs_commit.store(true, std::sync::atomic::Ordering::SeqCst);
} }
@@ -258,7 +258,7 @@ impl MemoryIndex {
pub fn add_task_sync(&self, t: &Task) { pub fn add_task_sync(&self, t: &Task) {
println!("add_task_sync called for task: {}", t.id); println!("add_task_sync called for task: {}", t.id);
if let Ok(writer) = self.writer.lock() { 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.id_field => t.id.as_str(),
self.title_field => t.title.as_str(), self.title_field => t.title.as_str(),
self.body_field => t.description.as_str(), self.body_field => t.description.as_str(),
@@ -348,6 +348,8 @@ mod tests {
context: "Test context".to_string(), context: "Test context".to_string(),
decision: "Test decision".to_string(), decision: "Test decision".to_string(),
consequence: "Test consequence".to_string(), consequence: "Test consequence".to_string(),
status: "accepted".to_string(),
supersedes: None,
timestamp: 0, timestamp: 0,
}; };
let _ = index.index_adr(&adr).await.unwrap(); let _ = index.index_adr(&adr).await.unwrap();
+10
View File
@@ -547,6 +547,16 @@ pub struct ListContextWorkspacesTool {
pub namespace: Option<String>, pub namespace: Option<String>,
} }
/// 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.). /// Search across all memory stores (Graph, Tasks, Snippets, ADRs, etc.).
/// Highly recommended for discovery. Supports Lucene query syntax. /// Highly recommended for discovery. Supports Lucene query syntax.
#[derive(Debug, Deserialize, Serialize, JsonSchema)] #[derive(Debug, Deserialize, Serialize, JsonSchema)]