list_events
Retrieve and display upcoming calendar events within specified time ranges and result limits using the Google Toolbox. Simplify event tracking and scheduling.
Instructions
List upcoming calendar events
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| max_results | No | ||
| time_max | No | ||
| time_min | No |
Implementation Reference
- server.py:407-462 (handler)The main handler function for the 'list_events' tool, decorated with @mcp.tool. It fetches upcoming Google Calendar events within a specified time range using the Google Calendar API, formats them into a list of dictionaries, and handles authentication and errors.@mcp.tool( name="list_events", description="List upcoming calendar events", ) async def list_events(time_min: Optional[str] = None, time_max: Optional[str] = None, max_results: int = 10) -> List[Dict[str, Any]]: """ List upcoming calendar events Args: time_min (str, optional): Start time in ISO format (default: now) time_max (str, optional): End time in ISO format (default: now + 1 week) max_results (int, optional): Maximum number of events to return (default: 10) Returns: List[Dict[str, Any]]: List of calendar events """ creds = get_google_credentials() if not creds: return "Google authentication failed." try: service = build('calendar', 'v3', credentials=creds) now_iso = datetime.datetime.now(datetime.timezone.utc).isoformat() time_min = time_min or now_iso time_max = time_max or now_iso events_result = service.events().list( calendarId='primary', timeMin=time_min, timeMax=time_max, maxResults=max_results, singleEvents=True, orderBy='startTime' ).execute() events = events_result.get('items', []) event_list = [ { 'id': event.get('id'), 'summary': event.get('summary'), 'start': event.get('start', {}).get('dateTime') or event.get('start', {}).get('date'), 'end': event.get('end', {}).get('dateTime') or event.get('end', {}).get('date'), 'location': event.get('location'), 'description': event.get('description'), } for event in events ] return event_list except HttpError as error: logger.error(f"API 오류 발생: {error}") return f"Calendar API 오류: {error.resp.status} - {error.content.decode()}" except Exception as e: logger.exception("이벤트 목록 조회 중 오류:") return f"예상치 못한 오류 발생: {str(e)}"
- server.py:193-207 (registration)A resource that lists all available tools including 'list_events', serving as a tool directory or registration list.@mcp.resource( uri='google://available-google-tools', name="available-google-tools", description="Returns a list of Google search categories available on this MCP server." ) async def get_available_google_tools() -> List[str]: """Returns a list of Google search categories available on this MCP server.""" available_google_tools = [ "list_emails", "search_emails", "send_email", "modify_email", "list_events", "create_event", "update_event", "delete_event", "search_google", "read_gdrive_file", "search_gdrive" ] logger.info(f"Resource 'get_available_google_tools' 호출됨. 반환: {available_google_tools}") return available_google_tools