mirror of
https://github.com/storytold/cadcraft.git
synced 2026-12-02 02:38:30 -06:00
CodeRabbit measures docstring coverage over the functions a PR touches, and this one was at 62%, under the repository's 80% threshold.
26 lines
1.2 KiB
Rust
26 lines
1.2 KiB
Rust
use super::args::{McpArgs, McpTarget};
|
|
use super::error::{CliError, Result};
|
|
|
|
/// Serve MCP on stdin and stdout against the running app or a headless session held to any roots given.
|
|
pub(crate) fn mcp(a: &McpArgs) -> Result {
|
|
let backend: Box<dyn cadcraft_mcp::Backend> = match a.target() {
|
|
McpTarget::Connect { addr, lazy: true, launch } => Box::new(cadcraft_mcp::Remote::lazy(&addr, launch)),
|
|
McpTarget::Connect { addr, .. } => match cadcraft_mcp::Remote::connect(&addr) {
|
|
Ok(r) => Box::new(r),
|
|
Err(source) => return Err(CliError::McpConnect { addr, source }),
|
|
},
|
|
McpTarget::Headless { read_root, write_root } => {
|
|
let roots = cadcraft_engine::file_access::AutomationRoots::new(
|
|
read_root.as_deref().map(std::path::Path::new),
|
|
write_root.as_deref().map(std::path::Path::new),
|
|
)
|
|
.map_err(CliError::AutomationRoots)?;
|
|
Box::new(cadcraft_mcp::Headless::default().with_automation_roots(roots))
|
|
}
|
|
};
|
|
let stdin = std::io::stdin();
|
|
let stdout = std::io::stdout();
|
|
cadcraft_mcp::Server::new(backend).serve(stdin.lock(), stdout.lock())?;
|
|
Ok(())
|
|
}
|