list_calendars
Retrieve a formatted list of accessible calendars for a user, including details like summary, ID, and primary status, using their Google email address.
Instructions
Retrieves a list of calendars accessible to the authenticated user.
Args:
user_google_email (str): The user's Google email address. Required.
Returns:
str: A formatted list of the user's calendars (summary, ID, primary status).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| service | Yes | ||
| user_google_email | Yes |
Implementation Reference
- gcalendar/calendar_tools.py:255-286 (handler)The complete handler implementation for the 'list_calendars' tool, including decorators for registration (@server.tool()), error handling, and Google service authentication. This function lists all calendars accessible to the user and returns a formatted string summary.@server.tool() @handle_http_errors("list_calendars", is_read_only=True, service_type="calendar") @require_google_service("calendar", "calendar_read") async def list_calendars(service, user_google_email: str) -> str: """ Retrieves a list of calendars accessible to the authenticated user. Args: user_google_email (str): The user's Google email address. Required. Returns: str: A formatted list of the user's calendars (summary, ID, primary status). """ logger.info(f"[list_calendars] Invoked. Email: '{user_google_email}'") calendar_list_response = await asyncio.to_thread( lambda: service.calendarList().list().execute() ) items = calendar_list_response.get("items", []) if not items: return f"No calendars found for {user_google_email}." calendars_summary_list = [ f"- \"{cal.get('summary', 'No Summary')}\"{' (Primary)' if cal.get('primary') else ''} (ID: {cal['id']})" for cal in items ] text_output = ( f"Successfully listed {len(items)} calendars for {user_google_email}:\n" + "\n".join(calendars_summary_list) ) logger.info(f"Successfully listed {len(items)} calendars for {user_google_email}.") return text_output
- gcalendar/calendar_tools.py:255-255 (registration)The @server.tool() decorator registers the list_calendars function as an MCP tool.@server.tool()
- gcalendar/calendar_tools.py:258-266 (schema)Function signature and docstring defining the input parameters and output format, which serves as the tool schema for MCP.async def list_calendars(service, user_google_email: str) -> str: """ Retrieves a list of calendars accessible to the authenticated user. Args: user_google_email (str): The user's Google email address. Required. Returns: str: A formatted list of the user's calendars (summary, ID, primary status).