Files
own_assist/mcp_server_collection/src/datetime.rs
T
milan 51b1123cf9 refactoring
different default system prompts for cli and audio
2026-05-04 21:18:09 +02:00

80 lines
2.2 KiB
Rust

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<Self>,
}
impl McpServerHandler for DateTimeHandler {
async fn new(
_additional_properties: Map<String, Value>,
) -> Result<Self, McpServerHandlerError> {
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")))
}
}