use allframe_core::router::Router;
use allframe_mcp::{init_tracing, McpServer, StdioConfig, StdioTransport};
#[tokio::main]
async fn main() {
init_tracing();
let router = create_router();
let mcp = McpServer::with_router(router);
let config = StdioConfig::default()
.with_debug_tool(true) .with_server_name("allframe-example");
StdioTransport::new(mcp, config).serve().await;
}
fn create_router() -> Router {
let mut router = Router::new();
router.register("get_user", || async {
let user_id = uuid::Uuid::new_v4();
format!(
"{{\"id\": \"{}\", \"name\": \"User {}\", \"email\": \"user@example.com\"}}",
user_id, user_id
)
});
router.register("create_order", || async {
let order_id = uuid::Uuid::new_v4();
format!(
"{{\"order_id\": \"{}\", \"product\": \"Widget\", \"status\": \"created\"}}",
order_id
)
});
router.register("search_products", || async {
r#"{"query": "search", "results": [{"id": "1", "name": "Product A"}, {"id": "2", "name": "Product B"}]}"#.to_string()
});
router.register("calculate_shipping", || async {
let weight = 10.0;
let cost = weight * 2.5 + 5.0;
format!("{{\"weight\": {}, \"cost\": {:.2}}}", weight, cost)
});
router
}