Skip to content

Plan, apply and roll back changes to a production ontology, with a blast radius report and a proof an auditor can re-check.

feat: add CLI with init and serve commands

FABIOTESSd024d670f822
diff --git a/src/main.rs b/src/main.rs
index 144ad0c3..68b1c9af 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,85 @@
-fn main() {
- println!("open-ontologies");
+use clap::{Parser, Subcommand};
+use rmcp::ServiceExt;
+
+use open_ontologies::config::{expand_tilde, Config};
+use open_ontologies::server::OpenOntologiesServer;
+use open_ontologies::state::StateDb;
+
+const DEFAULT_CONFIG: &str = r#"[general]
+data_dir = "~/.open-ontologies"
+"#;
+
+#[derive(Parser)]
+#[command(name = "open-ontologies", about = "AI-native ontology engine — MCP server")]
+struct Cli {
+ #[command(subcommand)]
+ command: Commands,
+}
+
+#[derive(Subcommand)]
+enum Commands {
+ /// Initialize: create data directory, DB, and default config
+ Init {
+ #[arg(long, default_value = "~/.open-ontologies")]
+ data_dir: String,
+ },
+ /// Start the MCP server
+ Serve {
+ #[arg(long, default_value = "~/.open-ontologies/config.toml")]
+ config: String,
+ },
+}
+
+#[tokio::main]
+async fn main() -> anyhow::Result<()> {
+ let cli = Cli::parse();
+
+ match cli.command {
+ Commands::Init { data_dir } => {
+ let data_dir = expand_tilde(&data_dir);
+ let data_path = std::path::Path::new(&data_dir);
+
+ std::fs::create_dir_all(data_path)?;
+ println!("Created data directory: {data_dir}");
+
+ let db_path = data_path.join("open-ontologies.db");
+ let _db = StateDb::open(&db_path)?;
+ println!("Initialized database: {}", db_path.display());
+
+ let config_path = data_path.join("config.toml");
+ if !config_path.exists() {
+ std::fs::write(&config_path, DEFAULT_CONFIG)?;
+ println!("Created default config: {}", config_path.display());
+ } else {
+ println!("Config already exists: {}", config_path.display());
+ }
+
+ println!("\nOpen Ontologies initialized successfully!");
+ }
+ Commands::Serve { config: config_path } => {
+ let config_path = expand_tilde(&config_path);
+ let cfg = match Config::load(std::path::Path::new(&config_path)) {
+ Ok(c) => c,
+ Err(e) => {
+ let msg = e.to_string();
+ if msg.contains("failed to read") {
+ Config::default()
+ } else {
+ return Err(e);
+ }
+ }
+ };
+ let data_dir = expand_tilde(&cfg.general.data_dir);
+ let db_path = std::path::Path::new(&data_dir).join("open-ontologies.db");
+
+ std::fs::create_dir_all(&data_dir)?;
+ let db = StateDb::open(&db_path)?;
+
+ let server = OpenOntologiesServer::new(db);
+ let service = server.serve(rmcp::transport::stdio()).await?;
+ service.waiting().await?;
+ }
+ }
+
+ Ok(())
}