This commit is contained in:
125
src/tools/calendar_tools.py
Normal file
125
src/tools/calendar_tools.py
Normal file
@@ -0,0 +1,125 @@
|
||||
from typing import Optional
|
||||
from fastmcp import FastMCP
|
||||
|
||||
from services.calendar_service import CalendarService
|
||||
|
||||
|
||||
def register_calendar_tools(mcp: FastMCP, service: CalendarService):
|
||||
"""Register all calendar-related MCP tools."""
|
||||
|
||||
@mcp.tool(description="List all available calendars from the CalDAV server. Returns calendar ID, name, and properties.")
|
||||
def list_calendars() -> list[dict]:
|
||||
"""List all calendars."""
|
||||
calendars = service.list_calendars()
|
||||
return [c.model_dump() for c in calendars]
|
||||
|
||||
@mcp.tool(description="List events in a calendar within a specified date range. Supports recurring event expansion.")
|
||||
def list_events(
|
||||
calendar_id: str,
|
||||
start_date: str,
|
||||
end_date: str,
|
||||
include_recurring: bool = True,
|
||||
) -> dict:
|
||||
"""
|
||||
List events in a date range.
|
||||
|
||||
Args:
|
||||
calendar_id: The calendar ID (URL) to query
|
||||
start_date: Start of date range (ISO format: YYYY-MM-DD)
|
||||
end_date: End of date range (ISO format: YYYY-MM-DD)
|
||||
include_recurring: Whether to expand recurring events (default: True)
|
||||
"""
|
||||
result = service.list_events(calendar_id, start_date, end_date, include_recurring)
|
||||
return result.model_dump()
|
||||
|
||||
@mcp.tool(description="Get detailed information about a specific calendar event including attendees and recurrence.")
|
||||
def get_event(
|
||||
calendar_id: str,
|
||||
event_id: str,
|
||||
) -> Optional[dict]:
|
||||
"""
|
||||
Get a specific event.
|
||||
|
||||
Args:
|
||||
calendar_id: The calendar ID containing the event
|
||||
event_id: The unique ID (UID) of the event
|
||||
"""
|
||||
result = service.get_event(calendar_id, event_id)
|
||||
return result.model_dump() if result else None
|
||||
|
||||
@mcp.tool(description="Create a new calendar event with title, time, location, attendees, and optional recurrence.")
|
||||
def create_event(
|
||||
calendar_id: str,
|
||||
title: str,
|
||||
start: str,
|
||||
end: str,
|
||||
description: Optional[str] = None,
|
||||
location: Optional[str] = None,
|
||||
attendees: Optional[list[str]] = None,
|
||||
reminders: Optional[list[int]] = None,
|
||||
recurrence: Optional[str] = None,
|
||||
) -> dict:
|
||||
"""
|
||||
Create a new calendar event.
|
||||
|
||||
Args:
|
||||
calendar_id: The calendar ID to create the event in
|
||||
title: Event title/summary
|
||||
start: Start datetime (ISO format: YYYY-MM-DDTHH:MM:SS)
|
||||
end: End datetime (ISO format: YYYY-MM-DDTHH:MM:SS)
|
||||
description: Event description (optional)
|
||||
location: Event location (optional)
|
||||
attendees: List of attendee email addresses (optional)
|
||||
reminders: List of reminder times in minutes before event (optional)
|
||||
recurrence: iCalendar RRULE string for recurring events (optional)
|
||||
"""
|
||||
result = service.create_event(
|
||||
calendar_id, title, start, end, description, location, attendees, reminders, recurrence
|
||||
)
|
||||
return result.model_dump()
|
||||
|
||||
@mcp.tool(description="Update an existing calendar event. Only provided fields will be modified.")
|
||||
def update_event(
|
||||
calendar_id: str,
|
||||
event_id: str,
|
||||
title: Optional[str] = None,
|
||||
start: Optional[str] = None,
|
||||
end: Optional[str] = None,
|
||||
description: Optional[str] = None,
|
||||
location: Optional[str] = None,
|
||||
attendees: Optional[list[str]] = None,
|
||||
) -> Optional[dict]:
|
||||
"""
|
||||
Update an existing event.
|
||||
|
||||
Args:
|
||||
calendar_id: The calendar ID containing the event
|
||||
event_id: The unique ID of the event to update
|
||||
title: New event title (optional)
|
||||
start: New start datetime (optional)
|
||||
end: New end datetime (optional)
|
||||
description: New description (optional)
|
||||
location: New location (optional)
|
||||
attendees: New list of attendee emails (optional)
|
||||
"""
|
||||
result = service.update_event(
|
||||
calendar_id, event_id, title, start, end, description, location, attendees
|
||||
)
|
||||
return result.model_dump() if result else None
|
||||
|
||||
@mcp.tool(description="Delete a calendar event by ID.")
|
||||
def delete_event(
|
||||
calendar_id: str,
|
||||
event_id: str,
|
||||
notify_attendees: bool = True,
|
||||
) -> dict:
|
||||
"""
|
||||
Delete a calendar event.
|
||||
|
||||
Args:
|
||||
calendar_id: The calendar ID containing the event
|
||||
event_id: The unique ID of the event to delete
|
||||
notify_attendees: Whether to notify attendees of cancellation (default: True)
|
||||
"""
|
||||
result = service.delete_event(calendar_id, event_id, notify_attendees)
|
||||
return result.model_dump()
|
||||
Reference in New Issue
Block a user