8000 feat(ws): add read-only list_upcoming_deadlines tool by cassohir · Pull Request #1 · SaadRahman01/moodle-mcp · GitHub
[go: up one dir, main page]

Skip to content

feat(ws): add read-only list_upcoming_deadlines tool - #1

Open
cassohir wants to merge 1 commit into
SaadRahman01:mainfrom
cassohir:feat/list-upcoming-deadlines
Open

cassohir wants to merge 1 commit into
SaadRahman01:mainfrom
cassohir:feat/list-upcoming-deadlines

Conversation

@cassohir
@cassohir cassohir commented Nov 2, 2026
Copy link
Copy Markdown

Summary

Adds list_upcoming_deadlines, a read-only Web Services tool that lists the authenticated user's pending activities — the same data shown in the Moodle Dashboard Timeline block — with due date, course, activity link and an overdue flag.

Motivation

Once MOODLE_URL + MOODLE_TOKEN are set, one of the most natural things a student or teacher asks an assistant is "what do I have due this week?". Today the only way to answer that is call_ws_function, which is (correctly) annotated destructiveHint=true. As a result, clients prompt for confirmation on every call, and the model has to know the right function name, its argument shape and Moodle's pagination rules.

A dedicated tool makes this a one-step, safe, well-formatted call.

What it does

  • Calls core_calendar_get_action_events_by_timesort, which is part of the moodle_mobile_app service. Any token issued for the official mobile app works, including on SSO-only sites (Shibboleth, CAS, …) via the admin/tool/mobile/launch.php flow.
  • Returns only items that are still actionable for the user, e.g. assignments not yet submitted. This is the same rule the Timeline block uses.
Parameter Default Range Meaning
days 30 1–365 How far ahead to look
overdue_days 7 0–365 How far back to include overdue items (0 = none)
limit 50 1–200 Maximum items returned
  • Pagination: Moodle caps limitnum at 50 per call, so the tool pages with aftereventid/lastid until it reaches limit. It stops early on a short page or a missing/unchanged lastid, so a misbehaving server can't make it loop.
  • Output: follows the existing {markdown, data} convention.
    • markdown: a table with due date in local time, course, linked activity, and status (**overdue** or the pending action, e.g. Add submission). Pipes and newlines in cells are escaped.
    • data.deadlines[]: id, name, event, module, course, timesort, an ISO-8601 UTC due, overdue, action and url, plus data.truncated.
  • Annotations: readOnlyHint=true, destructiveHint=false.
  • Errors: an unconfigured instance and WS errors return the same friendly messages as list_ws_functions and call_ws_function.

Example output

# Upcoming Moodle deadlines

**2** pending item(s).

| Due | Course | Activity | Status |
| --- | --- | --- | --- |
| Fri 2026-10-30 23:59 | Cálculo I | [Lista 3](https://…/mod/assign/view.php?id=123) | **overdue** |
| Wed 2026-11-04 23:59 | Algoritmos I | [TP1](https://…/mod/assign/view.php?id=456) | Add submission |

Changes

  • src/moodle_mcp/tools.py: tool_upcoming_deadlines plus small helpers _deadline_from_event and _md_cell.
  • src/moodle_mcp/server.py: tool schema (with bounds) and dispatch.
  • tests/test_ws.py: tests for formatting and sorting, request window params, pagination via aftereventid, the empty result, the unconfigured case, and the read-only annotations.
  • tests/test_dispatch.py: an end-to-end dispatch test for the unconfigured path.
  • README.md: the tool table, now "Eleven MCP tools".

No new dependencies, and existing tools are untouched.

Testing

  • ruff check . passes.
  • mypy passes.
  • pytest -q passes, 87 tests, on Python 3.10 and 3.12.

🤖 Generated with Claude Code

Surface the user's pending activities (the Dashboard "Timeline") via
core_calendar_get_action_events_by_timesort, so assistants can answer
"what do I have due?" without reaching for the destructive-annotated
call_ws_function.

- days / overdue_days window, limit up to 200 (paged 50 at a time via
  aftereventid, since Moodle caps limitnum at 50)
- markdown table (due in local time, course, linked activity, status)
  plus structured data with an ISO-8601 UTC due date and overdue flag
- annotated readOnlyHint=true / destructiveHint=false
- tests: formatting/sorting, pagination, empty, unconfigured, dispatch,
  annotations

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0