use rust_mcp_sdk::macros::{JsonSchema, mcp_tool};
use rust_mcp_sdk::schema::CallToolResult;
use rust_mcp_sdk::schema::schema_utils::CallToolError;
use serde_json::Value;
use crate::client::ApiClient;
#[mcp_tool(
name = "cancel_run",
description = "Cancel an in-progress workflow execution. Only works on runs that are not yet in a terminal state (pending, running, retrying, awaiting_approval)."
)]
#[derive(Debug, serde::Deserialize, serde::Serialize, JsonSchema)]
pub struct CancelRunTool {
pub run_id: String,
}
impl CancelRunTool {
pub async fn run(&self, client: &ApiClient) -> Result<CallToolResult, CallToolError> {
let path = format!("/runs/{}/cancel", self.run_id);
let result: Value = client
.post_action(&path)
.await
.map_err(CallToolError::new)?;
let text = serde_json::to_string_pretty(&result).map_err(CallToolError::new)?;
Ok(CallToolResult::text_content(vec![text.into()]))
}
}