iCalendar export: domain service + API + MCP tool (#15)
This commit is contained in:
@@ -14,7 +14,7 @@ use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::tools::{channels, library, schedule};
|
||||
use crate::tools::{channels, ical, library, schedule};
|
||||
|
||||
const SERVER_NAME: &str = "k-tv-mcp";
|
||||
|
||||
@@ -201,6 +201,16 @@ impl KTvMcpServer {
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[tool(
|
||||
description = "Export a channel's schedule as iCalendar (.ics). Returns RFC 5545 text."
|
||||
)]
|
||||
async fn export_schedule_ical(&self, #[tool(aggr)] p: ChannelIdParam) -> String {
|
||||
match parse_uuid(&p.channel_id) {
|
||||
Ok(id) => ical::export_schedule_ical(&self.channel_query, id).await,
|
||||
Err(e) => e,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tool(tool_box)]
|
||||
|
||||
20
crates/mcp/src/tools/ical.rs
Normal file
20
crates/mcp/src/tools/ical.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::error::domain_err;
|
||||
|
||||
pub async fn export_schedule_ical(
|
||||
channel_query: &Arc<dyn domain::ports::ChannelQuery>,
|
||||
channel_id: Uuid,
|
||||
) -> String {
|
||||
match channel_query.find_by_id(channel_id.into()).await {
|
||||
Ok(Some(channel)) => domain::generate_ical(
|
||||
channel.name(),
|
||||
channel.timezone(),
|
||||
channel.schedule_config(),
|
||||
),
|
||||
Ok(None) => serde_json::json!({"error": "Channel not found"}).to_string(),
|
||||
Err(e) => domain_err(e),
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod channels;
|
||||
pub mod ical;
|
||||
pub mod library;
|
||||
pub mod schedule;
|
||||
|
||||
Reference in New Issue
Block a user