agentic_workflow_mcp/tools/
registry.rs1use std::sync::Arc;
2use tokio::sync::Mutex;
3
4use agentic_workflow::engine::*;
5use agentic_workflow::resilience::*;
6use agentic_workflow::governance::*;
7use agentic_workflow::template::*;
8use agentic_workflow::intelligence::*;
9
10use crate::types::{ToolDefinition, ToolResult, TOOL_NOT_FOUND};
11
12use super::{
13 dag_tools, execution_tools, schedule_tools, trigger_tools,
14 resilience_tools, governance_tools, processing_tools,
15 state_tools, template_tools, intelligence_tools,
16};
17
18pub struct EngineState {
20 pub dag: DagEngine,
21 pub scheduler: SchedulerEngine,
22 pub trigger: TriggerEngine,
23 pub batch: BatchEngine,
24 pub stream: StreamEngine,
25 pub fanout: FanOutEngine,
26 pub fsm: FsmEngine,
27 pub retry: RetryEngine,
28 pub rollback: RollbackEngine,
29 pub circuit: CircuitBreakerEngine,
30 pub dead_letter: DeadLetterEngine,
31 pub idempotency: IdempotencyEngine,
32 pub approval: ApprovalEngine,
33 pub audit: AuditEngine,
34 pub variable: VariableEngine,
35 pub template: TemplateEngine,
36 pub natural: NaturalLanguageEngine,
37 pub composer: CompositionEngine,
38 pub archaeology: ArchaeologyEngine,
39 pub prediction: PredictionEngine,
40 pub evolution: EvolutionEngine,
41 pub dream: DreamEngine,
42 pub collective: CollectiveEngine,
43}
44
45impl EngineState {
46 pub fn new() -> Self {
47 Self {
48 dag: DagEngine::new(),
49 scheduler: SchedulerEngine::new(),
50 trigger: TriggerEngine::new(),
51 batch: BatchEngine::new(),
52 stream: StreamEngine::new(),
53 fanout: FanOutEngine::new(),
54 fsm: FsmEngine::new(),
55 retry: RetryEngine::new(),
56 rollback: RollbackEngine::new(),
57 circuit: CircuitBreakerEngine::new(),
58 dead_letter: DeadLetterEngine::new(),
59 idempotency: IdempotencyEngine::new(),
60 approval: ApprovalEngine::new(),
61 audit: AuditEngine::new(),
62 variable: VariableEngine::new(),
63 template: TemplateEngine::new(),
64 natural: NaturalLanguageEngine::new(),
65 composer: CompositionEngine::new(),
66 archaeology: ArchaeologyEngine::new(),
67 prediction: PredictionEngine::new(),
68 evolution: EvolutionEngine::new(),
69 dream: DreamEngine::new(),
70 collective: CollectiveEngine::new(),
71 }
72 }
73}
74
75impl Default for EngineState {
76 fn default() -> Self {
77 Self::new()
78 }
79}
80
81pub struct ToolRegistry {
83 state: Arc<Mutex<EngineState>>,
84}
85
86impl ToolRegistry {
87 pub fn new() -> Self {
88 Self {
89 state: Arc::new(Mutex::new(EngineState::new())),
90 }
91 }
92
93 pub fn tool_definitions(&self) -> Vec<ToolDefinition> {
95 let mut tools = Vec::new();
96 tools.extend(dag_tools::definitions());
97 tools.extend(execution_tools::definitions());
98 tools.extend(schedule_tools::definitions());
99 tools.extend(trigger_tools::definitions());
100 tools.extend(resilience_tools::definitions());
101 tools.extend(governance_tools::definitions());
102 tools.extend(processing_tools::definitions());
103 tools.extend(state_tools::definitions());
104 tools.extend(template_tools::definitions());
105 tools.extend(intelligence_tools::definitions());
106 tools
107 }
108
109 pub async fn call_tool(
111 &self,
112 name: &str,
113 params: serde_json::Value,
114 ) -> Result<ToolResult, (i32, String)> {
115 let mut state = self.state.lock().await;
116
117 match name {
118 n if n.starts_with("workflow_create") || n.starts_with("workflow_step_")
120 || n.starts_with("workflow_edge_") || n == "workflow_validate"
121 || n == "workflow_visualize" => {
122 dag_tools::dispatch(n, params, &mut state)
123 }
124
125 n if n == "workflow_run" || n == "workflow_status" || n == "workflow_progress"
127 || n == "workflow_observe" || n == "workflow_pause" || n == "workflow_resume"
128 || n == "workflow_cancel" || n == "workflow_intervene" => {
129 execution_tools::dispatch(n, params, &mut state)
130 }
131
132 n if n.starts_with("workflow_schedule") => {
134 schedule_tools::dispatch(n, params, &mut state)
135 }
136
137 n if n.starts_with("workflow_trigger") => {
139 trigger_tools::dispatch(n, params, &mut state)
140 }
141
142 n if n.starts_with("workflow_retry") || n.starts_with("workflow_rollback")
144 || n.starts_with("workflow_circuit") || n.starts_with("workflow_dead_letter")
145 || n.starts_with("workflow_idempotency") => {
146 resilience_tools::dispatch(n, params, &mut state)
147 }
148
149 n if n.starts_with("workflow_approve") || n.starts_with("workflow_audit")
151 || n.starts_with("workflow_var") => {
152 governance_tools::dispatch(n, params, &mut state)
153 }
154
155 n if n.starts_with("workflow_batch") || n.starts_with("workflow_stream")
157 || n.starts_with("workflow_fanout") => {
158 processing_tools::dispatch(n, params, &mut state)
159 }
160
161 n if n.starts_with("workflow_fsm") => {
163 state_tools::dispatch(n, params, &mut state)
164 }
165
166 n if n.starts_with("workflow_template") || n.starts_with("workflow_natural")
168 || n.starts_with("workflow_compose") || n.starts_with("workflow_collective") => {
169 template_tools::dispatch(n, params, &mut state)
170 }
171
172 n if n.starts_with("workflow_archaeology") || n.starts_with("workflow_predict")
174 || n.starts_with("workflow_evolve") || n.starts_with("workflow_dream") => {
175 intelligence_tools::dispatch(n, params, &mut state)
176 }
177
178 _ => Err((TOOL_NOT_FOUND, format!("Unknown tool: {}", name))),
179 }
180 }
181}
182
183impl Default for ToolRegistry {
184 fn default() -> Self {
185 Self::new()
186 }
187}