infomentor-se-mcp 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/README.md +86 -29
- package/RELEASING.md +14 -31
- package/dist/calendar.js +41 -1
- package/dist/client.js +65 -10
- package/dist/collection.js +64 -8
- package/dist/index.js +1 -0
- package/dist/server.js +8 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.2.0
|
|
4
|
+
|
|
5
|
+
- Item-local notification detail failures return `detailStatus: "pending"` with
|
|
6
|
+
a safe `detailError` while complete items can proceed. Pending details retry
|
|
7
|
+
on unchanged scans after cursor advancement and emit recovered content.
|
|
8
|
+
- Authentication, account/child context, cancellation and other systemic failures
|
|
9
|
+
continue to fail closed without advancing the collector cursor.
|
|
10
|
+
- Added the opt-in read-only `infomentor_get_calendar_week` and public calendar
|
|
11
|
+
week schemas/types. Whole-week CalendarV2 links now resolve automatically in
|
|
12
|
+
high-level collection as `detail.kind: "calendar_week"`, preserving exact
|
|
13
|
+
entries and allowing empty weeks without guessing one event.
|
|
14
|
+
- Week reads validate explicit ISO year/week, verify child/account context after
|
|
15
|
+
the feed read, share calendar feed caches, and restore the original selection.
|
|
16
|
+
Incomplete feeds stay pending and are retried; exact-event reads remain strict.
|
|
17
|
+
- The source tool surface is 9 default, 15 advanced, 13 setup, or 19 combined.
|
|
18
|
+
These changes are included in npm `1.2.0`.
|
|
19
|
+
|
|
3
20
|
## 1.1.0
|
|
4
21
|
|
|
5
22
|
- Child-context-dependent overview, message, and notification reads can receive
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# InfoMentor MCP
|
|
2
2
|
|
|
3
|
-
Current release: `1.
|
|
3
|
+
Current release: `1.2.0`.
|
|
4
4
|
|
|
5
5
|
A local MCP server for Swedish InfoMentor parent accounts. It uses InfoMentor's
|
|
6
6
|
HTTPS endpoints directly; it does not use Playwright, browser automation, or a
|
|
@@ -45,30 +45,34 @@ of this package and must be handled by a separate authorized workflow.
|
|
|
45
45
|
|
|
46
46
|
## Architecture
|
|
47
47
|
|
|
48
|
-
The
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
[Open the standalone HTML version](docs/architecture.html) in a browser for the
|
|
56
|
-
full self-contained visual diagram.
|
|
48
|
+
The published package is a local, host-neutral MCP stdio server. An MCP host
|
|
49
|
+
starts it as a child process; it keeps credentials and session state on the
|
|
50
|
+
user's machine and calls InfoMentor directly over HTTPS. It exposes nine
|
|
51
|
+
ordinary tools by default, with advanced and setup tools available only when
|
|
52
|
+
explicitly enabled. No hosted HTTP service, browser automation, or remote
|
|
53
|
+
credential relay is required.
|
|
57
54
|
|
|
58
55
|
## Install and configure with npm
|
|
59
56
|
|
|
60
|
-
|
|
57
|
+
The recommended user path is the published npm package. Node.js 20+ and npm
|
|
58
|
+
are required; Bun is not required.
|
|
59
|
+
|
|
60
|
+
First verify the package from a terminal:
|
|
61
61
|
|
|
62
62
|
```sh
|
|
63
|
-
npx -y infomentor-se-mcp@1.
|
|
63
|
+
npx -y infomentor-se-mcp@1.2.0 --version
|
|
64
|
+
npx -y infomentor-se-mcp@1.2.0 --help
|
|
64
65
|
```
|
|
65
66
|
|
|
67
|
+
Then add the server to the MCP host's configuration. This is the standard
|
|
68
|
+
stdio shape used by Claude Desktop, Cursor, Hermes, and other MCP hosts:
|
|
69
|
+
|
|
66
70
|
```json
|
|
67
71
|
{
|
|
68
72
|
"mcpServers": {
|
|
69
73
|
"infomentor": {
|
|
70
74
|
"command": "npx",
|
|
71
|
-
"args": ["-y", "infomentor-se-mcp@1.
|
|
75
|
+
"args": ["-y", "infomentor-se-mcp@1.2.0"],
|
|
72
76
|
"env": {
|
|
73
77
|
"INFOMENTOR_SE_SESSION_PATH": "/absolute/path/infomentor-session.json",
|
|
74
78
|
"INFOMENTOR_SE_CREDENTIALS_FILE": "/absolute/path/credentials.json"
|
|
@@ -78,9 +82,25 @@ npx -y infomentor-se-mcp@1.1.0 --version
|
|
|
78
82
|
}
|
|
79
83
|
```
|
|
80
84
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
85
|
+
Use absolute paths. The exact `@1.2.0` version keeps the host reproducible;
|
|
86
|
+
change it deliberately when upgrading. `@latest` is also supported when you
|
|
87
|
+
prefer automatic adoption of the newest published version.
|
|
88
|
+
|
|
89
|
+
`INFOMENTOR_SE_CREDENTIALS_FILE` is optional but recommended when automatic
|
|
90
|
+
session renewal is wanted. Instead, a host with secure secret injection may
|
|
91
|
+
provide `INFOMENTOR_SE_USERNAME` and `INFOMENTOR_SE_PASSWORD`. Do not put
|
|
92
|
+
passwords in repository files, MCP arguments, or shell history. Restart the
|
|
93
|
+
MCP host after changing its command or environment.
|
|
94
|
+
|
|
95
|
+
To expose the opt-in advanced tools, add the `serve` command and flag:
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
"args": ["-y", "infomentor-se-mcp@1.2.0", "serve", "--allow-advanced-tools"]
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Only enable `--allow-setup-tools` when the host must expose login, setup-status,
|
|
102
|
+
cancellation, or logout as MCP tools. The safer default is to run `login` and
|
|
103
|
+
`status` from a terminal as shown below.
|
|
84
104
|
|
|
85
105
|
## Sign in
|
|
86
106
|
|
|
@@ -146,13 +166,14 @@ The default server exposes nine everyday account, school-data, news, and collect
|
|
|
146
166
|
tools. Lower-level message and notification/detail tools are hidden unless the
|
|
147
167
|
host explicitly appends `--allow-advanced-tools` to `serve`:
|
|
148
168
|
|
|
149
|
-
| Advanced tool | Purpose
|
|
150
|
-
| ------------------------------- |
|
|
151
|
-
| `infomentor_get_messages` | List messages in a verified child context, with paging and search.
|
|
152
|
-
| `infomentor_get_message` | Read one message body in a verified child context.
|
|
153
|
-
| `infomentor_get_notifications` | Read the available notifications in a verified child context.
|
|
154
|
-
| `infomentor_get_news_item` | Resolve a `NewsItem` notification ID to its full article.
|
|
155
|
-
| `infomentor_get_calendar_event` | Resolve a `CalendarV2` notification ID to its
|
|
169
|
+
| Advanced tool | Purpose |
|
|
170
|
+
| ------------------------------- | ------------------------------------------------------------------------- |
|
|
171
|
+
| `infomentor_get_messages` | List messages in a verified child context, with paging and search. |
|
|
172
|
+
| `infomentor_get_message` | Read one message body in a verified child context. |
|
|
173
|
+
| `infomentor_get_notifications` | Read the available notifications in a verified child context. |
|
|
174
|
+
| `infomentor_get_news_item` | Resolve a `NewsItem` notification ID to its full article. |
|
|
175
|
+
| `infomentor_get_calendar_event` | Resolve a `CalendarV2` notification with an event ID to its exact event. |
|
|
176
|
+
| `infomentor_get_calendar_week` | Read the complete linked week for a whole-week `CalendarV2` notification. |
|
|
156
177
|
|
|
157
178
|
By default the server does not expose account setup mutations either. Append
|
|
158
179
|
`--allow-setup-tools` to `serve` only when the MCP host must perform login,
|
|
@@ -164,9 +185,38 @@ With setup tools enabled, the server additionally exposes
|
|
|
164
185
|
`infomentor_logout`. Login returns immediately; check setup status rather than
|
|
165
186
|
busy-polling.
|
|
166
187
|
|
|
167
|
-
With both flags enabled, the server exposes all
|
|
168
|
-
9 tools by default,
|
|
169
|
-
flags.
|
|
188
|
+
With both flags enabled, the server exposes all 19 tools. The surface is
|
|
189
|
+
9 tools by default, 15 with advanced tools, 13 with setup tools, or 19 with both
|
|
190
|
+
flags. Calendar-week support is included in `1.2.0`.
|
|
191
|
+
|
|
192
|
+
## Calendar notifications: exact events and whole weeks
|
|
193
|
+
|
|
194
|
+
`infomentor_collect_updates` resolves supported notifications automatically:
|
|
195
|
+
|
|
196
|
+
- Links containing `eventId` return an exact event with `detail.kind: "calendar"`.
|
|
197
|
+
- `calendarv2/whole_week` links without an event ID return
|
|
198
|
+
`detail.kind: "calendar_week"`, with the notification, verified `childId`,
|
|
199
|
+
Monday–Sunday `startDate`/`endDate`, `events`, `skipped`, and `retrievedAt`.
|
|
200
|
+
Each event preserves its actual ID, dates, times, all-day form, and text.
|
|
201
|
+
Multi-day events overlapping the requested week retain their original dates.
|
|
202
|
+
An empty week is a valid result, not a missing event.
|
|
203
|
+
|
|
204
|
+
For a targeted diagnostic read, enable advanced tools and call
|
|
205
|
+
`infomentor_get_calendar_week` with the positive numeric `notificationId` from
|
|
206
|
+
InfoMentor. The notification must contain an explicit valid ISO year/week and
|
|
207
|
+
whole-week route. The tool derives and verifies the child's context, reads the
|
|
208
|
+
linked week, and restores the original selection. It does not guess an event or
|
|
209
|
+
fall back to another week. `infomentor_get_calendar_event` remains exact-event-only.
|
|
210
|
+
|
|
211
|
+
Check `skipped` before treating a targeted week read as complete. The collector
|
|
212
|
+
returns incomplete week feeds as `detailStatus: "pending"` with safe
|
|
213
|
+
`detailError` metadata and retries them, even after unrelated cursor advancement.
|
|
214
|
+
Consumers must retain these pending items and must not acknowledge or archive
|
|
215
|
+
partial details as complete. Authentication, account/child-context drift,
|
|
216
|
+
cancellation, and systemic failures still fail closed.
|
|
217
|
+
|
|
218
|
+
Whole-week reads are read-only InfoMentor data. They do not create Google Calendar
|
|
219
|
+
events, mark notifications read, or modify school records.
|
|
170
220
|
|
|
171
221
|
## Tools
|
|
172
222
|
|
|
@@ -207,9 +257,16 @@ flags.
|
|
|
207
257
|
scans supported timetables, message summaries, and notifications for every
|
|
208
258
|
registered child, fetches message bodies only for new or changed summaries,
|
|
209
259
|
automatically resolves `NewsItem` and `CalendarV2` references, and marks
|
|
210
|
-
unsupported notification types explicitly.
|
|
211
|
-
|
|
212
|
-
|
|
260
|
+
unsupported notification types explicitly. Item-local detail failures return
|
|
261
|
+
`detailStatus: "pending"` and `detailError: {code, message}` with safe messages;
|
|
262
|
+
other valid items remain available and the cursor may advance. Pending items
|
|
263
|
+
are retried and returned on every scan, even when their summaries are unchanged,
|
|
264
|
+
including on a quiet first baseline. Recovered details are emitted as resolved.
|
|
265
|
+
Authentication, session/account/child identity, cancellation and other systemic
|
|
266
|
+
failures still abort without advancing a cursor. CalendarV2 links containing
|
|
267
|
+
only a selected year/week have no exact event ID: they stay pending rather than
|
|
268
|
+
guessing which calendar event the notification references. Save its returned
|
|
269
|
+
cursor only after handling or
|
|
213
270
|
delivering results; retry the previous cursor if delivery fails. Routine runs
|
|
214
271
|
should use `maxMessagePages: 5`; increase it only for a bounded backfill.
|
|
215
272
|
- The lower-level message and notification/detail tools are available only with
|
package/RELEASING.md
CHANGED
|
@@ -82,37 +82,20 @@ automatically with npm provenance.
|
|
|
82
82
|
|
|
83
83
|
## Future releases
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
3. Commit and push the release change. Wait for the normal CI workflow to pass.
|
|
100
|
-
4. Create and push an annotated tag whose version exactly matches
|
|
101
|
-
`package.json`:
|
|
102
|
-
|
|
103
|
-
```sh
|
|
104
|
-
git tag -a vX.Y.Z -m "Release InfoMentor MCP X.Y.Z"
|
|
105
|
-
git push origin vX.Y.Z
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
5. The `Publish npm package` workflow validates the tag, repeats the quality
|
|
109
|
-
gates, builds the Node entrypoint, and publishes with npm provenance.
|
|
110
|
-
6. Verify the registry and executable:
|
|
111
|
-
|
|
112
|
-
```sh
|
|
113
|
-
npm view infomentor-se-mcp@X.Y.Z version dist.tarball
|
|
114
|
-
npx -y infomentor-se-mcp@X.Y.Z --version
|
|
115
|
-
```
|
|
85
|
+
Add a new `## X.Y.Z` heading and its release notes at the top of
|
|
86
|
+
`CHANGELOG.md`, then run:
|
|
87
|
+
|
|
88
|
+
```sh
|
|
89
|
+
./release.sh X.Y.Z
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The script checks the main branch and clean worktree, verifies npm/GitHub
|
|
93
|
+
authentication and the Trusted Publisher reminder, updates `package.json` and
|
|
94
|
+
the pinned README version, runs all quality gates, commits and pushes the
|
|
95
|
+
release, waits for CI, asks before pushing the publication-triggering tag,
|
|
96
|
+
waits for the npm workflow, creates the GitHub release, and verifies both npm
|
|
97
|
+
and a fresh `npx` consumer. It never asks for or handles an npm password or
|
|
98
|
+
2FA code.
|
|
116
99
|
|
|
117
100
|
A published name/version pair cannot be reused. If a published version has a
|
|
118
101
|
problem, deprecate it and publish the next patch version instead of trying to
|
package/dist/calendar.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { parseDocument } from "htmlparser2";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { notificationSchema } from "./session.js";
|
|
3
|
+
import { InfoMentorError, notificationSchema } from "./session.js";
|
|
4
4
|
const positiveInteger = z
|
|
5
5
|
.union([
|
|
6
6
|
z.number().int().positive(),
|
|
@@ -148,6 +148,46 @@ export const calendarEventSchema = z.object({
|
|
|
148
148
|
skipped: z.number().int().nonnegative(),
|
|
149
149
|
retrievedAt: z.iso.datetime(),
|
|
150
150
|
});
|
|
151
|
+
export const calendarWeekRequestSchema = calendarEventRequestSchema;
|
|
152
|
+
export const calendarWeekSchema = z.object({
|
|
153
|
+
kind: z.literal("calendar_week"),
|
|
154
|
+
notification: notificationSchema,
|
|
155
|
+
childId: z.string().min(1),
|
|
156
|
+
startDate: z.string(),
|
|
157
|
+
endDate: z.string(),
|
|
158
|
+
events: z.array(calendarEventSchema),
|
|
159
|
+
skipped: z.number().int().nonnegative(),
|
|
160
|
+
retrievedAt: z.iso.datetime(),
|
|
161
|
+
});
|
|
162
|
+
export function calendarWeekRangeFromNotification(url) {
|
|
163
|
+
const fail = () => {
|
|
164
|
+
throw new InfoMentorError("UNEXPECTED_PAGE", "InfoMentor returned an invalid CalendarV2 whole-week route or ISO week.");
|
|
165
|
+
};
|
|
166
|
+
if (!/^\/?#\/calendarv2\/whole_week\?/i.test(url))
|
|
167
|
+
fail();
|
|
168
|
+
const params = new URLSearchParams(url.slice(url.indexOf("?") + 1));
|
|
169
|
+
const yearValue = params.get("selectedYear");
|
|
170
|
+
const weekValue = params.get("selectedWeek");
|
|
171
|
+
if (params.getAll("selectedYear").length !== 1 ||
|
|
172
|
+
params.getAll("selectedWeek").length !== 1 ||
|
|
173
|
+
!yearValue ||
|
|
174
|
+
!/^\d{4}$/.test(yearValue) ||
|
|
175
|
+
!weekValue ||
|
|
176
|
+
!/^\d{1,2}$/.test(weekValue))
|
|
177
|
+
fail();
|
|
178
|
+
const year = Number(yearValue);
|
|
179
|
+
const week = Number(weekValue);
|
|
180
|
+
if (year < 1000 || week < 1 || week > 53)
|
|
181
|
+
fail();
|
|
182
|
+
const start = isoWeekStart(year, week);
|
|
183
|
+
const thursday = new Date(start);
|
|
184
|
+
thursday.setUTCDate(start.getUTCDate() + 3);
|
|
185
|
+
if (thursday.getUTCFullYear() !== year)
|
|
186
|
+
fail();
|
|
187
|
+
const end = new Date(start);
|
|
188
|
+
end.setUTCDate(start.getUTCDate() + 6);
|
|
189
|
+
return { startDate: dateParts(start), endDate: dateParts(end) };
|
|
190
|
+
}
|
|
151
191
|
/** Extract the calendar event ID embedded in a CalendarV2 hash route. */
|
|
152
192
|
export function calendarEventIdFromNotificationUrl(url) {
|
|
153
193
|
const match = /(?:^|[?&#])eventId=(\d+)(?:[&#]|$)/i.exec(url);
|
package/dist/client.js
CHANGED
|
@@ -5,7 +5,7 @@ import { login, importSession, createAuthenticatedHttp, hasConfiguredCredentials
|
|
|
5
5
|
import { withSessionLock } from "./lock.js";
|
|
6
6
|
import { collectUpdates, collectRequestSchema, } from "./collection.js";
|
|
7
7
|
import { buildSaveCommentFields, buildSaveTimeRegistrationsPayload, commentsResponseSchema, datePart, fritidsschemaCommentRequestSchema, fritidsschemaRequestSchema, fritidsschemaTimesRequestSchema, saveCommentResponseSchema, saveTimeRegistrationsResponseSchema, timePart, timeRegistrationsResponseSchema, addLocalDate, } from "./fritidsschema.js";
|
|
8
|
-
import { buildCalendarEvent, calendarEntriesResponseSchema, calendarEventIdFromNotificationUrl, calendarEventRequestSchema, calendarRangeFromNotification, } from "./calendar.js";
|
|
8
|
+
import { buildCalendarEvent, calendarEntriesResponseSchema, calendarEventIdFromNotificationUrl, calendarEventRequestSchema, calendarRangeFromNotification, calendarWeekRequestSchema, calendarWeekSchema, calendarWeekRangeFromNotification, } from "./calendar.js";
|
|
9
9
|
import { buildNewsContent, buildNewsItem, childIdFromPupilSourceId, newsIdFromNotificationUrl, newsItemRequestSchema, newsListResponseSchema, newsSearchRequestSchema, newsSearchSchema, } from "./news.js";
|
|
10
10
|
import { InfoMentorError, overviewRequestSchema, selectChildRequestSchema, messagesRequestSchema, messageRequestSchema, notificationsRequestSchema, messagesPageResponseSchema, messageDetailSchema, notificationsResponseSchema, timetableResponseSchema, readSession, sessionPath, throwIfAborted, writeSession, } from "./session.js";
|
|
11
11
|
export const loginRequestSchema = z
|
|
@@ -371,6 +371,7 @@ export class InfoMentorClient {
|
|
|
371
371
|
},
|
|
372
372
|
resolveNewsItem: (notificationId, nextSignal, notification) => this.resolveNewsItem(http, notificationId, nextSignal, notification, resolverCaches),
|
|
373
373
|
resolveCalendarEvent: (notificationId, nextSignal, notification) => this.resolveCalendarEvent(http, notificationId, nextSignal, notification, resolverCaches),
|
|
374
|
+
resolveCalendarWeek: (notificationId, nextSignal, notification) => this.resolveCalendarWeek(http, notificationId, nextSignal, notification, resolverCaches),
|
|
374
375
|
});
|
|
375
376
|
}, collectionSignal);
|
|
376
377
|
}
|
|
@@ -495,7 +496,36 @@ export class InfoMentorClient {
|
|
|
495
496
|
const { notificationId } = calendarEventRequestSchema.parse(request);
|
|
496
497
|
return this.read((http, activeSignal) => this.resolveCalendarEvent(http, notificationId, activeSignal), signal);
|
|
497
498
|
}
|
|
499
|
+
/** Selection/restoration failures must never be downgraded to pending details. */
|
|
500
|
+
async readNotificationParent(http, signal, childId) {
|
|
501
|
+
const accountId = http.parent?.account.currentUser.id;
|
|
502
|
+
try {
|
|
503
|
+
const parent = await http.readParent(signal, childId);
|
|
504
|
+
if (!accountId || parent.account.currentUser.id !== accountId)
|
|
505
|
+
throw new InfoMentorError("INVALID_SESSION", "The notification account changed during resolution.");
|
|
506
|
+
}
|
|
507
|
+
catch (error) {
|
|
508
|
+
throwIfAborted(signal);
|
|
509
|
+
if (error instanceof InfoMentorError &&
|
|
510
|
+
!["INVALID_CONFIGURATION", "UNEXPECTED_PAGE", "NOT_FOUND"].includes(error.code))
|
|
511
|
+
throw error;
|
|
512
|
+
throw new InfoMentorError("INVALID_SESSION", "InfoMentor could not verify the notification child context. No cursor was advanced.");
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
getCalendarWeek(request, signal) {
|
|
516
|
+
const { notificationId } = calendarWeekRequestSchema.parse(request);
|
|
517
|
+
return this.read((http, activeSignal) => this.resolveCalendarWeek(http, notificationId, activeSignal), signal);
|
|
518
|
+
}
|
|
519
|
+
async resolveCalendarWeek(http, notificationId, signal, suppliedNotification, resolverCaches) {
|
|
520
|
+
return calendarWeekSchema.parse(await this.resolveCalendarReference(http, notificationId, signal, suppliedNotification, resolverCaches, true));
|
|
521
|
+
}
|
|
498
522
|
async resolveCalendarEvent(http, notificationId, signal, suppliedNotification, resolverCaches) {
|
|
523
|
+
const result = await this.resolveCalendarReference(http, notificationId, signal, suppliedNotification, resolverCaches, false);
|
|
524
|
+
if ("kind" in result)
|
|
525
|
+
throw new Error("Unexpected calendar week.");
|
|
526
|
+
return result;
|
|
527
|
+
}
|
|
528
|
+
async resolveCalendarReference(http, notificationId, signal, suppliedNotification, resolverCaches, wholeWeek) {
|
|
499
529
|
let notification = suppliedNotification;
|
|
500
530
|
if (!notification) {
|
|
501
531
|
const notifications = await http.readAppData("NotificationApp/NotificationApp/appData", {}, notificationsResponseSchema, signal);
|
|
@@ -503,12 +533,13 @@ export class InfoMentorClient {
|
|
|
503
533
|
}
|
|
504
534
|
if (!notification)
|
|
505
535
|
throw new InfoMentorError("INVALID_CONFIGURATION", "The requested InfoMentor notification is not available in the current feed.");
|
|
506
|
-
if (
|
|
507
|
-
|
|
536
|
+
if ((wholeWeek && !["CalendarV2", "CalendarV2EventCreated"].includes(notification.type)) ||
|
|
537
|
+
(notification.appType !== "CalendarV2" &&
|
|
538
|
+
!notification.type.toLowerCase().startsWith("calendarv2")))
|
|
508
539
|
throw new InfoMentorError("INVALID_CONFIGURATION", "The requested InfoMentor notification is not a CalendarV2 event.");
|
|
509
540
|
const eventId = calendarEventIdFromNotificationUrl(notification.url);
|
|
510
|
-
if (!eventId)
|
|
511
|
-
throw new InfoMentorError("
|
|
541
|
+
if (!wholeWeek && !eventId)
|
|
542
|
+
throw new InfoMentorError("NOT_FOUND", "This CalendarV2 notification links to a week without an event ID; an exact event cannot be safely resolved.");
|
|
512
543
|
const currentParent = http.parent;
|
|
513
544
|
const originalChildId = currentParent?.account.pupils.find((pupil) => pupil.selected)?.id;
|
|
514
545
|
const targetChildId = childIdFromPupilSourceId(notification.pupilSourceId);
|
|
@@ -518,9 +549,11 @@ export class InfoMentorClient {
|
|
|
518
549
|
throw new InfoMentorError("UNEXPECTED_PAGE", "InfoMentor returned a CalendarV2 notification without a supported child ID.");
|
|
519
550
|
const switchedChild = targetChildId !== originalChildId;
|
|
520
551
|
if (switchedChild)
|
|
521
|
-
await
|
|
552
|
+
await this.readNotificationParent(http, signal, targetChildId);
|
|
522
553
|
try {
|
|
523
|
-
const range =
|
|
554
|
+
const range = wholeWeek
|
|
555
|
+
? calendarWeekRangeFromNotification(notification.url)
|
|
556
|
+
: calendarRangeFromNotification(notification.url, notification.dateSent);
|
|
524
557
|
const feedKey = JSON.stringify([targetChildId, range]);
|
|
525
558
|
let feedPromise = resolverCaches?.calendarFeeds.get(feedKey);
|
|
526
559
|
if (!feedPromise) {
|
|
@@ -528,6 +561,28 @@ export class InfoMentorClient {
|
|
|
528
561
|
resolverCaches?.calendarFeeds.set(feedKey, feedPromise);
|
|
529
562
|
}
|
|
530
563
|
const feed = await feedPromise;
|
|
564
|
+
// Never attribute a feed to a child after shared session context drift.
|
|
565
|
+
// Read without selecting: selecting here would hide the changed context.
|
|
566
|
+
const confirmedParent = await http.readParent(signal);
|
|
567
|
+
const roster = (parent) => parent.account.pupils
|
|
568
|
+
.map((pupil) => pupil.id)
|
|
569
|
+
.sort()
|
|
570
|
+
.join("|");
|
|
571
|
+
if (!currentParent ||
|
|
572
|
+
confirmedParent.account.currentUser.id !== currentParent.account.currentUser.id ||
|
|
573
|
+
confirmedParent.account.pupils.find((pupil) => pupil.selected)?.id !== targetChildId ||
|
|
574
|
+
roster(confirmedParent) !== roster(currentParent))
|
|
575
|
+
throw new InfoMentorError("INVALID_SESSION", "InfoMentor calendar account or child context changed during the feed read.");
|
|
576
|
+
if (wholeWeek)
|
|
577
|
+
return calendarWeekSchema.parse({
|
|
578
|
+
kind: "calendar_week",
|
|
579
|
+
notification,
|
|
580
|
+
childId: targetChildId,
|
|
581
|
+
...range,
|
|
582
|
+
events: feed.items.map((row) => buildCalendarEvent(notification, row, targetChildId, feed.skipped)),
|
|
583
|
+
skipped: feed.skipped,
|
|
584
|
+
retrievedAt: new Date().toISOString(),
|
|
585
|
+
});
|
|
531
586
|
const row = feed.items.find((item) => item.id === eventId);
|
|
532
587
|
if (!row)
|
|
533
588
|
throw new InfoMentorError("UNEXPECTED_PAGE", "InfoMentor did not return the requested CalendarV2 event in its authenticated calendar feed.");
|
|
@@ -535,7 +590,7 @@ export class InfoMentorClient {
|
|
|
535
590
|
}
|
|
536
591
|
finally {
|
|
537
592
|
if (switchedChild)
|
|
538
|
-
await
|
|
593
|
+
await this.readNotificationParent(http, signal, originalChildId);
|
|
539
594
|
}
|
|
540
595
|
}
|
|
541
596
|
/** Resolve a NewsItem notification ID to its full authenticated news record. */
|
|
@@ -565,7 +620,7 @@ export class InfoMentorClient {
|
|
|
565
620
|
throw new InfoMentorError("UNEXPECTED_PAGE", "InfoMentor returned a NewsItem notification without a supported child ID.");
|
|
566
621
|
const switchedChild = targetChildId !== originalChildId;
|
|
567
622
|
if (switchedChild)
|
|
568
|
-
await
|
|
623
|
+
await this.readNotificationParent(http, signal, targetChildId);
|
|
569
624
|
try {
|
|
570
625
|
const feedKey = targetChildId;
|
|
571
626
|
let feedPromise = resolverCaches?.newsFeeds.get(feedKey);
|
|
@@ -581,7 +636,7 @@ export class InfoMentorClient {
|
|
|
581
636
|
}
|
|
582
637
|
finally {
|
|
583
638
|
if (switchedChild)
|
|
584
|
-
await
|
|
639
|
+
await this.readNotificationParent(http, signal, originalChildId);
|
|
585
640
|
}
|
|
586
641
|
}
|
|
587
642
|
getNotifications(request = {}, signal) {
|
package/dist/collection.js
CHANGED
|
@@ -3,7 +3,7 @@ import { readdir, rm, stat, utimes } from "node:fs/promises";
|
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { ensurePrivateDir, readPrivateFile, sweepTempInDirectory, writePrivateFile, } from "./shared/session-store/index.js";
|
|
5
5
|
import { z } from "zod";
|
|
6
|
-
import { calendarEventSchema } from "./calendar.js";
|
|
6
|
+
import { calendarEventSchema, calendarEventIdFromNotificationUrl, calendarWeekSchema, } from "./calendar.js";
|
|
7
7
|
import { newsItemSchema } from "./news.js";
|
|
8
8
|
import { InfoMentorError, PARENT_URL, messageDetailSchema, messagesPageSchema, notificationsDataSchema, notificationSchema, pupilSchema, sessionPath, timetableSchema, throwIfAborted, timetableEntrySchema, } from "./session.js";
|
|
9
9
|
export const collectRequestSchema = z
|
|
@@ -23,12 +23,19 @@ const collectedCalendarDetailSchema = calendarEventSchema
|
|
|
23
23
|
const notificationDetailSchema = z.discriminatedUnion("kind", [
|
|
24
24
|
collectedNewsDetailSchema,
|
|
25
25
|
collectedCalendarDetailSchema,
|
|
26
|
+
calendarWeekSchema,
|
|
26
27
|
]);
|
|
27
28
|
const collectedNotificationSchema = notificationSchema
|
|
28
29
|
.omit({ currentlySelectedPupil: true })
|
|
29
30
|
.extend({
|
|
30
|
-
detailStatus: z.enum(["resolved", "not_supported"]),
|
|
31
|
+
detailStatus: z.enum(["resolved", "not_supported", "pending"]),
|
|
31
32
|
detail: notificationDetailSchema.optional(),
|
|
33
|
+
detailError: z
|
|
34
|
+
.object({
|
|
35
|
+
code: z.enum(["INVALID_CONFIGURATION", "UNEXPECTED_PAGE", "NOT_FOUND"]),
|
|
36
|
+
message: z.string(),
|
|
37
|
+
})
|
|
38
|
+
.optional(),
|
|
32
39
|
});
|
|
33
40
|
const kindSchema = z.enum(["child", "timetable", "message", "notification"]);
|
|
34
41
|
const folderSchema = z.enum(["inbox", "sent"]);
|
|
@@ -249,10 +256,32 @@ async function resolveCollectedNotification(item, source, signal) {
|
|
|
249
256
|
catch (error) {
|
|
250
257
|
if (error instanceof InfoMentorError)
|
|
251
258
|
throw new InfoMentorError(error.code, `InfoMentor could not resolve NewsItem notification ${item.id}; no cursor was advanced.`, error.retryAfterMs);
|
|
252
|
-
|
|
259
|
+
if (error instanceof z.ZodError)
|
|
260
|
+
throw new InfoMentorError("UNEXPECTED_PAGE", "InfoMentor returned invalid notification details.");
|
|
261
|
+
throw error;
|
|
253
262
|
}
|
|
254
263
|
}
|
|
255
264
|
if (item.type === "CalendarV2" || item.type === "CalendarV2EventCreated") {
|
|
265
|
+
const wholeWeek = !calendarEventIdFromNotificationUrl(item.url) &&
|
|
266
|
+
/^\/?#\/calendarv2\/whole_week\?/i.test(item.url);
|
|
267
|
+
if (wholeWeek) {
|
|
268
|
+
if (!source.resolveCalendarWeek)
|
|
269
|
+
throw new InfoMentorError("INVALID_CONFIGURATION", "The collection source cannot resolve calendar weeks.");
|
|
270
|
+
const detail = calendarWeekSchema.parse(await source.resolveCalendarWeek(item.id, signal, item));
|
|
271
|
+
return collectedNotificationSchema.parse({
|
|
272
|
+
...item,
|
|
273
|
+
detailStatus: detail.skipped > 0 ? "pending" : "resolved",
|
|
274
|
+
detail,
|
|
275
|
+
...(detail.skipped > 0
|
|
276
|
+
? {
|
|
277
|
+
detailError: {
|
|
278
|
+
code: "UNEXPECTED_PAGE",
|
|
279
|
+
message: "InfoMentor calendar week contains malformed entries; collection will retry this item.",
|
|
280
|
+
},
|
|
281
|
+
}
|
|
282
|
+
: {}),
|
|
283
|
+
});
|
|
284
|
+
}
|
|
256
285
|
if (!source.resolveCalendarEvent)
|
|
257
286
|
throw new InfoMentorError("INVALID_CONFIGURATION", `The high-level collection source cannot resolve ${item.type} notification ${item.id}; no cursor was advanced.`);
|
|
258
287
|
try {
|
|
@@ -267,7 +296,9 @@ async function resolveCollectedNotification(item, source, signal) {
|
|
|
267
296
|
catch (error) {
|
|
268
297
|
if (error instanceof InfoMentorError)
|
|
269
298
|
throw new InfoMentorError(error.code, `InfoMentor could not resolve ${item.type} notification ${item.id}; no cursor was advanced.`, error.retryAfterMs);
|
|
270
|
-
|
|
299
|
+
if (error instanceof z.ZodError)
|
|
300
|
+
throw new InfoMentorError("UNEXPECTED_PAGE", "InfoMentor returned invalid notification details.");
|
|
301
|
+
throw error;
|
|
271
302
|
}
|
|
272
303
|
}
|
|
273
304
|
return collectedNotificationSchema.parse({ ...item, detailStatus: "not_supported" });
|
|
@@ -317,8 +348,10 @@ export async function collectUpdates(request, source) {
|
|
|
317
348
|
fingerprint.folder = update.folder;
|
|
318
349
|
recordCurrent(fingerprint);
|
|
319
350
|
const previousFingerprint = previousItems.get(fingerprintKey(fingerprint));
|
|
320
|
-
|
|
321
|
-
|
|
351
|
+
const pending = update.kind === "notification" && update.data.detailStatus === "pending";
|
|
352
|
+
if (!pending &&
|
|
353
|
+
((!previous && !input.includeExisting) ||
|
|
354
|
+
(previousFingerprint !== undefined && fingerprintsEqual(previousFingerprint, fingerprint))))
|
|
322
355
|
return;
|
|
323
356
|
const groupKey = JSON.stringify([referenceKey(fingerprint), fingerprint.hash]);
|
|
324
357
|
const grouped = updates.get(groupKey);
|
|
@@ -372,13 +405,36 @@ export async function collectUpdates(request, source) {
|
|
|
372
405
|
detailPromise = resolveCollectedNotification(item, source, signal);
|
|
373
406
|
resolvedNotificationCache.set(resolutionKey, detailPromise);
|
|
374
407
|
}
|
|
375
|
-
|
|
408
|
+
let data;
|
|
409
|
+
try {
|
|
410
|
+
data = await detailPromise;
|
|
411
|
+
}
|
|
412
|
+
catch (error) {
|
|
413
|
+
throwIfAborted(signal);
|
|
414
|
+
// Detail errors are item-local only while the authenticated account,
|
|
415
|
+
// roster and selected child remain exactly as expected.
|
|
416
|
+
confirmParent(checkedParent(await source.getParent(signal)), initial, child.id);
|
|
417
|
+
if (!(error instanceof InfoMentorError) ||
|
|
418
|
+
!["INVALID_CONFIGURATION", "UNEXPECTED_PAGE", "NOT_FOUND"].includes(error.code))
|
|
419
|
+
throw error;
|
|
420
|
+
data = collectedNotificationSchema.parse({
|
|
421
|
+
...item,
|
|
422
|
+
detailStatus: "pending",
|
|
423
|
+
detailError: {
|
|
424
|
+
code: error.code,
|
|
425
|
+
message: "InfoMentor notification details are unavailable; collection will retry this item.",
|
|
426
|
+
},
|
|
427
|
+
});
|
|
428
|
+
}
|
|
376
429
|
add({
|
|
377
430
|
kind: "notification",
|
|
378
431
|
sourceId,
|
|
379
432
|
childIds: [],
|
|
380
433
|
data,
|
|
381
|
-
}, child.id,
|
|
434
|
+
}, child.id,
|
|
435
|
+
// Only completed details may use the unchanged-summary fast path.
|
|
436
|
+
// Pending metadata retains a fingerprint but is retried every scan.
|
|
437
|
+
data.detailStatus === "pending" ? {} : { summaryHash });
|
|
382
438
|
}
|
|
383
439
|
confirmParent(checkedParent(await source.getParent(signal)), initial, child.id);
|
|
384
440
|
}
|
package/dist/index.js
CHANGED
|
@@ -4,3 +4,4 @@ export { login, importSession } from "./login.js";
|
|
|
4
4
|
export { collectRequestSchema, collectionSchema } from "./collection.js";
|
|
5
5
|
export { InfoMentorError, LOGIN_URL, overviewSchema, selectChildRequestSchema, savedSessionSchema, sessionStatusSchema, sessionPath, messagesRequestSchema, messageRequestSchema, notificationsRequestSchema, messagesSchema, messageSchema, notificationsSchema, } from "./session.js";
|
|
6
6
|
export { newsItemRequestSchema, newsItemSchema } from "./news.js";
|
|
7
|
+
export { calendarEventRequestSchema, calendarEventSchema, calendarWeekRequestSchema, calendarWeekSchema, } from "./calendar.js";
|
package/dist/server.js
CHANGED
|
@@ -5,7 +5,7 @@ import { toolResult } from "./tool-result.js";
|
|
|
5
5
|
import { InfoMentorClient, loginRequestSchema, setupStatusSchema } from "./client.js";
|
|
6
6
|
import { collectRequestSchema, collectionSchema } from "./collection.js";
|
|
7
7
|
import { fritidsschemaCommentRequestSchema, fritidsschemaCommentReadResultSchema, fritidsschemaCommentResultSchema, fritidsschemaRequestSchema, fritidsschemaResultSchema, fritidsschemaTimesRequestSchema, fritidsschemaTimesResultSchema, } from "./fritidsschema.js";
|
|
8
|
-
import { calendarEventRequestSchema, calendarEventSchema } from "./calendar.js";
|
|
8
|
+
import { calendarEventRequestSchema, calendarEventSchema, calendarWeekRequestSchema, calendarWeekSchema, } from "./calendar.js";
|
|
9
9
|
import { newsItemRequestSchema, newsItemSchema, newsSearchRequestSchema, newsSearchSchema, } from "./news.js";
|
|
10
10
|
import { overviewRequestSchema, overviewSchema, selectChildRequestSchema, sessionStatusSchema, messagesRequestSchema, messageRequestSchema, notificationsRequestSchema, messagesSchema, messageSchema, notificationsSchema, } from "./session.js";
|
|
11
11
|
export const packageInfo = { name: manifest.name, version: manifest.version };
|
|
@@ -100,6 +100,12 @@ export function createServer(options = {}) {
|
|
|
100
100
|
outputSchema: calendarEventSchema,
|
|
101
101
|
annotations: READ_ONLY,
|
|
102
102
|
}, (request, ctx) => result(() => client.getCalendarEvent(request, ctx.mcpReq.signal)));
|
|
103
|
+
server.registerTool("infomentor_get_calendar_week", {
|
|
104
|
+
description: "Read the authenticated whole week referenced by a CalendarV2 notificationId. Validates the whole_week route and explicit ISO selectedYear/selectedWeek, selects and verifies the notification child, and restores the original selection. Returns calendar_week with exact event identities, inclusive startDate/endDate, and skipped malformed entries; an empty week is valid, but skipped > 0 means incomplete and must not be archived as complete. Does not mark notifications read or change school records. Use infomentor_collect_updates for routine sync.",
|
|
105
|
+
inputSchema: calendarWeekRequestSchema,
|
|
106
|
+
outputSchema: calendarWeekSchema,
|
|
107
|
+
annotations: READ_ONLY,
|
|
108
|
+
}, (request, ctx) => result(() => client.getCalendarWeek(request, ctx.mcpReq.signal)));
|
|
103
109
|
server.registerTool("infomentor_get_news_item", {
|
|
104
110
|
description: "Read a full NewsItem by the numeric notificationId returned by infomentor_get_notifications. Use infomentor_search_news for one child and a date range instead of resolving many IDs one by one. The tool verifies that the notification is type NewsItem, resolves its exact news ID, reads the authenticated news feed through direct HTTPS, and returns only the matched item with inert HTML-derived text, links, images, and attachments. It does not mark the notification read or change account state.",
|
|
105
111
|
inputSchema: newsItemRequestSchema,
|
|
@@ -114,7 +120,7 @@ export function createServer(options = {}) {
|
|
|
114
120
|
}, (request, ctx) => result(() => client.getNotifications(request, ctx.mcpReq.signal)));
|
|
115
121
|
}
|
|
116
122
|
server.registerTool("infomentor_collect_updates", {
|
|
117
|
-
description: "Expensive all-child incremental sync for scheduled checks. Reads each registered child’s timetable, inbox/sent message pages and bodies only when a message is new or its summary changed, plus the notification feed; resolves supported NewsItem and CalendarV2 details. Use the saved cursor and save the returned cursor only after downstream handling succeeds. Do not use for one-off child/date/news questions; use infomentor_search_news or the local archive instead. Routine runs should use maxMessagePages: 5; increase only for bounded backfills. Unsupported notification types are explicitly marked `detailStatus: not_supported`.
|
|
123
|
+
description: "Expensive all-child incremental sync for scheduled checks. Reads each registered child’s timetable, inbox/sent message pages and bodies only when a message is new or its summary changed, plus the notification feed; resolves supported NewsItem and CalendarV2 details. Use the saved cursor and save the returned cursor only after downstream handling succeeds. Do not use for one-off child/date/news questions; use infomentor_search_news or the local archive instead. Routine runs should use maxMessagePages: 5; increase only for bounded backfills. Unsupported notification types are explicitly marked `detailStatus: not_supported`. Item-local detail failures return notification metadata with `detailStatus: pending` and a safe `detailError` code/message while other items proceed. Pending details are retried and returned on every scan, even with an unchanged summary or an advanced cursor; recovered details are emitted as resolved. Authentication, account/child context, cancellation and other systemic failures abort without advancing the cursor. A CalendarV2 week-only link has no exact event ID and remains pending rather than guessing a week event. Malformed rows are counted in total `skipped` and by feed in `skippedByFeed`; a partial feed keeps its previous baseline and emits no updates or missing references until a complete read. Other complete feeds remain usable. Restores the original selected child. First call establishes a quiet baseline unless includeExisting is true. Pass the last successfully handled cursor to return only new/changed items and missing feed references; missing does not mean deleted. Cursors expire after 90 days without use and stay on this MCP host. Does not mark messages or notifications read. Maximum 20 pages of 100 messages per folder/child; incomplete scans fail without advancing. childIds describe the contexts where an item was visible, not its recipients or ownership. Same-session local MCP calls are locked; other apps may still change the selected child. The scan has a five-minute deadline and 8 MiB response limit. Covers these supported feeds, not homework, attendance, grades, or attachments.",
|
|
118
124
|
inputSchema: collectRequestSchema,
|
|
119
125
|
outputSchema: collectionSchema,
|
|
120
126
|
annotations: { ...LOCAL_WRITE, readOnlyHint: false },
|