# campus-usc

> The USC's Campus Virtual (Moodle) in the terminal and for AI agents: one HTTP engine behind a 30 ms CLI and a 94-tool MCP server, with no browser to download.

- Role: Solo project
- When: Aug 2026 – present
- Stack: Python, httpx, BeautifulSoup, Chrome DevTools Protocol, MCP, keyring, Playwright, GitHub Actions, uv
- Links: [Source on GitHub](https://github.com/PabloPC05/campus-usc)
- Image: [Diagram: campus and mcp-usc are two faces of the campus-usc-core engine, which reads the USC's Campus Virtual over internal AJAX and HTML pages, with timetables and exams from usc.gal; logging in uses your own browser over the DevTools protocol.](https://ppardocotos.com/_astro/campus-usc.en.DlTHo8uc.svg)
- URL: https://ppardocotos.com/projects/campus-usc

The University of Santiago de Compostela runs its Campus Virtual on Moodle with no student API. **campus-usc** talks HTTP just like a browser and exposes two thin interfaces over one engine: a fast terminal CLI for people (`campus`) and a 94-tool MCP server for AI agents. Open source (MIT) and unofficial, with no affiliation to the university.

<div class="cifras">
<div class="cifra"><strong>~30 ms</strong><span>per screen</span><small>cached (~1.8 s fresh · ~2.2 s web)</small></div>
<div class="cifra"><strong>0 MB</strong><span>extra browser</span><small>reuses installed Chrome/Edge/Brave</small></div>
<div class="cifra"><strong>94</strong><span>MCP tools</span><small>over the same engine as the CLI</small></div>
<div class="cifra"><strong>3 OSes</strong><span>verified in CI</span><small>Linux, macOS and Windows</small></div>
</div>
<p class="pie-grafico">Tested live across Computer Science, Mathematics and Medicine, and verified end to end with a second real student account.</p>

## Three design decisions

<div class="decisiones una-col">
<div class="decision">
<div class="cab"><b>1. No official API → direct HTTP (AJAX + HTML)</b><span class="tag ok">Same footprint as the web</span></div>
<p>Moodle's mobile API is disabled at the USC. The engine uses the web session to call internal AJAX endpoints (courses, assignments, files, messages) and parses HTML only where Moodle offers no structured data (grades, forums, quizzes). Timetables and exam dates are fetched on demand from public <code>usc.gal</code> pages for any degree, including phased-out study plans.</p>
</div>
<div class="decision">
<div class="cab"><b>2. 2FA sign-in without downloading a browser</b><span class="tag ok">Silent renewal</span></div>
<p>Instead of bundling a 160 MB Chromium download, it drives an existing Chromium browser (Chrome, Edge, Brave, Chromium or Helium) over DevTools in an isolated profile that never touches your tabs or passwords, grabs only the session cookie and renews headless afterwards. Playwright remains an optional fallback.</p>
</div>
<div class="decision">
<div class="cab"><b>3. Instant cache and safe writes by default</b><span class="tag ok">Preview + confirmation</span></div>
<p>The CLI paints from local cache and refreshes stale data in the background, firing network calls concurrently over one session. Every write (submitting work, sending messages) requires a preview and a single-use confirmation token, and Campus output is stripped of terminal control characters.</p>
</div>
</div>

## Architecture

A four-package monorepo: the HTTP engine (`campus-usc-core`), the CLI (`campus`), the MCP server (`mcp-usc`) and the optional timetables-and-exams module. A single-command installer detects OS and browser before touching anything, with CI across Linux, macOS and Windows (Python 3.11 and 3.14).
