caldav-mcp 0.10.1 → 0.10.2
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.
|
@@ -1,31 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
if (r.freq !== undefined)
|
|
5
|
-
out.freq = r.freq;
|
|
6
|
-
if (r.interval !== undefined)
|
|
7
|
-
out.interval = r.interval;
|
|
8
|
-
if (r.count !== undefined)
|
|
9
|
-
out.count = r.count;
|
|
10
|
-
if (r.until !== undefined)
|
|
11
|
-
out.until = new Date(r.until);
|
|
12
|
-
if (r.byday !== undefined)
|
|
13
|
-
out.byday = r.byday;
|
|
14
|
-
if (r.bymonthday !== undefined)
|
|
15
|
-
out.bymonthday = r.bymonthday;
|
|
16
|
-
if (r.bymonth !== undefined)
|
|
17
|
-
out.bymonth = r.bymonth;
|
|
18
|
-
return out;
|
|
19
|
-
}
|
|
20
|
-
const recurrenceRuleSchema = z.object({
|
|
21
|
-
freq: z.enum(["DAILY", "WEEKLY", "MONTHLY", "YEARLY"]).optional(),
|
|
22
|
-
interval: z.number().optional(),
|
|
23
|
-
count: z.number().optional(),
|
|
24
|
-
until: z.string().datetime({ offset: true }).optional(), // ISO 8601 string
|
|
25
|
-
byday: z.array(z.string()).optional(), // e.g. ["MO", "TU"]
|
|
26
|
-
bymonthday: z.array(z.number()).optional(),
|
|
27
|
-
bymonth: z.array(z.number()).optional(),
|
|
28
|
-
});
|
|
2
|
+
import { recurrenceRuleSchema, toRecurrenceRule, } from "./recurrence-rule.js";
|
|
3
|
+
import { toWholeDayDate } from "./whole-day-date.js";
|
|
29
4
|
export const createEventDefinition = {
|
|
30
5
|
name: "create-event",
|
|
31
6
|
description: "Creates an event in the calendar specified by its URL. For all-day events, set `wholeDay` to true. For a single-day all-day event, use `start` and `end` datetimes on the same calendar date; they do not need to be identical timestamps.",
|
|
@@ -55,13 +30,13 @@ export function registerCreateEvent(client, server) {
|
|
|
55
30
|
const { calendarUrl, summary, start, end, wholeDay, description, location, recurrenceRule, } = args;
|
|
56
31
|
const event = await client.createEvent(calendarUrl, {
|
|
57
32
|
summary: summary,
|
|
58
|
-
start: new Date(start),
|
|
59
|
-
end: new Date(end),
|
|
33
|
+
start: wholeDay ? toWholeDayDate(start) : new Date(start),
|
|
34
|
+
end: wholeDay ? toWholeDayDate(end) : new Date(end),
|
|
60
35
|
...(wholeDay !== undefined && { wholeDay }),
|
|
61
36
|
...(description !== undefined && { description }),
|
|
62
37
|
...(location !== undefined && { location }),
|
|
63
38
|
...(recurrenceRule !== undefined && {
|
|
64
|
-
recurrenceRule: toRecurrenceRule(recurrenceRule),
|
|
39
|
+
recurrenceRule: toRecurrenceRule(recurrenceRule, wholeDay),
|
|
65
40
|
}),
|
|
66
41
|
});
|
|
67
42
|
return {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { toWholeDayDate } from "./whole-day-date.js";
|
|
3
|
+
export function toRecurrenceRule(r, wholeDay) {
|
|
4
|
+
const out = {};
|
|
5
|
+
if (r.freq !== undefined)
|
|
6
|
+
out.freq = r.freq;
|
|
7
|
+
if (r.interval !== undefined)
|
|
8
|
+
out.interval = r.interval;
|
|
9
|
+
if (r.count !== undefined)
|
|
10
|
+
out.count = r.count;
|
|
11
|
+
if (r.until !== undefined) {
|
|
12
|
+
out.until = wholeDay ? toWholeDayDate(r.until) : new Date(r.until);
|
|
13
|
+
}
|
|
14
|
+
if (r.byday !== undefined)
|
|
15
|
+
out.byday = r.byday;
|
|
16
|
+
if (r.bymonthday !== undefined)
|
|
17
|
+
out.bymonthday = r.bymonthday;
|
|
18
|
+
if (r.bymonth !== undefined)
|
|
19
|
+
out.bymonth = r.bymonth;
|
|
20
|
+
return out;
|
|
21
|
+
}
|
|
22
|
+
export const recurrenceRuleSchema = z.object({
|
|
23
|
+
freq: z.enum(["DAILY", "WEEKLY", "MONTHLY", "YEARLY"]).optional(),
|
|
24
|
+
interval: z.number().optional(),
|
|
25
|
+
count: z.number().optional(),
|
|
26
|
+
until: z.string().datetime({ offset: true }).optional(), // ISO 8601 string
|
|
27
|
+
byday: z.array(z.string()).optional(), // e.g. ["MO", "TU"]
|
|
28
|
+
bymonthday: z.array(z.number()).optional(),
|
|
29
|
+
bymonth: z.array(z.number()).optional(),
|
|
30
|
+
});
|
|
@@ -1,32 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { hrefFor } from "./caldav-href.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (r.freq !== undefined)
|
|
6
|
-
out.freq = r.freq;
|
|
7
|
-
if (r.interval !== undefined)
|
|
8
|
-
out.interval = r.interval;
|
|
9
|
-
if (r.count !== undefined)
|
|
10
|
-
out.count = r.count;
|
|
11
|
-
if (r.until !== undefined)
|
|
12
|
-
out.until = new Date(r.until);
|
|
13
|
-
if (r.byday !== undefined)
|
|
14
|
-
out.byday = r.byday;
|
|
15
|
-
if (r.bymonthday !== undefined)
|
|
16
|
-
out.bymonthday = r.bymonthday;
|
|
17
|
-
if (r.bymonth !== undefined)
|
|
18
|
-
out.bymonth = r.bymonth;
|
|
19
|
-
return out;
|
|
20
|
-
}
|
|
21
|
-
const recurrenceRuleSchema = z.object({
|
|
22
|
-
freq: z.enum(["DAILY", "WEEKLY", "MONTHLY", "YEARLY"]).optional(),
|
|
23
|
-
interval: z.number().optional(),
|
|
24
|
-
count: z.number().optional(),
|
|
25
|
-
until: z.string().datetime({ offset: true }).optional(),
|
|
26
|
-
byday: z.array(z.string()).optional(),
|
|
27
|
-
bymonthday: z.array(z.number()).optional(),
|
|
28
|
-
bymonth: z.array(z.number()).optional(),
|
|
29
|
-
});
|
|
3
|
+
import { recurrenceRuleSchema, toRecurrenceRule, } from "./recurrence-rule.js";
|
|
4
|
+
import { carryOverWholeDayDates, toWholeDayDate } from "./whole-day-date.js";
|
|
30
5
|
export const updateEventDefinition = {
|
|
31
6
|
name: "update-event",
|
|
32
7
|
description: "Updates an existing event in the calendar specified by its URL. Only provided fields are changed. For a one-day full-day event, set `wholeDay` to true and set `start` and `end` to the same calendar day.",
|
|
@@ -59,16 +34,24 @@ export function registerUpdateEvent(client, server) {
|
|
|
59
34
|
if (!existing) {
|
|
60
35
|
throw new Error(`Event not found: ${uid}`);
|
|
61
36
|
}
|
|
37
|
+
const effectiveWholeDay = wholeDay ?? existing.wholeDay;
|
|
62
38
|
const updated = await client.updateEvent(calendarUrl, {
|
|
63
39
|
...existing,
|
|
40
|
+
// Dates the caller doesn't pass are carried over; reshape them so the
|
|
41
|
+
// writer stores the same days. Explicit values below override these.
|
|
42
|
+
...(effectiveWholeDay && carryOverWholeDayDates(existing)),
|
|
64
43
|
...(summary !== undefined && { summary }),
|
|
65
|
-
...(start !== undefined && {
|
|
66
|
-
|
|
44
|
+
...(start !== undefined && {
|
|
45
|
+
start: effectiveWholeDay ? toWholeDayDate(start) : new Date(start),
|
|
46
|
+
}),
|
|
47
|
+
...(end !== undefined && {
|
|
48
|
+
end: effectiveWholeDay ? toWholeDayDate(end) : new Date(end),
|
|
49
|
+
}),
|
|
67
50
|
...(wholeDay !== undefined && { wholeDay }),
|
|
68
51
|
...(description !== undefined && { description }),
|
|
69
52
|
...(location !== undefined && { location }),
|
|
70
53
|
...(recurrenceRule !== undefined && {
|
|
71
|
-
recurrenceRule: toRecurrenceRule(recurrenceRule),
|
|
54
|
+
recurrenceRule: toRecurrenceRule(recurrenceRule, effectiveWholeDay),
|
|
72
55
|
}),
|
|
73
56
|
});
|
|
74
57
|
return {
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// ts-caldav and ical.js disagree about how a whole-day (`VALUE=DATE`) value is
|
|
2
|
+
// represented as a `Date`. ts-caldav writes each date it stores (DTSTART,
|
|
3
|
+
// DTEND, RRULE UNTIL, EXDATE, RDATE, RECURRENCE-ID) with
|
|
4
|
+
// `date.toISOString().split("T")[0]` (the UTC calendar day) and takes `end` as
|
|
5
|
+
// inclusive, adding a day itself to produce the exclusive DTEND. ical.js reads
|
|
6
|
+
// a `VALUE=DATE` back as local midnight, and reports DTEND as is (exclusive).
|
|
7
|
+
// The helpers below anchor a calendar day at UTC midnight, so the writer's
|
|
8
|
+
// `toISOString()` truncation stores exactly the day that was meant.
|
|
9
|
+
/**
|
|
10
|
+
* Converts an ISO 8601 datetime string to a `Date` representing the same
|
|
11
|
+
* calendar date at UTC midnight, for use with whole-day events.
|
|
12
|
+
*
|
|
13
|
+
* A `Date` built with `new Date(iso)` preserves the input's UTC *instant*, not
|
|
14
|
+
* its calendar date, so for any offset east of UTC ts-caldav's truncation
|
|
15
|
+
* silently rolls the stored date back by one day (e.g. local midnight
|
|
16
|
+
* `2026-09-30T00:00:00+09:00` becomes `2026-09-29T15:00:00.000Z`, which
|
|
17
|
+
* truncates to `2026-09-29`). Taking the date part of the string as written
|
|
18
|
+
* makes the truncation a no-op, so the calendar date the caller wrote is the
|
|
19
|
+
* calendar date that gets stored.
|
|
20
|
+
*/
|
|
21
|
+
export function toWholeDayDate(iso) {
|
|
22
|
+
return new Date(`${iso.slice(0, 10)}T00:00:00.000Z`);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Anchors the local calendar day of a `Date` read from the server at UTC
|
|
26
|
+
* midnight, so ts-caldav's writer stores that day again.
|
|
27
|
+
*
|
|
28
|
+
* ical.js hands a `VALUE=DATE` back as local midnight, which `toISOString()`
|
|
29
|
+
* turns into the previous day in any zone east of UTC. For a timed value
|
|
30
|
+
* (when a timed event becomes whole-day) the local day is the day the event
|
|
31
|
+
* shows on in this server's zone, which is also what UTC truncation misses.
|
|
32
|
+
*/
|
|
33
|
+
export function localDayToWholeDayDate(value) {
|
|
34
|
+
return new Date(Date.UTC(value.getFullYear(), value.getMonth(), value.getDate()));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Turns an end read from the server into the inclusive last day ts-caldav's
|
|
38
|
+
* writer expects, anchored at UTC midnight.
|
|
39
|
+
*
|
|
40
|
+
* A whole-day DTEND is exclusive (local midnight after the last day) and a
|
|
41
|
+
* timed end is the instant the event stops, so in both cases the last day is
|
|
42
|
+
* the local day of the instant just before `end`. It is never earlier than
|
|
43
|
+
* the start's day, so a zero-length event (DTEND equal to DTSTART) stays a
|
|
44
|
+
* valid one-day range instead of ending before it starts.
|
|
45
|
+
*/
|
|
46
|
+
export function inclusiveEndToWholeDayDate(end, start) {
|
|
47
|
+
const last = localDayToWholeDayDate(new Date(end.getTime() - 1));
|
|
48
|
+
const first = localDayToWholeDayDate(start);
|
|
49
|
+
return last < first ? first : last;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Reshapes every date of a stored event that an update carries over, so a
|
|
53
|
+
* whole-day event keeps its days when the caller changes something else.
|
|
54
|
+
*
|
|
55
|
+
* Covers DTSTART and DTEND as well as RRULE UNTIL, EXDATE, RDATE and
|
|
56
|
+
* RECURRENCE-ID: ts-caldav reads and writes them all the way described above,
|
|
57
|
+
* so leaving any one of them out moves it a day earlier east of UTC (an UNTIL
|
|
58
|
+
* that drops the last occurrence, an EXDATE that no longer excludes
|
|
59
|
+
* anything). Values the caller passes explicitly override these.
|
|
60
|
+
*/
|
|
61
|
+
export function carryOverWholeDayDates(existing) {
|
|
62
|
+
const carried = {
|
|
63
|
+
start: localDayToWholeDayDate(existing.start),
|
|
64
|
+
};
|
|
65
|
+
if (existing.end) {
|
|
66
|
+
carried.end = inclusiveEndToWholeDayDate(existing.end, existing.start);
|
|
67
|
+
}
|
|
68
|
+
if (existing.recurrenceRule?.until) {
|
|
69
|
+
carried.recurrenceRule = {
|
|
70
|
+
...existing.recurrenceRule,
|
|
71
|
+
until: localDayToWholeDayDate(existing.recurrenceRule.until),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (existing.exdates) {
|
|
75
|
+
carried.exdates = existing.exdates.map(localDayToWholeDayDate);
|
|
76
|
+
}
|
|
77
|
+
if (existing.rdates) {
|
|
78
|
+
carried.rdates = existing.rdates.map(localDayToWholeDayDate);
|
|
79
|
+
}
|
|
80
|
+
if (existing.recurrenceId) {
|
|
81
|
+
carried.recurrenceId = localDayToWholeDayDate(existing.recurrenceId);
|
|
82
|
+
}
|
|
83
|
+
return carried;
|
|
84
|
+
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "caldav-mcp",
|
|
3
3
|
"mcpName": "io.github.dominik1001/caldav-mcp",
|
|
4
4
|
"description": "A CalDAV client using Model Context Protocol (MCP) to expose calendar operations as tools for AI assistants.",
|
|
5
|
-
"version": "0.10.
|
|
5
|
+
"version": "0.10.2",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"bin": {
|