use crate::server_handler::{McpServerHandler, McpServerHandlerError}; use chrono::{Datelike, Local, Utc}; use rmcp::handler::server::tool::ToolRouter; use rmcp::model::{Implementation, ServerCapabilities, ServerInfo}; use rmcp::{ServerHandler, tool, tool_handler, tool_router}; use toml::Value; use toml::map::Map; #[derive(Debug, Clone)] pub(crate) struct DateTimeHandler { tool_router: ToolRouter, } impl McpServerHandler for DateTimeHandler { async fn new( _additional_properties: Map, ) -> Result { Ok(DateTimeHandler { tool_router: Self::tool_router(), }) } } #[tool_router] impl DateTimeHandler { #[tool( description = "returns the local datetime in ISO 8601", annotations(read_only_hint = true) )] fn get_local_datetime() -> String { Local::now().format("%+").to_string() } #[tool( description = "returns the utc datetime in ISO 8601", annotations(read_only_hint = true) )] fn get_utc_datetime() -> String { Utc::now().format("%+").to_string() } #[tool( description = "return current week number in year", annotations(read_only_hint = true) )] fn get_week() -> String { Local::now().iso_week().week().to_string() } #[tool( description = "return current weekday", annotations(read_only_hint = true) )] fn get_weekday() -> String { use chrono::Weekday::*; match Local::now().weekday() { Mon => "Monday", Tue => "Tuesday", Wed => "Wednesday", Thu => "Thursday", Fri => "Friday", Sat => "Saturday", Sun => "Sunday", }.to_string() } } #[tool_handler] impl ServerHandler for DateTimeHandler { fn get_info(&self) -> ServerInfo { ServerInfo::new(ServerCapabilities::builder().enable_tools().build()) .with_instructions( "A simple clock/datetime provider. It is read only and thus safe to use." .to_string(), ) .with_server_info(Implementation::new("datetime", env!("CARGO_PKG_VERSION"))) } }