mod config;
mod server;
use std::error::Error;
use rmcp::transport::stdio;
use rmcp::ServiceExt;
use topodb::Db;
use crate::config::Config;
use crate::server::TopoServer;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let config = Config::from_args(std::env::args().skip(1))?;
if let Some(parent) = config.db_path.parent() {
if !parent.as_os_str().is_empty() && !parent.exists() {
return Err(format!(
"database parent directory does not exist: {}",
parent.display()
)
.into());
}
}
let db = match &config.spec {
Some(spec) => Db::open_with(&config.db_path, spec.clone())?,
None if config.db_path.exists() => Db::open_stored(&config.db_path)?,
None => Db::open_with(&config.db_path, config::default_spec())?,
};
let server = TopoServer::new(db, &config);
let service = server.serve(stdio()).await?;
service.waiting().await?;
Ok(())
}