Skip to main content

org_mcp_server/
core.rs

1use std::{error, sync::Arc};
2use tokio::sync::Mutex;
3
4use org_core::{OrgMode, config::OrgConfig};
5use rmcp::handler::server::tool::ToolRouter;
6
7pub struct OrgModeRouter {
8    pub(crate) org_mode: Arc<Mutex<OrgMode>>,
9    pub(crate) tool_router: ToolRouter<Self>,
10}
11
12impl OrgModeRouter {
13    pub fn with_config(config: OrgConfig) -> Result<Self, Box<dyn error::Error>> {
14        let org_mode = OrgMode::new(config)?;
15        Ok(Self {
16            org_mode: Arc::new(Mutex::new(org_mode)),
17            tool_router: Self::tool_router(),
18        })
19    }
20
21    pub fn with_directory(org_dir: &str) -> Result<Self, Box<dyn error::Error>> {
22        let config = OrgConfig {
23            org_directory: org_dir.to_string(),
24            ..OrgConfig::default()
25        };
26        let config = config.validate()?;
27        Self::with_config(config)
28    }
29
30    fn tool_router() -> ToolRouter<Self> {
31        Self::tool_router_list_files() + Self::tool_router_search() + Self::tool_router_agenda()
32    }
33}