Skip to main content
Glama
README.md
# canvas-mcp

Read-only Canvas access for one student, as a CLI and an MCP server.

## Description

Canvas has a full REST API, but some schools disable the personal access
tokens that normally unlock it. `canvas-mcp` reads the `canvas_session` cookie
that Firefox already holds and uses it for `GET` requests only. An agent can
then answer questions about coursework: what is due, what is still owed, what
a course holds, and where its files are on the disk.

One core, `canvas_mcp.Canvas`, does the work. The `canvas` CLI and the
`canvas-mcp` stdio server each register the same operations and add no logic.

The client cannot write to Canvas. Its authenticated transport refuses any
request that is not a `GET` over `https` to the configured host.

## Getting Started

### Dependencies

* Linux and Firefox, with Canvas open in a normal (non-private) window.
* Firefox session restore, so that `browser.startup.page` is `3`. Firefox only
  saves session cookies to disk with this setting.
* [uv](https://docs.astral.sh/uv/) and Python 3.11 or later.

### Installing

```sh
git clone https://github.com/ramirc0/canvas-mcp
cd canvas-mcp
uv sync
```

Set the Canvas host name. It MUST match the host exactly.

```sh
export CANVAS_HOST=school.instructure.com
```

Two optional variables:

* `CANVAS_TOKEN`: a personal access token. It takes precedence over the cookie.
* `CANVAS_ICS_URL`: the calendar feed URL from Canvas, under Calendar, Calendar
  Feed. It backs `canvas calendar`. Treat it as a password.

### Executing program

From the command line:

```sh
uv run canvas courses
uv run canvas due --until 2026-12-31
uv run canvas mirror 101
uv run canvas raw '/api/v1/users/self'
```

As an MCP server, for example in a `.mcp.json`:

```json
{
  "mcpServers": {
    "canvas": {
      "command": "uv",
      "args": ["run", "--project", "/path/to/canvas-mcp", "canvas-mcp"],
      "env": { "CANVAS_HOST": "school.instructure.com" }
    }
  }
}
```

`skill/SKILL.md` tells an agent which CLI command answers which question.

Course files are mirrored to `~/Canvas/<course id>-<code>/`. They are untrusted
input. Do not execute anything from that tree.

## Help

```sh
uv run canvas --help
uv run canvas due --help
```

* `StaleSession`: log into Canvas in Firefox again.
* `MissingCookie`: open Canvas in a non-private Firefox window and wait about
  15 seconds for Firefox to save its session. The message lists the profiles
  searched and whether session restore is on.
* `NotPermitted`: Canvas denies your account that resource.
* The mirror skips a file when its module requires you to view it. Open it in
  Canvas once, then run the mirror again.

## Authors

Christian Ramirez

## License

This project is licensed under the MIT License - see the LICENSE file for details

## Acknowledgments

* [yt-dlp](https://github.com/yt-dlp/yt-dlp), for the idea of reading cookies
  from the browser at call time.
* [lucanardinocchi/canvas-mcp](https://github.com/lucanardinocchi/canvas-mcp),
  a token-based Canvas MCP server that showed which questions students ask.