Smartschool MCP
by Renefffes
README.md
# Smartschool MCP
<!-- mcp-name: io.github.MauroDruwel/smartschool-mcp -->
A lean, very fast [Model Context Protocol](https://modelcontextprotocol.io) core for Smartschool, built to run on tiny machines (0.1 vCPU, 512 MB RAM).
It has one tool, `download_course`, on top of a small core: the MCP protocol (stdio and Streamable HTTP), a lazily created, TTL-cached and login-guarded Smartschool session, and a tool registry.
## `download_course`
Ask your agent something like *"download de volledige cursus van nrt"*. In one call the tool:
1. finds the course by name, part of the name, abbreviation (`nrt`), id, or a close typo;
2. lists all Documenten folders in parallel and starts each download as soon as its folder is listed (`MCP_DOWNLOAD_WORKERS` connections, default 8);
3. returns the files inside the tool result: a JSON summary (paths, sizes, web links), then each file as an MCP embedded resource (images as `image`, text as `text`, everything else base64 `blob`).
Nothing is written to the server's disk; the files end up in the agent's context. Arguments: `course` (required), `document` (only files whose folder or name contains these words, e.g. `"hoofdstuk 3"`), `max_mb` (default 40, max 60, so the reply fits in 512 MB RAM).
Set `SMARTSCHOOL_PREWARM=1` so the library import and login happen at startup instead of during the first call.
## Why it is fast
- **No heavy dependencies.** The MCP protocol is implemented in about 250 lines of standard-library Python: no pydantic, anyio, starlette or uvicorn. Runtime dependencies are `smartschool` and `lxml` (fast HTML parsing).
- **Lazy loading.** The `smartschool` library is imported, and the login happens, only when a tool first asks for a session. Startup imports about 6 ms of modules.
- **Prebuilt hot path.** `initialize`, `ping` and `tools/list` are answered from objects built once.
- **Small HTTP server.** Plain sockets, one thread per keep-alive connection, `TCP_NODELAY`, compact JSON.
- **Non-blocking stdio.** Tool calls run in a small thread pool, so a slow Smartschool request never delays a `ping`.
Measured in Docker with `--cpus=0.1 --memory=512m` (Python 3.12):
| | v0.3.0 | v0.4.0 |
|---|---|---|
| stdio cold start to `initialize` reply | 10.5 s | 0.2–0.3 s |
| HTTP cold start | 11.3 s | 0.5 s |
| HTTP `tools/list` p50 / p95 | 2.0 / 98 ms | 0.1 / 0.9 ms |
| HTTP throughput (one keep-alive client) | 34 req/s | 407 req/s |
| Peak RSS (stdio / HTTP) | 85 / 85 MB | 11 / 17 MB |
## Adding a tool
```python
from smartschool_mcp.server import ToolError, mcp, session
@mcp.tool(
description="List enrolled courses.",
input_schema={"type": "object", "properties": {}},
annotations={"readOnlyHint": True},
)
def get_courses() -> dict:
from smartschool import Courses # import heavy modules inside the tool
return {"courses": [course.name for course in Courses(session())]}
```
- Return a `dict` (sent as text plus `structuredContent`), a list or a string.
- Raise `ToolError("...")` for a clean error result; any other exception is caught and reported as `isError`.
- Without `input_schema`, the schema is built from the signature (`int`, `str`, `bool`, `float`, `list`, `dict`, optional `| None`).
- Register tools in a module imported by `smartschool_mcp/server.py` (or in it).
## Quick start: Claude Desktop
With the extension (see above), Claude Desktop needs [uv](https://docs.astral.sh/uv/) on your computer to run it. Or install it from PyPI:
```bash
uvx mcp install smartschool-mcp \
-e SMARTSCHOOL_USERNAME="you" \
-e SMARTSCHOOL_PASSWORD="secret" \
-e SMARTSCHOOL_MAIN_URL="school.smartschool.be" \
-e SMARTSCHOOL_MFA="YYYY-MM-DD"
```
Or add it manually to `claude_desktop_config.json`:
```json
{
"mcpServers": {
"smartschool": {
"command": "uvx",
"args": ["smartschool-mcp"],
"env": {
"SMARTSCHOOL_USERNAME": "you",
"SMARTSCHOOL_PASSWORD": "secret",
"SMARTSCHOOL_MAIN_URL": "school.smartschool.be",
"SMARTSCHOOL_MFA": "YYYY-MM-DD"
}
}
}
}
```
Config file locations: `%APPDATA%\Claude\claude_desktop_config.json` (Windows) · `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) · `~/.config/Claude/claude_desktop_config.json` (Linux)
## Remote / claude.ai
## Remote (Streamable HTTP)
```bash
export SMARTSCHOOL_USERNAME="..." SMARTSCHOOL_PASSWORD="..."
export SMARTSCHOOL_MAIN_URL="school.smartschool.be" SMARTSCHOOL_MFA="YYYY-MM-DD"
export MCP_API_KEY="a-long-random-secret" # recommended
smartschool-mcp --transport streamable-http --host 0.0.0.0 --port 8000
```
The endpoint is `http://HOST:PORT/mcp` (stateless, JSON responses); `GET /health` answers `{"status":"ok"}` without auth. Put it behind HTTPS (Caddy, nginx, Cloudflare Tunnel) and add it to your client with the header `Authorization: Bearer <MCP_API_KEY>`.
## Environment variables
| Variable | CLI flag | Default | Description |
|----------|----------|---------|-------------|
| `MCP_TRANSPORT` | `--transport` | `stdio` | `stdio` or `streamable-http` |
| `MCP_HOST` | `--host` | `0.0.0.0` | Bind address (HTTP) |
| `MCP_PORT` | `--port` | `8000` | Port (HTTP) |
| `MCP_API_KEY` | | | Require `Authorization: Bearer <key>` (HTTP) |
| `MCP_ALLOWED_HOSTS` | | | Comma-separated `Host` header allow-list (HTTP) |
| `MCP_WORKERS` | | `4` | Tool-call threads (stdio) |
| `MCP_DOWNLOAD_WORKERS` | | `8` | Parallel Smartschool connections for `download_course` |
| `SMARTSCHOOL_PREWARM` | | off | `1`: import `smartschool` and log in in the background at start |
| `SESSION_TTL_SECONDS` | | `3600` | Rebuild the Smartschool session after this many seconds |
| `SMARTSCHOOL_USERNAME` | | | Smartschool username |
| `SMARTSCHOOL_PASSWORD` | | | Smartschool password |
| `SMARTSCHOOL_MAIN_URL` | | | School address, e.g. `school.smartschool.be` |
| `SMARTSCHOOL_MFA` | | | Birth date (`dd-mm-yyyy` or `YYYY-MM-DD`) or a TOTP secret |
## Login safety
Settings are checked before the first login, so a typo never costs a login attempt. A password Smartschool rejects is posted only once: an `auth_failed` marker next to the session cache blocks further attempts until you delete it, because Smartschool locks an account after a few failed logins. Credentials are only ever posted to the school's own host over HTTPS.
## Development
```bash
uv sync --extra dev
uv run pytest
uv run ruff check . && uv run ruff format --check .
uv run mypy smartschool_mcp/
```
## Disclaimer
Unofficial tool, not affiliated with Smartschool. Use in accordance with your school's terms of service.
TDQS
A4.1/5.0
Scored across 1 tool
Disambiguation5/5
With only a single tool, there is no possibility of confusion between tools. The one tool has a clearly stated purpose.
Naming Consistency4/5
The name download_course follows a clean verb_noun snake_case convention. With only one tool there is no pattern to break, but it is a readable, conventional name.
Tool Count2/5
A single tool for a whole platform integration (Smartschool courses, documents, presumably grades/messages) is very thin. The domain implies many more operations than one download endpoint.
Completeness2/5
Only downloading course documents is supported, with no way to list courses, browse folders, or access other Smartschool data. Agents cannot discover courses or perform any lifecycle operations beyond a single bulk fetch.
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues