hoosh 1.3.0

AI inference gateway — multi-provider LLM routing, local model serving, speech-to-text, and token budget management
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
//! MCP bridge — wraps bote's Dispatcher + szal's built-in tools for direct
//! tool invocation via /v1/tools/list and /v1/tools/call endpoints.
//!
//! Extended integrations (feature-gated):
//! - `tools-audit`: Tamper-proof tool call logging via libro audit chain
//! - `tools-events`: Tool lifecycle events via majra pub/sub
//! - `tools-discovery`: Cross-node tool announcement and discovery
//! - `tools-sandbox`: Kavach-sandboxed tool execution

use std::sync::Arc;

use bote::{Dispatcher, JsonRpcRequest, JsonRpcResponse};

/// MCP tool bridge backed by bote protocol dispatch and szal built-in tools,
/// plus hoosh's own workflow-as-tool.
pub struct McpBridge {
    dispatcher: Dispatcher,
    /// Tracks active workflow cancellation tokens by execution ID.
    cancellation_tokens:
        std::sync::RwLock<std::collections::HashMap<String, tokio_util::sync::CancellationToken>>,
    /// Execution store for workflow persistence.
    execution_store: Arc<szal::storage::InMemoryExecutionStore>,
    /// Workflow storage for sub-flow composition.
    workflow_storage: Arc<szal::storage::InMemoryStorage>,
    /// Discovery service for multi-node tool sharing.
    #[cfg(feature = "tools-discovery")]
    discovery: Option<bote::discovery::DiscoveryService>,
}

impl McpBridge {
    const MAX_ACTIVE_WORKFLOWS: usize = 1024;
    const MAX_WORKFLOW_TEMPLATES: usize = 256;

    /// Create a new bridge with szal's built-in tools + workflow-as-tool.
    ///
    /// Wires up audit, events, discovery, and sandbox integrations
    /// based on compile-time feature flags.
    pub fn new() -> Self {
        // Build audit sink (feature: tools-audit)
        #[cfg(feature = "tools-audit")]
        let audit: Option<Arc<dyn bote::AuditSink>> = Some(Arc::new(
            bote::audit::LibroAudit::new()
                .with_source("hoosh")
                .with_agent_id("hoosh-mcp"),
        ));
        #[cfg(not(feature = "tools-audit"))]
        let audit: Option<Arc<dyn bote::AuditSink>> = None;

        // Build event sink (feature: tools-events)
        #[cfg(feature = "tools-events")]
        let events: Option<Arc<dyn bote::EventSink>> =
            Some(Arc::new(bote::events::MajraEvents::new()));
        #[cfg(not(feature = "tools-events"))]
        let events: Option<Arc<dyn bote::EventSink>> = None;

        // Register szal tools with audit + events sinks
        let dispatcher = szal::mcp::register_tools_with(audit, events.clone());

        // Build discovery service (feature: tools-discovery)
        #[cfg(feature = "tools-discovery")]
        let discovery = events.clone().map(|ev| {
            let node_id = format!("hoosh-{}", uuid::Uuid::new_v4());
            tracing::info!(node_id = %node_id, "tool discovery service initialized");
            bote::discovery::DiscoveryService::new(node_id, ev)
        });

        Self {
            dispatcher,
            cancellation_tokens: std::sync::RwLock::new(std::collections::HashMap::new()),
            execution_store: Arc::new(szal::storage::InMemoryExecutionStore::new()),
            workflow_storage: Arc::new(szal::storage::InMemoryStorage::new()),
            #[cfg(feature = "tools-discovery")]
            discovery,
        }
    }

    /// List all registered tools as a JSON value.
    pub fn list_tools(&self) -> serde_json::Value {
        let request = JsonRpcRequest::new(1, "tools/list");
        let mut result = match self.dispatcher.dispatch(&request) {
            Some(resp) if resp.error.is_none() => {
                resp.result.unwrap_or(serde_json::json!({"tools": []}))
            }
            Some(resp) => serde_json::json!({
                "error": resp.error.map(|e| e.message).unwrap_or_default()
            }),
            None => serde_json::json!({"tools": []}),
        };

        // Append hoosh-registered tools
        if let Some(tools) = result["tools"].as_array_mut() {
            tools.push(serde_json::json!({
                "name": "szal_workflow_run",
                "description": "Execute a szal workflow (sequential/parallel/DAG/hierarchical steps with retry, rollback, conditions, and cancellation)",
                "inputSchema": {
                    "type": "object",
                    "properties": {
                        "flow": {"type": "object", "description": "Flow definition with name, mode (Sequential/Parallel/Dag/Hierarchical), and steps"},
                        "max_concurrency": {"type": "integer", "description": "Max parallel steps (default: 16)", "default": 16}
                    },
                    "required": ["flow"]
                }
            }));
            tools.push(serde_json::json!({
                "name": "szal_workflow_cancel",
                "description": "Cancel a running workflow by execution ID",
                "inputSchema": {
                    "type": "object",
                    "properties": {
                        "execution_id": {"type": "string", "description": "Execution ID to cancel"}
                    },
                    "required": ["execution_id"]
                }
            }));
            tools.push(serde_json::json!({
                "name": "szal_workflow_status",
                "description": "Get workflow execution status and history",
                "inputSchema": {
                    "type": "object",
                    "properties": {
                        "execution_id": {"type": "string", "description": "Specific execution ID (optional)"},
                        "flow_name": {"type": "string", "description": "Filter by flow name (optional)"}
                    }
                }
            }));
            tools.push(serde_json::json!({
                "name": "szal_workflow_register",
                "description": "Register a reusable workflow template for sub-flow composition",
                "inputSchema": {
                    "type": "object",
                    "properties": {
                        "flow": {"type": "object", "description": "Flow definition to register as a template"}
                    },
                    "required": ["flow"]
                }
            }));
        }

        result
    }

    /// Call a tool by name with the given arguments.
    pub fn call_tool(&self, name: &str, arguments: serde_json::Value) -> (serde_json::Value, bool) {
        // Handle hoosh-registered tools first
        match name {
            "szal_workflow_run" => return self.run_workflow(arguments),
            "szal_workflow_cancel" => return self.cancel_workflow(arguments),
            "szal_workflow_status" => return self.workflow_status(arguments),
            "szal_workflow_register" => return self.register_workflow(arguments),
            _ => {}
        }

        // Sandbox wrapping for external tools (feature: tools-sandbox)
        #[cfg(feature = "tools-sandbox")]
        if let Some(real_name) = name.strip_prefix("sandbox:") {
            return self.call_sandboxed(real_name, arguments);
        }

        let request = JsonRpcRequest::new(1, "tools/call").with_params(serde_json::json!({
            "name": name,
            "arguments": arguments,
        }));

        match self.dispatcher.dispatch(&request) {
            Some(resp) => response_to_result(resp),
            None => (
                serde_json::json!({"error": "no response from dispatcher"}),
                true,
            ),
        }
    }

    /// Number of registered tools.
    pub fn tool_count(&self) -> usize {
        let list = self.list_tools();
        list["tools"].as_array().map(|a| a.len()).unwrap_or(0)
    }

    /// Dynamically register a tool at runtime.
    pub fn register_tool(
        &self,
        name: &str,
        description: &str,
        handler: bote::dispatch::ToolHandler,
    ) -> bool {
        tracing::info!(tool = name, "dynamically registering tool");
        self.dispatcher
            .register_tool(
                bote::ToolDef::new(
                    name,
                    description,
                    bote::ToolSchema::new("object", std::collections::HashMap::new(), vec![]),
                ),
                handler,
            )
            .is_ok()
    }

    /// Dynamically deregister a tool at runtime.
    pub fn deregister_tool(&self, name: &str) -> bool {
        tracing::info!(tool = name, "deregistering tool");
        self.dispatcher.deregister_tool(name).is_ok()
    }

    /// Announce this node's tools to the discovery mesh.
    #[cfg(feature = "tools-discovery")]
    pub fn announce_tools(&self) {
        if let Some(discovery) = &self.discovery {
            let list = self.list_tools();
            let tools: Vec<bote::ToolDef> = list["tools"]
                .as_array()
                .map(|arr| {
                    arr.iter()
                        .filter_map(|t| serde_json::from_value(t.clone()).ok())
                        .collect()
                })
                .unwrap_or_default();
            discovery.announce(&tools);
        }
    }

    // ─── Workflow execution ─────────────────────────────────────────────

    /// Execute a szal workflow with full feature integration:
    /// - DAG/Parallel/Sequential/Hierarchical modes
    /// - Condition DSL on steps
    /// - Cancellation token tracking
    /// - Execution persistence
    /// - Step-type metrics to Prometheus
    /// - Sub-flow composition via workflow storage
    fn run_workflow(&self, args: serde_json::Value) -> (serde_json::Value, bool) {
        let flow_json = &args["flow"];
        let flow_def: szal::flow::FlowDef = match serde_json::from_value(flow_json.clone()) {
            Ok(f) => f,
            Err(e) => {
                return (
                    serde_json::json!({"error": format!("invalid flow: {e}")}),
                    true,
                );
            }
        };

        if let Err(e) = flow_def.validate() {
            return (
                serde_json::json!({"error": format!("flow validation failed: {e}")}),
                true,
            );
        }

        if flow_def.steps.is_empty() {
            return (
                serde_json::json!({"error": "flow must contain at least one step"}),
                true,
            );
        }

        let max_concurrency = match args["max_concurrency"].as_u64() {
            Some(v) if v == 0 || v > 1024 => {
                return (
                    serde_json::json!({"error": "max_concurrency must be 1-1024"}),
                    true,
                );
            }
            Some(v) => v as usize,
            None => 16,
        };

        // Guard against unbounded active workflow growth
        {
            let tokens = self
                .cancellation_tokens
                .read()
                .unwrap_or_else(|e| e.into_inner());
            if tokens.len() >= Self::MAX_ACTIVE_WORKFLOWS {
                return (
                    serde_json::json!({"error": "too many active workflows"}),
                    true,
                );
            }
        }

        // Build engine config with execution store and step-type metrics
        let config = szal::engine::EngineConfig {
            max_concurrency,
            execution_store: Some(self.execution_store.clone()),
            step_type_metrics: Some(Arc::new(|step_type, status, duration_ms| {
                crate::metrics::record_workflow_step(step_type, status, duration_ms);
            })),
            ..Default::default()
        };

        // Sub-flow handler wrapping the base handler
        let base_handler = szal::engine::handler_fn(|step| async move {
            Ok(serde_json::json!({"step": step.name, "status": "completed"}))
        });
        let handler = szal::engine::sub_flow_handler(self.workflow_storage.clone(), base_handler);

        let engine = szal::engine::Engine::new(config, handler);

        // Unique execution ID per invocation (avoids collision on reused flow_def.id)
        let execution_id = uuid::Uuid::new_v4().to_string();

        // Create cancellation token and track it
        let token = szal::engine::CancellationToken::new();
        {
            let mut tokens = self
                .cancellation_tokens
                .write()
                .unwrap_or_else(|e| e.into_inner());
            tokens.insert(execution_id.clone(), token.clone());
        }

        let rt = tokio::runtime::Handle::current();
        let result = rt.block_on(engine.run_with_cancellation(&flow_def, token));

        // Always clean up cancellation token
        {
            let mut tokens = self
                .cancellation_tokens
                .write()
                .unwrap_or_else(|e| e.into_inner());
            tokens.remove(&execution_id);
        }

        match result {
            Ok(result) => (
                serde_json::json!({
                    "execution_id": execution_id,
                    "success": result.success,
                    "flow": result.flow_name,
                    "completed": result.completed_count(),
                    "failed": result.failed_count(),
                    "skipped": result.skipped_count(),
                    "duration_ms": result.total_duration_ms,
                    "rolled_back": result.rolled_back,
                }),
                false,
            ),
            Err(e) => (
                serde_json::json!({
                    "execution_id": execution_id,
                    "error": format!("workflow failed: {e}"),
                }),
                true,
            ),
        }
    }

    /// Cancel a running workflow by execution ID.
    fn cancel_workflow(&self, args: serde_json::Value) -> (serde_json::Value, bool) {
        let execution_id = match args["execution_id"].as_str() {
            Some(id) => id,
            None => return (serde_json::json!({"error": "missing execution_id"}), true),
        };

        let tokens = self
            .cancellation_tokens
            .read()
            .unwrap_or_else(|e| e.into_inner());
        if let Some(token) = tokens.get(execution_id) {
            token.cancel();
            tracing::info!(execution_id, "workflow cancellation requested");
            (
                serde_json::json!({"cancelled": true, "execution_id": execution_id}),
                false,
            )
        } else {
            (
                serde_json::json!({"error": "execution not found or already completed"}),
                true,
            )
        }
    }

    /// Get workflow execution status from the execution store.
    fn workflow_status(&self, args: serde_json::Value) -> (serde_json::Value, bool) {
        use szal::storage::ExecutionStore;

        if let Some(execution_id) = args["execution_id"].as_str() {
            match self.execution_store.get(execution_id) {
                Some(record) => (serde_json::to_value(&record).unwrap_or_default(), false),
                None => (serde_json::json!({"error": "execution not found"}), true),
            }
        } else {
            let flow_name = args["flow_name"].as_str();
            let ids = self.execution_store.list(flow_name);
            let records: Vec<serde_json::Value> = ids
                .iter()
                .filter_map(|id| self.execution_store.get(id))
                .map(|r| serde_json::to_value(&r).unwrap_or_default())
                .collect();
            (serde_json::json!({"executions": records}), false)
        }
    }

    /// Register a reusable workflow template.
    fn register_workflow(&self, args: serde_json::Value) -> (serde_json::Value, bool) {
        let flow_json = &args["flow"];
        let flow_def: szal::flow::FlowDef = match serde_json::from_value(flow_json.clone()) {
            Ok(f) => f,
            Err(e) => {
                return (
                    serde_json::json!({"error": format!("invalid flow: {e}")}),
                    true,
                );
            }
        };

        if let Err(e) = flow_def.validate() {
            return (
                serde_json::json!({"error": format!("flow validation failed: {e}")}),
                true,
            );
        }

        // Guard against unbounded template growth
        use szal::storage::WorkflowStorage;
        if self.workflow_storage.list().len() >= Self::MAX_WORKFLOW_TEMPLATES {
            return (
                serde_json::json!({"error": "too many registered workflow templates"}),
                true,
            );
        }

        let name = flow_def.name.clone();
        self.workflow_storage.insert(flow_def);
        tracing::info!(flow = %name, "workflow template registered");
        (
            serde_json::json!({"registered": true, "flow_name": name}),
            false,
        )
    }

    /// Execute a tool in a sandbox (feature: tools-sandbox).
    #[cfg(feature = "tools-sandbox")]
    fn call_sandboxed(
        &self,
        name: &str,
        arguments: serde_json::Value,
    ) -> (serde_json::Value, bool) {
        let config = bote::sandbox::ToolSandboxConfig::basic();
        let handler = bote::sandbox::wrap_command(name, config);
        let result = handler(arguments);
        let is_error = result.get("error").is_some();
        (result, is_error)
    }
}

impl Default for McpBridge {
    fn default() -> Self {
        Self::new()
    }
}

/// Convert a JSON-RPC response to (result_value, is_error).
fn response_to_result(resp: JsonRpcResponse) -> (serde_json::Value, bool) {
    if let Some(err) = resp.error {
        (serde_json::json!({"error": err.message}), true)
    } else {
        (resp.result.unwrap_or(serde_json::Value::Null), false)
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn bridge_creation() {
        let bridge = McpBridge::new();
        assert!(bridge.tool_count() > 0);
    }

    #[test]
    fn list_tools_returns_array() {
        let bridge = McpBridge::new();
        let list = bridge.list_tools();
        assert!(list["tools"].is_array());
        assert!(!list["tools"].as_array().unwrap().is_empty());
    }

    #[test]
    fn list_tools_includes_workflow_tools() {
        let bridge = McpBridge::new();
        let list = bridge.list_tools();
        let tools = list["tools"].as_array().unwrap();
        let names: Vec<&str> = tools.iter().filter_map(|t| t["name"].as_str()).collect();
        assert!(names.contains(&"szal_workflow_run"));
        assert!(names.contains(&"szal_workflow_cancel"));
        assert!(names.contains(&"szal_workflow_status"));
        assert!(names.contains(&"szal_workflow_register"));
    }

    // szal tools use Handle::current().block_on() internally,
    // so these must run within a multi-thread tokio runtime.
    #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
    async fn call_uuid() {
        let bridge = McpBridge::new();
        let (result, is_error) = tokio::task::spawn_blocking(move || {
            bridge.call_tool("szal_uuid", serde_json::json!({}))
        })
        .await
        .unwrap();
        assert!(!is_error, "szal_uuid should succeed: {result}");
    }

    #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
    async fn call_timestamp() {
        let bridge = McpBridge::new();
        let (result, is_error) = tokio::task::spawn_blocking(move || {
            bridge.call_tool("szal_timestamp", serde_json::json!({}))
        })
        .await
        .unwrap();
        assert!(!is_error, "szal_timestamp should succeed: {result}");
    }

    #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
    async fn call_unknown_tool() {
        let bridge = McpBridge::new();
        let (_, is_error) = tokio::task::spawn_blocking(move || {
            bridge.call_tool("nonexistent_tool", serde_json::json!({}))
        })
        .await
        .unwrap();
        assert!(is_error);
    }

    #[test]
    fn default_impl() {
        let bridge = McpBridge::default();
        assert!(bridge.tool_count() > 0);
    }

    #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
    async fn call_workflow_run() {
        let bridge = McpBridge::new();
        let mut flow_def = szal::flow::FlowDef::new("test-flow", szal::flow::FlowMode::Sequential);
        flow_def.steps.push(szal::step::StepDef::new("step-1"));
        flow_def.steps.push(szal::step::StepDef::new("step-2"));
        let flow = serde_json::to_value(&flow_def).unwrap();
        let (result, is_error) = tokio::task::spawn_blocking(move || {
            bridge.call_tool("szal_workflow_run", serde_json::json!({"flow": flow}))
        })
        .await
        .unwrap();
        assert!(!is_error, "workflow should succeed: {result}");
        assert_eq!(result["success"], true);
        assert_eq!(result["completed"], 2);
        assert_eq!(result["failed"], 0);
        assert!(result["execution_id"].as_str().is_some());
    }

    #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
    async fn call_workflow_dag_mode() {
        let bridge = McpBridge::new();
        let mut flow = szal::flow::FlowDef::new("dag-flow", szal::flow::FlowMode::Dag);
        flow.steps.push(szal::step::StepDef::new("a"));
        flow.steps.push(szal::step::StepDef::new("b"));
        let flow_json = serde_json::to_value(&flow).unwrap();
        let (result, is_error) = tokio::task::spawn_blocking(move || {
            bridge.call_tool("szal_workflow_run", serde_json::json!({"flow": flow_json}))
        })
        .await
        .unwrap();
        assert!(!is_error, "DAG workflow should succeed: {result}");
        assert_eq!(result["success"], true);
    }

    #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
    async fn call_workflow_invalid_flow() {
        let bridge = McpBridge::new();
        let (result, _) = tokio::task::spawn_blocking(move || {
            bridge.call_tool(
                "szal_workflow_run",
                serde_json::json!({"flow": "not an object"}),
            )
        })
        .await
        .unwrap();
        assert!(result["error"].as_str().unwrap().contains("invalid flow"));
    }

    #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
    async fn workflow_cancel_nonexistent() {
        let bridge = McpBridge::new();
        let (result, is_error) = tokio::task::spawn_blocking(move || {
            bridge.call_tool(
                "szal_workflow_cancel",
                serde_json::json!({"execution_id": "nonexistent"}),
            )
        })
        .await
        .unwrap();
        assert!(is_error);
        assert!(result["error"].as_str().unwrap().contains("not found"));
    }

    #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
    async fn workflow_status_empty() {
        let bridge = McpBridge::new();
        let (result, is_error) = tokio::task::spawn_blocking(move || {
            bridge.call_tool("szal_workflow_status", serde_json::json!({}))
        })
        .await
        .unwrap();
        assert!(!is_error);
        assert!(result["executions"].is_array());
    }

    #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
    async fn workflow_register_and_status() {
        let bridge = McpBridge::new();
        let mut flow = szal::flow::FlowDef::new("template-1", szal::flow::FlowMode::Sequential);
        flow.steps.push(szal::step::StepDef::new("s1"));
        let flow_json = serde_json::to_value(&flow).unwrap();
        let (result, is_error) = tokio::task::spawn_blocking(move || {
            bridge.call_tool(
                "szal_workflow_register",
                serde_json::json!({"flow": flow_json}),
            )
        })
        .await
        .unwrap();
        assert!(!is_error);
        assert_eq!(result["registered"], true);
        assert_eq!(result["flow_name"], "template-1");
    }

    #[test]
    fn dynamic_tool_registration() {
        let bridge = McpBridge::new();
        let initial = bridge.tool_count();
        bridge.register_tool(
            "hoosh_test_tool",
            "test tool",
            Arc::new(|_| serde_json::json!({"ok": true})),
        );
        assert_eq!(bridge.tool_count(), initial + 1);

        assert!(bridge.deregister_tool("hoosh_test_tool"));
        assert_eq!(bridge.tool_count(), initial);
    }
}