Skip to main content
Glama

get_pending_events

Retrieve upcoming events and deadlines from Moodle calendar to track academic schedules and manage course requirements.

Instructions

Get upcoming events and deadlines from Moodle calendar.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • main.py:143-151 (handler)
    MCP tool handler that invokes the client method and formats events as list of dicts with error handling.
    def tool_get_pending_events() -> List[Dict[str, str]]:
        try:
            events = muster_client.get_pending_events()
            return [
                {"name": event.name, "course": event.course, "due_date": event.due_date, "url": event.url}
                for event in events
            ]
        except Exception as e:
            return [{"error": f"Failed to get pending events: {str(e)}"}]
  • Core implementation in MUSTerClient: authenticates, navigates to Moodle upcoming events, parses each event container with Selenium selectors, extracts details into Event dataclass instances.
    def get_pending_events(self) -> List[Event]:
        """Get all pending events and assignment deadlines with detailed information."""
        
        self._ensure_driver()
        self.heartBeat()
        if not self.logged_in:
            if not self.login():
                raise Exception("Login required to get events.")
    
        events = []
        try:
            # Navigate to upcoming events page
            self.driver.get(f"{MOODLE_URL}/calendar/view.php?view=upcoming")
    
            # Wait for events to load
            WebDriverWait(self.driver, 10).until(
                EC.presence_of_element_located((By.CSS_SELECTOR, "[data-type='event']"))
            )
    
            # Find all event containers
            event_elements = self.driver.find_elements(By.CSS_SELECTOR, "[data-type='event']")
    
            for element in event_elements:
                try:
                    # Extract event name from header
                    event_name = ""
                    try:
                        event_name = element.find_element(By.CSS_SELECTOR, "h3.name").text.strip()
                    except Exception:
                        # Fallback to data attribute
                        event_name = element.get_attribute("data-event-title") or ""
    
                    if not event_name:
                        continue
    
                    # Extract due date/time
                    due_date = ""
                    try:
                        # Find the row containing the "When" icon
                        date_row = element.find_element(By.XPATH, ".//div[@class='row'][.//i[@title='When']]")
                        date_col = date_row.find_element(By.CSS_SELECTOR, ".col-11")
                        due_date = date_col.text.strip()
                    except Exception:
                        pass
    
                    # Extract event type
                    event_type = ""
                    try:
                        # Find the row containing the "Event type" icon
                        type_row = element.find_element(By.XPATH, ".//div[@class='row mt-1'][.//i[@title='Event type']]")
                        type_col = type_row.find_element(By.CSS_SELECTOR, ".col-11")
                        event_type = type_col.text.strip()
                    except Exception:
                        # Fallback to data attribute
                        event_type = element.get_attribute("data-event-eventtype") or "unknown"
    
                    # Extract course name and URL
                    course_name = ""
                    course_url = ""
                    try:
                        # Find the row containing the "Course" icon
                        course_row = element.find_element(By.XPATH, ".//div[@class='row mt-1'][.//i[@title='Course']]")
                        course_link = course_row.find_element(By.CSS_SELECTOR, ".col-11 a")
                        course_name = course_link.text.strip()
                        course_url = course_link.get_attribute("href") or ""
                    except Exception:
                        pass
    
                    # Extract description (if available)
                    description = ""
                    try:
                        desc_element = element.find_element(By.CSS_SELECTOR, ".description-content")
                        description = desc_element.text.strip()
                    except Exception:
                        pass
    
                    # Extract activity URL
                    activity_url = ""
                    try:
                        activity_link = element.find_element(By.CSS_SELECTOR, ".card-footer a.card-link")
                        activity_url = activity_link.get_attribute("href") or ""
                    except Exception:
                        pass
    
                    # Create Event object
                    event = Event(
                        name=event_name,
                        due_date=due_date,
                        event_type=event_type,
                        course=course_name,
                        course_url=course_url,
                        url=activity_url,
                        description=description
                    )
                    events.append(event)
    
                except Exception as e:
                    print(f"Error parsing individual event: {e}")
                    continue
    
        except TimeoutException:
            print("Timeout while waiting for events to load")
        except Exception as e:
            print(f"Error retrieving pending events: {e}")
    
        self.heartBeat()
        return events
  • main.py:45-48 (registration)
    Tool registration in list_muster_tools(): defines name, description, and empty input schema (no parameters).
    Tool(
        name="get_pending_events",
        description="Get upcoming events and deadlines from Moodle calendar.",
        inputSchema={"type": "object", "properties": {}, "required": []},
  • Output data structure defining fields for each pending event returned by the handler.
    class Event:
        name: str
        due_date: str
        event_type: str
        course: str
        course_url: str
        url: str = ""
        description: str = ""

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Cosmostima/MUSTer_MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server