Skip to main content

boost/tools/
models.rs

1//! `list-models` — dump cast model registrations from inventory.
2//!
3//! Cast registers each `#[derive(Model)]` type via inventory; here we surface
4//! that list to AI agents so they can see which models exist without crawling
5//! the source tree.
6
7use async_trait::async_trait;
8use serde_json::{json, Value};
9
10use crate::protocol::CallToolResult;
11use crate::tool::{Context, Tool};
12
13pub struct ListModels;
14
15#[async_trait]
16impl Tool for ListModels {
17    fn name(&self) -> &'static str {
18        "list-models"
19    }
20    fn description(&self) -> &'static str {
21        "List every cast model registered via `#[derive(Model)]`. Returns table name and Rust struct path."
22    }
23
24    async fn call(&self, _ctx: &Context, _args: Value) -> CallToolResult {
25        // cast_core::model exposes a registry via inventory. If the API isn't
26        // available, we degrade to an empty list and let the agent know.
27        let models = cast_core::registered_models();
28        let payload: Vec<Value> = models
29            .iter()
30            .map(|m| {
31                json!({
32                    "class": m.class,
33                    "table": m.table,
34                })
35            })
36            .collect();
37        CallToolResult::json(&json!({
38            "count": payload.len(),
39            "models": payload,
40        }))
41    }
42}