//! Model Context Protocol (MCP) server executable for Phoebus OS. //! //! Speaks JSON-RPC 2.0 over standard I/O, conforming to the MCP specification. //! Used by Claude Code, Cursor, OpenCode, and Zed. use std::io::{self, BufRead, Write}; use std::path::PathBuf; use clap::Parser; use phoebus_mcp::handle_mcp_message; #[derive(Parser, Debug)] #[command( name = "phoebus-mcp", about = "Model Context Protocol server for Phoebus OS desktop & developer agents" )] struct Cli { /// Override the user's home directory (useful for testing or isolation). #[arg(long)] home: Option, } fn main() { let cli = Cli::parse(); let home = cli.home.unwrap_or_else(|| { std::env::var("HOME") .map(PathBuf::from) .unwrap_or_else(|_| PathBuf::from(".")) }); let stdin = io::stdin(); let mut stdout = io::stdout(); for line in stdin.lock().lines() { let line = match line { Ok(l) => l, Err(_) => break, }; let trimmed = line.trim(); if trimmed.is_empty() { continue; } if let Some(response) = handle_mcp_message(trimmed, &home) { let _ = writeln!(stdout, "{response}"); let _ = stdout.flush(); } } }