Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
# ILIAS MCP

Production-oriented MCP server for ILIAS login, enrolled course listing, dashboard news, repository crawling, and file downloads.
Production-oriented MCP server for ILIAS login, enrolled course listing, dashboard news, repository crawling, file downloads, and exercise submission management.

## Tools

### General

- [login](#login): authenticate against ILIAS
- [list_courses](#list_courses): list enrolled courses with title, URL, and ref ID
- [server_info](#server_info): show non-sensitive runtime config
- [list_calendar_events](#list_calendar_events): list agenda events for a day
- [list_dashboard_news](#list_dashboard_news): list personal dashboard news from ilPDNewsGUI

### Repository

- [list_repository_items](#list_repository_items): list child objects below a ref ID
- [get_repository_item_details](#get_repository_item_details): fetch page details and detect download URLs
- [get_file_content](#get_file_content): download file content by ref ID; PDFs are parsed to text with pypdf
- [crawl_repository](#crawl_repository): recursively walk a course or folder and return a flat tree
- [download_file](#download_file): download one file object by ref ID
- [download_repository_files](#download_repository_files): recursively download matching files and preserve ILIAS folders

### Exercise Submission

- [list_exercise_assignments](#list_exercise_assignments): list assignments (Übungsblätter) for an exercise object by ref ID
- [submit_exercise_file](#submit_exercise_file): upload a local file as a submission for an assignment
- [list_submitted_files](#list_submitted_files): list already submitted files with their delivery IDs
- [delete_submitted_files](#delete_submitted_files): delete submitted files by delivery ID

### Team Management

- [list_team_members](#list_team_members): list current submission team members
- [add_team_member](#add_team_member): add a user to the submission team by ILIAS login name
- [remove_team_member](#remove_team_member): remove a team member by user ID
- [search_users](#search_users): search ILIAS users by name fragment to find their login name

## Demo

![ILIAS MCP tools demo](assets/ilias-mcp-tools-demo.png)
Expand Down Expand Up @@ -48,6 +67,7 @@ ilias-mcp

- Server keeps a session in memory while process is running.
- On process restart, login is re-established on demand.
- This server is intentionally read-only for safety.
- Downloads use the official ILIAS file routes used by the Stuttgart fork, including ilObjFileGUI sendfile and goto.php file download routes.
- Start with [list_courses](#list_courses), then call [crawl_repository](#crawl_repository) or [download_repository_files](#download_repository_files) with the course ref ID.
- For exercise submission: use [list_exercise_assignments](#list_exercise_assignments) to get `ass_id` values, then [submit_exercise_file](#submit_exercise_file) with the local file path.
- For team management: use [search_users](#search_users) to find a teammate's login name, then [add_team_member](#add_team_member).
Comment thread
DenizAltunkapan marked this conversation as resolved.
Resolved
21 changes: 21 additions & 0 deletions src/domain/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,24 @@ class NewsItem:
author: str
date_label: str
url: str


@dataclass(frozen=True)
class ExerciseAssignment:
ass_id: str
title: str
deadline: str
status: str


@dataclass(frozen=True)
class SubmittedFile:
Comment thread
DenizAltunkapan marked this conversation as resolved.
Resolved
filename: str
size: str
date: str


@dataclass(frozen=True)
class TeamMember:
user_id: str
name: str
232 changes: 232 additions & 0 deletions src/mcp_app/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from services.calendar_service import CalendarService, IliasCalendarError
from services.course_service import CourseService, IliasCourseError
from services.news_service import IliasNewsError, NewsService
from services.exercise_service import ExerciseService, IliasExerciseError
from services.repository_service import IliasRepositoryError, RepositoryService

logging.basicConfig(level=logging.INFO)
Expand All @@ -29,13 +30,15 @@ def __init__(
calendar_service: CalendarService,
news_service: NewsService,
repository_service: RepositoryService,
exercise_service: ExerciseService,
) -> None:
self.settings = settings
self.auth_service = auth_service
self.course_service = course_service
self.calendar_service = calendar_service
self.news_service = news_service
self.repository_service = repository_service
self.exercise_service = exercise_service


@asynccontextmanager
Expand Down Expand Up @@ -69,6 +72,9 @@ async def lifespan(_: FastMCP) -> AsyncIterator[AppContext]:
repository_service = RepositoryService(
settings=settings, session=session, auth_service=auth_service
)
exercise_service = ExerciseService(
settings=settings, session=session, auth_service=auth_service
)
logger.info("ILIAS MCP server initialized and ready.")
yield AppContext(
settings=settings,
Expand All @@ -77,6 +83,7 @@ async def lifespan(_: FastMCP) -> AsyncIterator[AppContext]:
calendar_service=calendar_service,
news_service=news_service,
repository_service=repository_service,
exercise_service=exercise_service,
)
logger.info("Shutting down ILIAS MCP server.")

Expand Down Expand Up @@ -390,6 +397,231 @@ async def list_dashboard_news(
}


@mcp.tool()
async def list_exercise_assignments(
ctx: Context[ServerSession, AppContext],
ref_id: str,
) -> dict[str, object]:
"""List all assignments (Übungsblätter) for an ILIAS exercise object by ref_id."""
Comment thread
DenizAltunkapan marked this conversation as resolved.
Resolved
app = _app(ctx)
try:
assignments = app.exercise_service.list_assignments(ref_id=ref_id)
except (IliasAuthError, IliasExerciseError) as exc:
logger.warning("Exercise listing failed for ref_id=%s: %s", ref_id, exc)
return {
Comment thread
DenizAltunkapan marked this conversation as resolved.
Resolved
"status": "error",
"message": str(exc),
"ref_id": ref_id,
"assignments": [],
}

return {
"status": "ok",
"ref_id": ref_id,
"count": len(assignments),
"assignments": [
{
"ass_id": a.ass_id,
"title": a.title,
"deadline": a.deadline,
"status": a.status,
}
for a in assignments
],
}


@mcp.tool()
async def submit_exercise_file(
ctx: Context[ServerSession, AppContext],
ref_id: str,
ass_id: str,
local_path: str,
) -> dict[str, object]:
"""Upload a local file as a submission for an ILIAS exercise assignment.

ref_id: ref_id of the exercise object (e.g. Abgabe-Gruppe).
ass_id: assignment ID obtained from list_exercise_assignments.
local_path: absolute or home-relative path to the file to upload.
"""
app = _app(ctx)
try:
Comment thread
DenizAltunkapan marked this conversation as resolved.
Resolved
result = app.exercise_service.submit_file(
ref_id=ref_id, ass_id=ass_id, local_path=local_path
)
except (IliasAuthError, IliasExerciseError, OSError) as exc:
logger.warning(
"Exercise submission failed for ref_id=%s ass_id=%s: %s",
ref_id,
ass_id,
exc,
)
return {"status": "error", "message": str(exc)}

return {"status": "ok", **result}


@mcp.tool()
async def list_submitted_files(
ctx: Context[ServerSession, AppContext],
ref_id: str,
ass_id: str,
) -> dict[str, object]:
"""List all files already submitted for an exercise assignment, with their delivery IDs."""
app = _app(ctx)
try:
files = app.exercise_service.list_submitted_files(ref_id=ref_id, ass_id=ass_id)
except (IliasAuthError, IliasExerciseError) as exc:
logger.warning(
"List submitted files failed for ref_id=%s ass_id=%s: %s",
ref_id,
ass_id,
exc,
)
return {"status": "error", "message": str(exc), "files": []}
return {
"status": "ok",
"ref_id": ref_id,
"ass_id": ass_id,
"count": len(files),
"files": files,
}


@mcp.tool()
async def delete_submitted_files(
ctx: Context[ServerSession, AppContext],
ref_id: str,
ass_id: str,
delivery_ids: list[str],
) -> dict[str, object]:
"""Delete one or more submitted files by their delivery_id (from list_submitted_files).

delivery_ids: list of delivery_id strings to delete.
"""
app = _app(ctx)
try:
result = app.exercise_service.delete_submitted_files(
ref_id=ref_id, ass_id=ass_id, delivery_ids=delivery_ids
)
except (IliasAuthError, IliasExerciseError) as exc:
logger.warning(
"Delete submitted files failed for ref_id=%s ass_id=%s: %s",
ref_id,
ass_id,
exc,
)
return {"status": "error", "message": str(exc)}
return {"status": "ok", **result}


@mcp.tool()
async def list_team_members(
ctx: Context[ServerSession, AppContext],
ref_id: str,
ass_id: str,
) -> dict[str, object]:
"""List current team members for an exercise assignment submission team."""
app = _app(ctx)
try:
members = app.exercise_service.list_team_members(ref_id=ref_id, ass_id=ass_id)
except (IliasAuthError, IliasExerciseError) as exc:
logger.warning(
"Team listing failed for ref_id=%s ass_id=%s: %s", ref_id, ass_id, exc
)
return {"status": "error", "message": str(exc), "members": []}

return {
"status": "ok",
"ref_id": ref_id,
"ass_id": ass_id,
"count": len(members),
"members": [{"user_id": m.user_id, "name": m.name} for m in members],
}


@mcp.tool()
async def search_users(
ctx: Context[ServerSession, AppContext],
ref_id: str,
ass_id: str,
term: str,
) -> dict[str, object]:
"""Search ILIAS users by name or login fragment.

Returns login names that can be passed to add_team_member.
"""
app = _app(ctx)
try:
results = app.exercise_service.search_users(
ref_id=ref_id, ass_id=ass_id, term=term
)
except (IliasAuthError, IliasExerciseError) as exc:
logger.warning("User search failed term=%s: %s", term, exc)
return {"status": "error", "message": str(exc), "results": []}
return {"status": "ok", "term": term, "count": len(results), "results": results}


@mcp.tool()
async def add_team_member(
ctx: Context[ServerSession, AppContext],
ref_id: str,
ass_id: str,
username: str,
) -> dict[str, object]:
"""Add a user to the submission team by their ILIAS login name (e.g. st123456).

ref_id: ref_id of the exercise object.
ass_id: assignment ID from list_exercise_assignments.
username: ILIAS login name of the person to add.
"""
app = _app(ctx)
try:
result = app.exercise_service.add_team_member(
ref_id=ref_id, ass_id=ass_id, username=username
)
except (IliasAuthError, IliasExerciseError) as exc:
logger.warning(
"Add team member failed for ref_id=%s ass_id=%s user=%s: %s",
ref_id,
ass_id,
username,
exc,
)
return {"status": "error", "message": str(exc)}

return {"status": "ok", **result}


@mcp.tool()
async def remove_team_member(
ctx: Context[ServerSession, AppContext],
ref_id: str,
ass_id: str,
user_id: str,
) -> dict[str, object]:
"""Remove a user from the submission team by their ILIAS user_id.

user_id can be obtained from list_team_members.
"""
app = _app(ctx)
try:
result = app.exercise_service.remove_team_member(
ref_id=ref_id, ass_id=ass_id, user_id=user_id
)
except (IliasAuthError, IliasExerciseError) as exc:
logger.warning(
"Remove team member failed for ref_id=%s ass_id=%s user_id=%s: %s",
ref_id,
ass_id,
user_id,
exc,
)
return {"status": "error", "message": str(exc)}

return {"status": "ok", **result}


@mcp.resource("ilias://courses")
async def courses_resource(ctx: Context[ServerSession, AppContext]) -> str:
"""All enrolled ILIAS courses as a context document."""
Expand Down
Loading
Loading