#[cfg(feature = "mcp-server")]
mod mcp_server_example {
use agentix::{McpServer, ToolBundle, tool};
struct MathTools;
#[tool]
impl agentix::Tool for MathTools {
async fn add(&self, a: f64, b: f64) -> f64 {
a + b
}
async fn multiply(&self, a: f64, b: f64) -> f64 {
a * b
}
}
pub async fn run() -> Result<(), Box<dyn std::error::Error>> {
let bundle = ToolBundle::new().with(MathTools);
let server = McpServer::new(bundle);
let addr = ("127.0.0.1", 3001);
println!("Starting MCP HTTP Server on http://{}:{}", addr.0, addr.1);
println!("You can now connect an MCP client (using HTTP transport) to this endpoint.");
println!("Press Ctrl+C to stop the server.");
server.serve_http(addr).await?;
Ok(())
}
}
#[cfg(feature = "mcp-server")]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
mcp_server_example::run().await
}
#[cfg(not(feature = "mcp-server"))]
fn main() {
println!("Please run this example with the `mcp-server` feature enabled:");
println!("cargo run --example 06_mcp_server --features mcp-server");
}