From a56a6d0b2c0e5c76606557cc8525ab93fdd0d340 Mon Sep 17 00:00:00 2001 From: henrik <1822029+akesson@users.noreply.github.com> Date: Sat, 17 May 2025 18:45:03 +0200 Subject: [PATCH] Refactor hello server to use stdio --- mcp-command/src/main.rs | 6 +++++- mcp-lib/Cargo.toml | 1 + mcp-lib/src/lib.rs | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/mcp-command/src/main.rs b/mcp-command/src/main.rs index ce8a3ff..9c0998e 100644 --- a/mcp-command/src/main.rs +++ b/mcp-command/src/main.rs @@ -1,5 +1,5 @@ use cmd_lib::run; -use mcp_lib::Mcp; +use mcp_lib::{Mcp, start_hello_server}; fn main() { let output = match run("echo", &["Hello from mcp-command"]) { @@ -12,4 +12,8 @@ fn main() { let formatted = Mcp::process_output(&output.stdout); println!("{formatted}"); + + if let Err(err) = start_hello_server() { + eprintln!("server error: {err}"); + } } diff --git a/mcp-lib/Cargo.toml b/mcp-lib/Cargo.toml index d417a39..2a5eeb4 100644 --- a/mcp-lib/Cargo.toml +++ b/mcp-lib/Cargo.toml @@ -4,3 +4,4 @@ version = "0.1.0" edition = "2021" [dependencies] +rmcp = { version = "0.1", features = ["server"] } diff --git a/mcp-lib/src/lib.rs b/mcp-lib/src/lib.rs index ee048b0..e4e97ee 100644 --- a/mcp-lib/src/lib.rs +++ b/mcp-lib/src/lib.rs @@ -8,6 +8,23 @@ impl Mcp { } } +/// Start a simple "Hello World" MCP server over stdio. +/// +/// This uses the `rmcp` crate's stdio server functionality. +pub fn start_hello_server() -> std::io::Result<()> { + use rmcp::stdio::Server; + + let mut server = Server::new(); + println!("MCP stdio server ready"); + + for mut connection in server.incoming() { + let mut stream = connection?; + stream.send(b"Hello World\n")?; + } + + Ok(()) +} + #[cfg(test)] mod tests { use super::*;