Skip to main content
Glama
README.md
# campus-lens

**English** · [Español](README.es.md)

A read-only study assistant for any Moodle campus, built on [Claude Code](https://claude.com/claude-code).
It downloads your courses, materials, assignments and due dates, finds what changed since last time,
turns PDFs, Word and PowerPoint files into searchable Markdown, and lets Claude answer questions about
them, always citing the file and the page.

It **never submits anything**: the code can only call Moodle functions that read.

```
You → /due-soon → skill → MCP tool list_assignments → local SQLite → answer
```

## What your campus needs

It works with any Moodle that lets you log in **with a username and password through the mobile app**:

1. The **mobile API is turned on** (the official Moodle app works with your campus).
2. The login is **not SSO**: you type your password in a Moodle form, not on a Google, Microsoft or
   university page.

You do not need to find this out by hand. `setup_campus.py` asks Moodle, without logging in, through
the public `tool_mobile_get_public_config` function, and tells you if the campus cannot be used and
why.

## Installation

You need Python 3.12 or newer and, to use it with Claude, [Claude Code](https://claude.com/claude-code)
and [uv](https://docs.astral.sh/uv/) (Claude Code starts the MCP server with uv).

```bash
git clone https://github.com/Erbizo/campus-lens.git
cd campus-lens
uv sync                  # install the dependencies (uv's sync, not the campus one)
uv run setup_campus.py   # choose your campus and log in
```

Without uv, with your own Python (`py` on Windows, `python3` on macOS and Linux):

```bash
py -m pip install -e .        # installs the dependencies; -e keeps using this folder
py setup_campus.py
py -m campus.command_line courses
```

Every `uv run …` command in this README works the same as `py …` after that install.

`setup_campus.py`:

1. Asks for your campus address, for example `https://moodle.example.com`. Only `https` is accepted.
   If you already set up several campuses, you choose one by number.
2. Checks that the mobile API is on and the login has no SSO. Only then is the campus saved in
   `config.toml` (ignored by git) and made active.
3. Asks for your username and password with hidden input, exchanges them for a token and keeps
   **only the token**, in your system keyring. The password is never stored.
4. Checks that the campus offers the 6 functions the assistant needs. If it does, it says the
   connection was established successfully and shows the next steps; if not, it lists only the
   missing ones.

The next steps are: choose the courses to follow, open Claude Code, and synchronise. From the
command line it looks like this:

```bash
uv run -m campus.command_line courses                  # list your courses and their ids
uv run -m campus.command_line courses --follow 12 15   # follow those (replaces the selection)
uv run -m campus.command_line sync                     # download and extract
```

## Use from Claude Code

Open Claude Code in the project folder. It starts the `campus` MCP server by itself (accept it the
first time it asks). You can use the skills or just ask in your own words, in any language:

| Skill | What it does |
|---|---|
| `/sync` | Connects to the campus, downloads what is new and counts the changes. Only you can start it |
| `/whats-new [course]` | Summarises the changes you have not seen and asks whether to mark them as seen |
| `/due-soon` | Table of what is due in the next 5 days. The quick one |
| `/assignments [course]` | Every assignment not submitted, by urgency |

The MCP server offers six tools: `sync_campus`, `list_changes`, `list_assignments`,
`assignment_details`, `search_materials` and `read_material`. Only `sync_campus` uses the network;
the rest read what is already on your computer.

Example questions: *"Where do my notes explain photosynthesis?"*, *"What does the lab report ask for
and when is it due?"*

## Use from the command line

Everything works without Claude too:

| Command | What for |
|---|---|
| `uv run setup_campus.py` | Choose or add a campus and log in. Run it again when the token expires |
| `uv run -m campus.command_line courses [--follow ID ...]` | List your courses and choose which to follow |
| `uv run -m campus.command_line sync` | Synchronise the courses you follow |
| `uv run -m campus.command_line changes [--mark-seen]` | Changes not seen yet |
| `uv run -m campus.command_line assignments` | Assignments and other dates |
| `uv run -m campus.command_line extract [--all]` | Redo the Markdown (sync already does it) |

## Architecture

```
                 ┌──────────────────────── Claude Code ─────────────────────────┐
                 │  skills (.claude/skills)  →  MCP server (mcp_server/)        │
                 └──────────────────────────────────┬───────────────────────────┘
 setup_campus.py      campus/command_line.py        │
        │                     │                     │
        ▼                     ▼                     ▼
 ┌──────────────────────────── campus/ (library) ──────────────────────────────┐
 │ campus_config   active campus, config.toml, one folder per campus           │
 │ authentication  username+password → token → system keyring                 │
 │ moodle_client   REST client: allow list of read functions, no redirects     │
 │ course_sync     courses, materials, assignments, dates → changes            │
 │ text_extraction PDF, DOCX, PPTX, ODT, HTML, ZIP → Markdown with pages       │
 │ local_database  SQLite                                                      │
 └─────────────────────────────────────────────────────────────────────────────┘
        │ HTTPS (only sync, courses and setup)
        ▼
   Moodle campus

 campuses/<campus>/state.db   courses, assignments, dates and changes
 campuses/<campus>/files/     original files, by course, in Assignments/ and Materials/
 campuses/<campus>/text/      the same in Markdown, with "## Page N" to cite them
```

Synchronisation and change detection are deterministic (Python + SQLite, no LLM). Claude only
summarises, explains and searches. Search is literal, over the Markdown files, ignoring accents and
capitals: no embeddings, no RAG.

Each campus has its own folder, database and token, so you can use several campuses without
mixing them up. `setup_campus.py` switches the active one, and the MCP server picks up the change
without restarting.

## Security decisions

- **It never submits work.** `MoodleClient` only accepts the 6 functions in `ALLOWED_FUNCTIONS`, all of
  them read-only. Any other call fails before reaching the network, and a test checks it.
- **The password is never stored.** It is typed with `getpass`, sent by POST (never in the URL) and
  exchanged for a token. The `privatetoken` Moodle returns, which could open a web session, is thrown
  away.
- **The token lives only in the system keyring**, stored under the campus address.
- **The token only goes to the configured campus.** Redirects are not followed, `https` is mandatory,
  and files are only downloaded if their URL starts with the campus' own `/webservice/pluginfile.php/`,
  computed from the HTTP client itself. If someone edits `config.toml` to point elsewhere, that address
  has no token in the keyring, so there is nothing to send.
- **No data about classmates.** Forums, chats, wikis, glossaries, workshops, participants and messages
  are not synchronised. Authors, user ids, grades and feedback are dropped before saving.
- **Gentle with the campus:** a 1-second pause between requests and an honest User-Agent:
  `campus-lens/0.1 personal use`.
- **Downloads are never run or unzipped to disk.** ZIP files are read in memory, with limits on number
  of files and size, and encrypted entries are skipped. Office files are size-checked before opening.
- **Campus content is data, not instructions.** The MCP server and the skills say so to Claude, and
  `read_material` can only read `.md` files inside the active campus' `text/` folder.
- **No browser and no desktop control.** `.claude/settings.json` denies them to Claude in this project,
  so nothing can be submitted that way either.

## Limitations

- Campuses that require SSO (Google, Microsoft, CAS, SAML…) or have the mobile API turned off are not
  supported.
- Dates and statuses are those of the **last synchronisation**.
- Scanned PDFs and images cannot be searched. Their `.md` says `OPEN THE ORIGINAL`.
- Formats that are not extracted (images, `.dwg`, videos…) stay as original files.
- Search is literal: it does not understand synonyms.
- The keyring needs a backend: Windows Credential Manager, macOS Keychain, or a running Secret
  Service (GNOME Keyring, KWallet) on Linux.

## Try it with another campus

1. Run `uv run setup_campus.py` and type the address of the new campus.
2. If it says the mobile API is off or the login is SSO, that campus cannot be used. Nothing is saved.
3. If it works, follow some courses, run `sync`, and open Claude Code to ask `/due-soon`.
4. To go back to another campus, run `setup_campus.py` again and pick it by number.

If you do not have an account on a second campus, a public Moodle demo site (see
[moodle.org/demo](https://moodle.org/demo)) may work, if it allows the mobile app login.
`setup_campus.py` will tell you.

## Tests

```bash
uv run pytest
# or, without uv: py -m pip install pytest, then py -m pytest
```

They use no network, no real keyring and no real configuration: Moodle is simulated with
`httpx.MockTransport`, and `tests/conftest.py` makes any test fail if it touches the real keyring
or network.

## License

[MIT](LICENSE)