Make calendar_id optional in list_events tool
All checks were successful
Build And Test / publish (push) Successful in 47s
All checks were successful
Build And Test / publish (push) Successful in 47s
When no calendar_id is provided, lists events from all calendars. Events include calendar_name field when listing from all calendars. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,24 +13,50 @@ def register_calendar_tools(mcp: FastMCP, service: CalendarService):
|
||||
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.")
|
||||
@mcp.tool(description="List events within a date range. If no calendar is specified, lists events from all calendars.")
|
||||
def list_events(
|
||||
calendar_id: str,
|
||||
start_date: str,
|
||||
end_date: str,
|
||||
calendar_id: Optional[str] = None,
|
||||
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)
|
||||
calendar_id: The calendar ID (URL) to query. If not provided, lists from all calendars.
|
||||
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()
|
||||
if calendar_id:
|
||||
# Single calendar
|
||||
result = service.list_events(calendar_id, start_date, end_date, include_recurring)
|
||||
return result.model_dump()
|
||||
else:
|
||||
# All calendars
|
||||
calendars = service.list_calendars()
|
||||
all_events = []
|
||||
for cal in calendars:
|
||||
try:
|
||||
result = service.list_events(cal.id, start_date, end_date, include_recurring)
|
||||
for event in result.events:
|
||||
event_dict = event.model_dump()
|
||||
event_dict["calendar_name"] = cal.name
|
||||
all_events.append(event_dict)
|
||||
except Exception:
|
||||
continue # Skip calendars that fail
|
||||
|
||||
# Sort by start time
|
||||
all_events.sort(key=lambda e: e.get("start", ""))
|
||||
|
||||
return {
|
||||
"events": all_events,
|
||||
"total": len(all_events),
|
||||
"calendar_id": "all",
|
||||
"start_date": start_date,
|
||||
"end_date": end_date,
|
||||
}
|
||||
|
||||
@mcp.tool(description="Get detailed information about a specific calendar event including attendees and recurrence.")
|
||||
def get_event(
|
||||
|
||||
Reference in New Issue
Block a user