Every area — courses, rooms, boards, topics, tasks, files, quizzes, teams,
groups, submissions, grades — was checked for data the instance has and the
tools did not show.
Grades and feedback. A teacher's /homework page is a different page from a
student's: grade and comment live in the grading form, one block per
submission, so a teacher account reported every graded submission as having
neither. parseTeacherGrading reads the form, and list_submissions can now
include the written feedback and who handed the work in.
Names. /api/v1 is partly served: courses, users and classes survive in the
deployment's ingress table, and users/{id} is the only route from an id to a
name. Submitters, file creators and course teachers resolve through it, and
degrade to "not visible to this account" where a student may not read them.
Courses, rooms and classes. get_course adds the description, teachers,
member count and weekly timetable from /api/v1/courses. list_classes is new.
get_room reports what the account may do — allowedOperations is an object of
booleans, not the list it was typed as — and applicants and invitation links
where it may manage them.
Board and topic content. Link descriptions, image alt text, drawing and
video-conference titles, the ids behind external tools and H5P content (the
only thing resembling a quiz), and what a deleted element used to be. Topic
Etherpad pads are read like board pads, and htmlToText keeps table columns
apart and drops template indentation.
Files. A scan with no text layer falls back to the preview endpoint, whose
width and outputFormat are undocumented enums, so Claude gets a picture of
the page; list_files reports counts and sizes. Teams stay documented as
unreadable at any API version; their files come later.
What the crawl missed. Tasks attached to topics (18 of 60 on the live
account), each course's own file area, and — behind INDEX_PERSONAL_FILES —
personal files and submissions with their grade comments, so search and
what_changed cover grading. A submission hit points at get_task.
The local instance's preview profile gets an ImageMagick policy that allows
the coders its 7.1.2 build needs; the image's own denies them all.
110 tests.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
101 lines
4.0 KiB
TypeScript
101 lines
4.0 KiB
TypeScript
/**
|
|
* Runtime configuration, read once from the environment.
|
|
*
|
|
* The two Schulcloud values are named after the browser artefacts they come
|
|
* from (`TSC_URL`, `TSC_JWT_COOKIE`) so that copying a fresh token out of
|
|
* DevTools stays an obvious, mechanical step — see docs/AUTH.md.
|
|
*/
|
|
|
|
import { resolve } from 'node:path';
|
|
|
|
export interface Config {
|
|
/** Instance base URL, no trailing slash, e.g. `https://schulcloud-thueringen.de`. */
|
|
baseUrl: string;
|
|
/** Raw JWT from the instance's `jwt` cookie. Sent as `Authorization: Bearer`. */
|
|
jwt: string;
|
|
/** Shared secret callers must present to this MCP server. Unused in stdio mode. */
|
|
authToken: string | undefined;
|
|
port: number;
|
|
bindHost: string;
|
|
/** Hard ceiling on how many bytes `download_file` will pull from the instance. */
|
|
maxDownloadBytes: number;
|
|
/** Characters of extracted text returned before truncation kicks in. */
|
|
maxExtractedChars: number;
|
|
requestTimeoutMs: number;
|
|
/**
|
|
* How often to ping the instance to hold the session open. Must stay well
|
|
* under the instance's `JWT_TIMEOUT_SECONDS` (7200s here) — see
|
|
* src/core/keepalive.ts. Zero disables the keepalive.
|
|
*/
|
|
keepaliveIntervalMs: number;
|
|
|
|
/** Postgres for the search index and file mirror. Unset = live-only mode. */
|
|
databaseUrl: string | undefined;
|
|
/** Where mirrored file bytes live on disk. */
|
|
mirrorDir: string;
|
|
/** Files larger than this are indexed as metadata but not mirrored. */
|
|
mirrorMaxBytes: number;
|
|
/** Index personal files and submitted/returned work as well as course content. */
|
|
indexPersonalFiles: boolean;
|
|
/** How often to re-crawl on a timer. Zero = only on demand. */
|
|
crawlIntervalMs: number;
|
|
}
|
|
|
|
function required(name: string): string {
|
|
const value = process.env[name]?.trim();
|
|
if (!value) throw new Error(`Missing required environment variable ${name}`);
|
|
return value;
|
|
}
|
|
|
|
/** `1`, `true`, `yes` and `on` are all true; anything else falls back. */
|
|
function bool(name: string, fallback: boolean): boolean {
|
|
const raw = process.env[name]?.trim().toLowerCase();
|
|
if (!raw) return fallback;
|
|
return ['1', 'true', 'yes', 'on'].includes(raw);
|
|
}
|
|
|
|
function int(name: string, fallback: number): number {
|
|
const raw = process.env[name]?.trim();
|
|
if (!raw) return fallback;
|
|
const parsed = Number.parseInt(raw, 10);
|
|
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
throw new Error(`Environment variable ${name} must be a positive integer, got ${raw}`);
|
|
}
|
|
return parsed;
|
|
}
|
|
|
|
/** Like `int`, but 0 is meaningful (it disables the feature) rather than invalid. */
|
|
function intAllowingZero(name: string, fallback: number): number {
|
|
const raw = process.env[name]?.trim();
|
|
if (!raw) return fallback;
|
|
const parsed = Number.parseInt(raw, 10);
|
|
if (!Number.isFinite(parsed) || parsed < 0) {
|
|
throw new Error(`Environment variable ${name} must be a non-negative integer, got ${raw}`);
|
|
}
|
|
return parsed;
|
|
}
|
|
|
|
export function loadConfig(): Config {
|
|
return {
|
|
baseUrl: required('TSC_URL').replace(/\/+$/, ''),
|
|
jwt: required('TSC_JWT_COOKIE'),
|
|
authToken: process.env.MCP_AUTH_TOKEN?.trim() || undefined,
|
|
port: int('PORT', 8080),
|
|
bindHost: process.env.BIND_HOST?.trim() || '0.0.0.0',
|
|
maxDownloadBytes: int('MAX_DOWNLOAD_BYTES', 25 * 1024 * 1024),
|
|
maxExtractedChars: int('MAX_EXTRACTED_CHARS', 120_000),
|
|
requestTimeoutMs: int('REQUEST_TIMEOUT_MS', 30_000),
|
|
keepaliveIntervalMs: intAllowingZero('KEEPALIVE_INTERVAL_MS', 30 * 60_000),
|
|
databaseUrl: process.env.DATABASE_URL?.trim() || undefined,
|
|
// Absolute: res.sendFile rejects a relative path, and resolveWithin only
|
|
// returns an absolute path if the root it is given is one.
|
|
mirrorDir: resolve(process.env.MIRROR_DIR?.trim() || '/var/lib/schulcloud-mcp/mirror'),
|
|
mirrorMaxBytes: int('MIRROR_MAX_BYTES', 64 * 1024 * 1024),
|
|
// Off by default: submissions are per task, so this roughly doubles the
|
|
// cost of a full crawl. Worth turning on to make your own handed-in work
|
|
// searchable, which no other route offers.
|
|
indexPersonalFiles: bool('INDEX_PERSONAL_FILES', false),
|
|
crawlIntervalMs: intAllowingZero('CRAWL_INTERVAL_MS', 6 * 60 * 60_000),
|
|
};
|
|
}
|