add caldav mcp server

refactoring
This commit is contained in:
milan
2026-05-03 18:28:20 +02:00
parent 20a5b01311
commit 3dd897c422
14 changed files with 1342 additions and 97 deletions
+37 -15
View File
@@ -1,38 +1,56 @@
use chrono::{Datelike, Local};
use rmcp::model::{Implementation, ServerCapabilities, ServerInfo};
use rmcp::{tool, tool_handler, tool_router, ServerHandler};
use crate::server_handler::{McpServerHandler, McpServerHandlerError};
use chrono::{Datelike, Local, Utc};
use rmcp::handler::server::tool::ToolRouter;
use crate::McpServerHandler;
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 struct DateTimeHandler {
tool_router: ToolRouter<Self>
pub(crate) struct DateTimeHandler {
tool_router: ToolRouter<Self>,
}
impl McpServerHandler for DateTimeHandler {
fn new() -> Self {
DateTimeHandler { tool_router: Self::tool_router() }
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))]
#[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))]
#[tool(
description = "returns the utc datetime in ISO 8601",
annotations(read_only_hint = true)
)]
fn get_utc_datetime() -> String {
Local::now().format("%+").to_string()
Utc::now().format("%+").to_string()
}
#[tool(description = "return current week number in year", annotations(read_only_hint = true))]
#[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))]
#[tool(
description = "return current weekday",
annotations(read_only_hint = true)
)]
fn get_weekday() -> String {
Local::now().weekday().to_string()
}
@@ -42,6 +60,10 @@ impl DateTimeHandler {
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")))
.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")))
}
}
}