use anyhow::Result;
use std::path::Path;
#[cfg(feature = "mcp")]
pub fn handle_mcp_command(
name: &str,
_streaming: bool,
_timeout: u64,
_min_score: f64,
_max_complexity: u32,
verbose: bool,
_config: Option<&Path>,
) -> Result<()> {
use anyhow::Context;
use ruchy::mcp::{create_ruchy_mcp_server, create_ruchy_tools, StdioTransport};
if verbose {
eprintln!("🚀 Starting Ruchy MCP Server: {}", name);
}
let server = create_ruchy_mcp_server().context("Failed to create MCP server")?;
let tools = create_ruchy_tools();
if verbose {
eprintln!(" Registered {} tools:", tools.len());
for (tool_name, tool) in &tools {
eprintln!(" - {}: {}", tool_name, tool.description());
}
}
if verbose {
eprintln!(" Transport: stdio");
eprintln!(" Awaiting MCP client connection...");
}
let runtime = tokio::runtime::Runtime::new().context("Failed to create async runtime")?;
runtime.block_on(async {
let transport = StdioTransport::new();
if verbose {
eprintln!("✅ MCP server running");
}
server.run(transport).await.context("MCP server error")
})
}
#[cfg(not(feature = "mcp"))]
pub fn handle_mcp_command(
_name: &str,
_streaming: bool,
_timeout: u64,
_min_score: f64,
_max_complexity: u32,
_verbose: bool,
_config: Option<&Path>,
) -> Result<()> {
eprintln!("Error: MCP support not enabled");
eprintln!("Rebuild with: cargo build --features mcp");
std::process::exit(1);
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_mcp_handler_stub() {
}
#[test]
#[cfg(not(feature = "mcp"))]
fn test_handle_mcp_command_no_feature() {
}
#[test]
fn test_mcp_command_accepts_parameters() {
let _ = handle_mcp_command("test-server", false, 3600, 0.8, 10, false, None);
}
#[test]
fn test_mcp_command_with_streaming() {
let _ = handle_mcp_command(
"streaming-server",
true, 3600,
0.8,
10,
false,
None,
);
}
#[test]
fn test_mcp_command_with_verbose() {
let _ = handle_mcp_command(
"verbose-server",
false,
3600,
0.8,
10,
true, None,
);
}
#[test]
fn test_mcp_command_various_timeouts() {
let timeouts = [60, 300, 3600, 86400];
for timeout in &timeouts {
let _ = handle_mcp_command("test", false, *timeout, 0.8, 10, false, None);
}
}
#[test]
fn test_mcp_command_various_scores() {
let scores = [0.0, 0.5, 0.8, 1.0];
for score in &scores {
let _ = handle_mcp_command("test", false, 3600, *score, 10, false, None);
}
}
#[test]
fn test_mcp_command_various_complexity() {
let complexities = [1, 5, 10, 20, 50];
for complexity in &complexities {
let _ = handle_mcp_command("test", false, 3600, 0.8, *complexity, false, None);
}
}
#[test]
fn test_mcp_command_with_config() {
let _ = handle_mcp_command(
"config-server",
false,
3600,
0.8,
10,
false,
Some(Path::new("/path/to/config.toml")),
);
}
#[test]
fn test_mcp_command_all_options() {
let _ = handle_mcp_command(
"full-server",
true,
7200,
0.9,
15,
true,
Some(Path::new("./mcp.toml")),
);
}
#[test]
fn test_mcp_command_empty_name() {
let _ = handle_mcp_command("", false, 3600, 0.8, 10, false, None);
}
}