darkspace
by gmntl
README.md
# darkspace
darkspace is an MCP server for D2L Brightspace. It uses the Brightspace Valence REST API to read your courses, content, assignments, grades and calendar. The default site is `https://purdue.brightspace.com`.
> [!WARNING]
> This project is vibe coded. An AI wrote most of the code, and nobody audited it. Use it at your own discretion and risk.
>
> darkspace is not affiliated with, endorsed by or supported by Purdue University, D2L or Microsoft. The author does not endorse any use of it. Before you use it, make sure that your use obeys the rules of your school, including its acceptable use policy, and the terms of the services that darkspace connects to.
>
> You alone are responsible for how you use this software. The author is not responsible or liable for damage, data loss, account suspension, disciplinary action or other consequences that come from its use. The software is provided "as is", without warranty of any kind. See [LICENSE](LICENSE).
## Tools
| Tool | Function |
| --- | --- |
| `whoami` | Shows the user of the credentials. |
| `list_courses` | Lists your courses. Other tools use the `course_id` from this list. |
| `get_upcoming` | Lists calendar events across your courses: due dates, quizzes and events. |
| `get_announcements` | Lists the announcements of a course. |
| `get_course_content` | Shows the modules and topics of a course. |
| `get_topic` | Shows one content topic. |
| `download_topic_file` | Downloads the file of a topic to the disk of the computer that runs darkspace. |
| `list_assignments` | Lists assignments with instructions, due dates and your submission status. |
| `get_grades` | Shows your released grades and your final grade. |
| `list_quizzes` | Lists quizzes with dates, attempts and time limits. |
| `list_discussions` | Lists discussion forums and topics. |
| `get_discussion_posts` | Shows the posts of a discussion topic. |
| `api_get` | Sends a GET request to a Valence API route. Use it when no other tool fits. |
All tools only read data from Brightspace.
## How the login works
Brightspace does not have personal access tokens. darkspace logs in through the Purdue single sign-on (Brightspace, then `sso.purdue.edu`, then Microsoft) in a dedicated headless Chromium. It keeps the Brightspace session cookies. When Brightspace stops accepting them, darkspace logs in again and repeats the request.
darkspace can sign in to Microsoft in two ways:
- **With an imported passkey.** darkspace gives the passkey to a virtual authenticator in Chromium and completes the sign-in itself. Use this on a server.
- **Interactively.** You sign in once in a browser window. After that, darkspace uses the saved Microsoft session. When the Microsoft session expires, you must sign in again.
## Make a passkey for the server
Make a separate passkey for darkspace. Do not export the passkey that you use every day. With a separate passkey, you can remove the server's access and keep your own passkey.
1. In Bitwarden, make a new login item, for example `Purdue (darkspace server)`.
2. Go to https://mysignins.microsoft.com/security-info and sign in.
3. Select **Add sign-in method**, then **Passkey**.
4. When Bitwarden asks where to save the passkey, select the new item.
5. Export the item: `bw get item "Purdue (darkspace server)" > passkey.json`.
6. Give `passkey.json` to the server (see below). Then delete the local copy.
> **Warning:** The passkey lets anyone who has it sign in to your Purdue account. Keep the file secret. If the server is compromised, remove the passkey in Microsoft **Security info**.
darkspace supports only P-256 (ES256) passkeys. Bitwarden makes this type.
## Run on a NixOS server
Add the flake to your system configuration:
```nix
{
inputs.darkspace.url = "github:gmntl/darkspace";
outputs = { nixpkgs, darkspace, ... }: {
nixosConfigurations.server = nixpkgs.lib.nixosSystem {
modules = [
darkspace.nixosModules.default
{
services.darkspace = {
enable = true;
tokenFile = "/run/agenix/darkspace-token"; # openssl rand -hex 32
passkeyFile = "/run/agenix/darkspace-passkey"; # passkey.json from Bitwarden
};
}
];
};
};
}
```
The service listens on `127.0.0.1:8765` at the path `/mcp`. Put it behind Tailscale or a reverse proxy with HTTPS. Set `host` and `openFirewall` only if the network is trusted.
| Option | Default | Description |
| --- | --- | --- |
| `url` | `https://purdue.brightspace.com` | The Brightspace site. |
| `host`, `port` | `127.0.0.1`, `8765` | The address of the HTTP server. |
| `tokenFile` | (required) | The bearer token, 32 or more characters. |
| `passkeyFile` | `null` | The passkey as Bitwarden JSON. |
| `openFirewall` | `false` | Opens the port. |
| `environment` | `{ }` | More environment variables. |
The service keeps its state in `/var/lib/darkspace`. If a login fails, darkspace saves a screenshot to `/var/lib/darkspace/login-failure.png`. Read the log with `journalctl -u darkspace`.
## Connect a client
Claude Code:
```sh
claude mcp add --transport http darkspace https://<server>/mcp \
--header "Authorization: Bearer <token>"
```
Other clients must send the same `Authorization` header.
## Run on your computer
1. Install Nix with flakes and direnv.
2. In the project folder, run `direnv allow`.
3. Run `uv sync`.
4. Run `uv run playwright install chromium`.
5. Log in with one of these procedures:
- Passkey: `bw get item "Purdue (darkspace server)" | uv run darkspace passkey import`, then `uv run darkspace login`.
- Interactive: `uv run darkspace login`. Sign in in the window. When Microsoft asks "Stay signed in?", select **Yes**.
6. Run `uv run darkspace status` to make sure that the login is correct.
Use stdio for a local client:
```sh
claude mcp add darkspace -- uv --directory /path/to/darkspace run darkspace
```
Or use HTTP: `DARKSPACE_HTTP_TOKEN=<token> uv run darkspace serve --http`.
If direnv cannot find `flake.nix`, add the files to Git: `git add -N flake.nix flake.lock nix`. Nix flakes ignore files that Git does not track.
## Commands
| Command | Function |
| --- | --- |
| `darkspace` or `darkspace serve` | Runs the MCP server on stdio. |
| `darkspace serve --http [--host H] [--port P] [--path /mcp]` | Runs the MCP server on Streamable HTTP. |
| `darkspace login [--show]` | Logs in. With a passkey, there is no window unless you give `--show`. |
| `darkspace status` | Shows the logged-in user. |
| `darkspace passkey import [FILE]` | Imports a passkey from Bitwarden JSON. The default input is stdin. |
| `darkspace passkey remove` | Deletes the imported passkey. |
| `darkspace logout` | Deletes the session and the browser profile. |
## Configuration
All variables are optional, except a token for HTTP.
| Variable | Description |
| --- | --- |
| `BRIGHTSPACE_URL` | The URL of the Brightspace site. The default is `https://purdue.brightspace.com`. |
| `DARKSPACE_HTTP_TOKEN`, `DARKSPACE_HTTP_TOKEN_FILE` | The bearer token for HTTP, or a file that contains it. |
| `DARKSPACE_PASSKEY_FILE` | A passkey as Bitwarden JSON. It has priority over `darkspace passkey import`. |
| `BRIGHTSPACE_TOKEN` | An OAuth 2.0 access token. It has priority over the login. darkspace does not refresh it. |
| `BRIGHTSPACE_COOKIE` | Session cookies in the format `d2lSessionVal=...; d2lSecureSessionVal=...`. darkspace does not refresh them. |
| `BRIGHTSPACE_BROWSER` | A Chromium-based browser executable for the login. |
| `BRIGHTSPACE_DOWNLOAD_DIR` | The folder for downloads. The default is `~/Downloads/darkspace`. |
| `BRIGHTSPACE_LP_VERSION`, `BRIGHTSPACE_LE_VERSION` | The API versions. darkspace finds the latest versions if you do not set them. |
| `XDG_STATE_HOME` | darkspace keeps its state in `$XDG_STATE_HOME/darkspace`. The default is `~/.local/state/darkspace`. |
## Development
```sh
uv run pytest
ruff check .
ruff format .
nix build .#default
```
The tests do not connect to Brightspace or Microsoft. They use a mock HTTP transport and fake sign-in pages in a local Chromium.
## API reference
https://docs.valence.desire2learn.com/reference.html
## License
MIT. See [LICENSE](LICENSE).
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues