#[cfg(feature = "repl-mcp")]
use crate::service::TuiService;
#[cfg(feature = "repl-mcp")]
use std::sync::Arc;
#[cfg(feature = "repl-mcp")]
use terraphim_automata::LinkType;
#[cfg(feature = "repl-mcp")]
use terraphim_types::RoleName;
#[cfg(feature = "repl-mcp")]
#[allow(dead_code)] pub struct McpToolsHandler {
service: Arc<TuiService>,
}
#[cfg(feature = "repl-mcp")]
#[allow(dead_code)] impl McpToolsHandler {
pub fn new(service: Arc<TuiService>) -> Self {
Self { service }
}
async fn get_role(&self) -> RoleName {
self.service.get_selected_role().await
}
pub async fn autocomplete_terms(
&self,
query: &str,
limit: Option<usize>,
) -> anyhow::Result<Vec<String>> {
let role = self.get_role().await;
let results = self.service.autocomplete(&role, query, limit).await?;
Ok(results.into_iter().map(|r| r.term).collect())
}
pub async fn extract_paragraphs(
&self,
text: &str,
exclude_term: bool,
) -> anyhow::Result<Vec<(String, String)>> {
let role = self.get_role().await;
self.service
.extract_paragraphs(&role, text, exclude_term)
.await
}
pub async fn find_matches(&self, text: &str) -> anyhow::Result<Vec<String>> {
let role = self.get_role().await;
let matches = self.service.find_matches(&role, text).await?;
Ok(matches.into_iter().map(|m| m.term).collect())
}
pub async fn replace_matches(
&self,
text: &str,
format: Option<String>,
) -> anyhow::Result<String> {
let role = self.get_role().await;
let link_type = match format.as_deref() {
Some("html") => LinkType::HTMLLinks,
_ => LinkType::MarkdownLinks,
};
self.service.replace_matches(&role, text, link_type).await
}
pub async fn get_thesaurus(
&self,
role: Option<String>,
) -> anyhow::Result<Vec<(String, String)>> {
let role_name = match role {
Some(r) => RoleName::new(&r),
None => self.get_role().await,
};
let thesaurus = self.service.get_thesaurus(&role_name).await?;
let pairs: Vec<_> = thesaurus
.into_iter()
.map(|(_, nterm)| {
(
nterm.value.to_string(),
nterm.url.clone().unwrap_or_default(),
)
})
.collect();
Ok(pairs)
}
}