use super::make_tool;
use crate::config::workflows::WorkflowsConfig;
use anyhow::Result;
use rmcp::model::Tool;
use serde_json::{Value, json};
pub fn get_tools() -> Vec<Tool> {
vec![make_tool(
"list_workflows",
"List all available workflows. Returns name + description for each workflow. \
Call BEFORE connecting to discover which workflows exist. \
Use the workflow name with the `connect` tool's `workflow` parameter.",
json!({}),
vec![],
)]
}
pub fn list_workflows(workflows: &WorkflowsConfig) -> Result<Value> {
let mut entries: Vec<Value> = workflows
.named_workflows
.iter()
.map(|(key, config)| {
json!({
"name": key,
"description": config.description.as_deref().unwrap_or(""),
})
})
.collect();
entries.sort_by(|a, b| {
let a_name = a.get("name").and_then(|v| v.as_str()).unwrap_or("");
let b_name = b.get("name").and_then(|v| v.as_str()).unwrap_or("");
a_name.cmp(b_name)
});
Ok(json!({
"count": entries.len(),
"workflows": entries,
}))
}