canvas-mcp
# canvas-mcp
A read-only cache of your [Canvas LMS](https://www.instructure.com/canvas)
courses, served to AI assistants over the
[Model Context Protocol](https://modelcontextprotocol.io). Point Claude,
ChatGPT or any MCP client at it and ask "what's due this week?", "what do I
need on the final for a B?" or "find the lecture on molecular orbitals".
It is plain Python (standard library plus one vendored, hash-pinned wheel),
built to run as a small Kubernetes pod but usable anywhere.
## What it does
- **Syncs on a schedule** (default 30 minutes) with your personal Canvas API
token: courses, grades, assignment groups and rubrics, submission comments,
modules, pages, announcements, calendar events, missing work and course
files. Hidden Files/Pages tabs are worked around by following module items
and links in the syllabus, pages and assignments. Every request is a `GET`;
the token is sent only to your Canvas host and never to file-download
redirects.
- **Keeps an archive**: courses that leave your active list at the end of a
term stay in the cache, with their files.
- **Serves MCP tools** that read only the cache, never Canvas: upcoming and
missing work, grades and grade projection, exams, calendar, feedback,
syllabus, pages, modules, files and search. Nothing can submit, message or
change anything in Canvas.
- **Extracts and indexes documents**: text from PDFs (via `pypdf`) and text
files, searchable by keyword and by meaning (hybrid search with a small
static embedding model, no GPU or model server).
- **Optionally notifies** through [ntfy](https://ntfy.sh), only about what
Canvas does not tell you itself: a morning digest of work due in 48 hours,
newly missing work, letter-grade cutoff crossings and exam reminders.
## Tools
| Tool | Purpose |
| --- | --- |
| `canvas_status` | Last sync time and whether the token still works |
| `list_courses` | Credit courses and current scores |
| `get_upcoming_assignments` | Work due in the next N days, with state, platform and completion |
| `get_missing_assignments` | Work Canvas marks missing |
| `get_grades` | Scores per course or per assignment |
| `project_grade` | Average needed on remaining work per letter cutoff |
| `get_recent_announcements` | Announcements |
| `get_recent_changes` | Pages, files, assignments, grades and announcements changed recently |
| `get_course_modules` | Course structure, filterable by module or week |
| `get_page`, `get_syllabus` | Page and syllabus text with resolved links |
| `get_assignment` | Instructions, rubric with your scores, feedback, submission status |
| `get_feedback` | Recent instructor comments and rubric notes |
| `get_exam_schedule`, `get_calendar` | Exams (from the calendar, assignments and syllabus text) and one timeline |
| `list_course_files`, `read_course_file` | Files, as documents or extracted text by page |
| `search_course_materials` | Hybrid keyword + semantic search with page citations |
Every result carries `synced_at` and is returned both as JSON text and as MCP
`structuredContent`.
### Facts, inferences and unknowns
Tools keep three things apart, so an agent does not present a guess as fact:
- **Assignment state** is graded, graded but hidden, submitted and ungraded,
missing, past due with unknown status, or upcoming. Work done outside Canvas
(Gradescope, PrairieLearn, a Google Form) has `completion: "unknown"`, never
"nothing to do".
- **Grade projections** separate graded, remaining and unknown work. They
apply Canvas drop rules and accept syllabus policy that Canvas lacks
(`group_weights`, `group_rules`, `future_work`), and report
`projection_complete` only when nothing is unknown.
- **Exam dates** read from syllabus text are marked `confidence: "syllabus
text"` with their sources. The year comes from the text or the page title
before the term, and stated weekdays are checked. `coverage` says what was
searched: no exams found does not mean no exams.
## Running it
```sh
# 1. Sync (needs a Canvas token in $CANVAS_CREDENTIALS/token)
CANVAS_BASE_URL=https://canvas.example.edu \
CANVAS_CREDENTIALS=./credentials CANVAS_DATA=./data CANVAS_DEPS=./vendor \
python app/canvas_sync.py once
# 2. Serve MCP over stdio for a local client
CANVAS_DATA=./data python app/canvas_mcp.py
```
For Claude Code: `claude mcp add canvas -- python /path/to/app/canvas_mcp.py`
(with `CANVAS_DATA` set). `python app/canvas_sync.py serve` keeps syncing and
exposes Prometheus metrics on port 9464 (`/metrics`, `/healthz`).
### Remote clients (ChatGPT)
`python app/canvas_mcp.py serve-http` serves streamable HTTP on `POST /mcp`
(port `CANVAS_MCP_PORT`, default 8080). It is meant to sit behind
[Cloudflare Access](https://developers.cloudflare.com/cloudflare-one/access-controls/applications/http-apps/managed-oauth/)
with managed OAuth. Every request must carry an Access JWT, which the server
verifies itself (RS256 against the team's keys, issuer, expiry, allowed
emails). Set `CANVAS_ACCESS_TEAM` (e.g. `yourteam.cloudflareaccess.com`) and
`CANVAS_ACCESS_EMAILS`, and optionally `CANVAS_ACCESS_AUD`.
For ChatGPT, allow both of its OAuth callbacks in the Access app's dynamic
client registration: `https://chatgpt.com/connector_platform_oauth_redirect`
and `https://chatgpt.com/connector/oauth/*`. Access does not advertise RFC 9207
issuer identification, so ChatGPT uses the per-connection one.
### Configuration
| Variable | Default | Meaning |
| --- | --- | --- |
| `CANVAS_BASE_URL` | `https://canvas.wisc.edu` | Your Canvas host |
| `CANVAS_CREDENTIALS` | `/credentials` | Directory with `token` and optional `expires` (YYYY-MM-DD) |
| `CANVAS_DATA` | `/data` | Cache directory |
| `CANVAS_SYNC_INTERVAL` | `1800` | Seconds between syncs |
| `CANVAS_MAX_FILE_MB`, `CANVAS_FILES_BUDGET_GB` | `50`, `8` | Download limits |
| `CANVAS_DEPS` | `/deps` | Directory with `vendor/` contents (pypdf) |
| `CANVAS_MODEL` | `$CANVAS_DATA/models/potion-base-8M` | Embedding model, downloaded once and hash-checked |
| `CANVAS_NTFY_URL`, `CANVAS_NTFY_TOKEN_FILE` | unset, `/ntfy/token` | ntfy topic URL and token; notifications are off without a URL |
Defaults lean toward UW–Madison (base URL, letter scale A 93 / AB 88 / B 83 /
BC 78 / C 70, subject aliases such as `CS 354` → COMPSCI). Pass `targets` to
`project_grade` for other scales.
Student API tokens may be short-lived. With `CANVAS_CREDENTIALS/expires` set,
the metrics expose the expiry, so you can alert before it lapses. The token
file is re-read every cycle, so rotating it needs no restart.
## Supply chain
- Runtime dependencies are the Python standard library plus
`vendor/pypdf-7.1.0-py3-none-any.whl`. Its SHA-256 is pinned in
`vendor/manifest.json` and checked before import.
- The embedding model ([`minishlab/potion-base-8M`](https://huggingface.co/minishlab/potion-base-8M),
MIT) is fetched from a fixed revision and refused if either file's SHA-256
differs (`FILES` in `app/canvas_semantic.py`). No neural network runs at
query time: a text's vector is the normalized mean of its WordPiece tokens'
rows.
## Development
```sh
python -m unittest discover -s tests -v
```
The tests are offline: Canvas, ntfy, Cloudflare Access and the embedding
model are all faked. A tiny generated model checks the tokenizer and index,
and a throwaway RSA key checks JWT verification.
## License
MIT
TDQS
Scored across 18 tools
Most tools target distinct resources (courses, grades, modules, pages, files, syllabus, feedback, exams), and descriptions actively disambiguate near-neighbors like get_recent_changes vs get_recent_announcements or get_assignment vs get_missing_assignments. The main overlap is among the time-window tools (get_upcoming_assignments, get_calendar, get_exam_schedule, get_missing_assignments), which a careful agent can separate but could occasionally misselect.
Strong, predictable snake_case verb_noun pattern throughout (list_courses, get_assignment, read_course_file, search_course_materials). Only minor deviations break the pattern: canvas_status (noun-only) and project_grade (verb without a clear get_ prefix).
At 18 tools the set is on the high end of the comfortable band, but each tool maps to a distinct Canvas surface (courses, assignments, grades, files, pages, modules, exams, calendar, search, status). No tool appears redundant filler, so the count is justified for an LMS domain.
Coverage is broad for a read-only student workflow: courses, assignments, grades and projections, modules, pages, syllabus, files, cross-material search, exams, calendar, feedback, and sync status. The notable gap is the absence of any write/submission actions (submit assignment, post, mark done), so lifecycle coverage is complete for reading but not for acting.