arcature-cli 2026.1.1

Developer lifecycle CLI for Arcature applications.
Documentation
//! `services` tool — the typed service table from the UAG.
//!
//! Returns every service (name + typed dependency names) the UAG carries.
//! Takes no arguments. The UAG content is developer-authored (trusted), so
//! returning all services is not an abuse vector.

use crate::commands::mcp::capability::CapabilitySet;
use crate::commands::mcp::error::McpError;
use crate::commands::mcp::registry::ToolContext;
use serde::Serialize;
use serde_json::Value;

#[derive(Serialize)]
struct ServicesResult<'a> {
    services: &'a [arcature_build::uag::schema::ServiceEntry],
}

pub(crate) fn call(
    _arguments: &Value,
    _capabilities: &CapabilitySet,
    context: &ToolContext,
) -> Result<Value, McpError> {
    let result = ServicesResult {
        services: &context.uag.services,
    };
    serde_json::to_value(result).map_err(McpError::from)
}

#[cfg(test)]
mod tests {
    use super::*;
    use arcature_build::uag::Uag;
    use arcature_build::uag::schema::ServiceEntry;
    use std::collections::BTreeMap;

    fn ctx_with_services() -> ToolContext {
        ToolContext {
            uag: Uag {
                schema_version: 1,
                application: "App".into(),
                framework_version: "2026.1.0".into(),
                modules: BTreeMap::new(),
                routes: vec![],
                services: vec![
                    ServiceEntry {
                        name: "LinkService".into(),
                        deps: vec!["Db".into(), "Cache".into()],
                    },
                    ServiceEntry {
                        name: "MailService".into(),
                        deps: vec![],
                    },
                ],
                pages: vec![],
            },
        }
    }

    #[test]
    fn returns_all_services_with_deps() {
        let ctx = ctx_with_services();
        let value = call(
            &Value::Null,
            &CapabilitySet::from_options(&crate::cli::McpOptions::default()),
            &ctx,
        )
        .expect("ok");
        let arr = value["services"].as_array().expect("array");
        assert_eq!(arr.len(), 2);
        assert_eq!(arr[0]["name"], "LinkService");
        assert_eq!(arr[0]["deps"].as_array().expect("array").len(), 2);
        assert_eq!(arr[1]["deps"].as_array().expect("array").len(), 0);
    }

    #[test]
    fn empty_uag_returns_empty_services() {
        let ctx = ToolContext {
            uag: Uag {
                schema_version: 1,
                application: String::new(),
                framework_version: String::new(),
                modules: BTreeMap::new(),
                routes: vec![],
                services: vec![],
                pages: vec![],
            },
        };
        let value = call(
            &Value::Null,
            &CapabilitySet::from_options(&crate::cli::McpOptions::default()),
            &ctx,
        )
        .expect("ok");
        assert!(value["services"].as_array().expect("array").is_empty());
    }
}