caldav-mcp 0.10.1 → 0.10.3
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/README.md +1 -1
- package/dist/tools/caldav-href.js +40 -0
- package/dist/tools/complete-todo.js +3 -2
- package/dist/tools/create-event.js +8 -31
- package/dist/tools/create-todo.js +3 -1
- package/dist/tools/delete-event.js +3 -2
- package/dist/tools/delete-todo.js +3 -2
- package/dist/tools/list-calendars.js +8 -2
- package/dist/tools/list-events.js +3 -1
- package/dist/tools/list-todos.js +2 -1
- package/dist/tools/recurrence-rule.js +30 -0
- package/dist/tools/update-event.js +16 -32
- package/dist/tools/update-todo.js +3 -2
- package/dist/tools/whole-day-date.js +84 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -73,7 +73,7 @@ node dist/index.js
|
|
|
73
73
|
<!-- TOOLS:START - generated by scripts/gen-tool-docs.ts -->
|
|
74
74
|
### list-calendars
|
|
75
75
|
|
|
76
|
-
List all calendars returning both name and URL
|
|
76
|
+
List all calendars returning both name and absolute URL. Pass a calendar's `url` unchanged as `calendarUrl` to the other tools.
|
|
77
77
|
|
|
78
78
|
Parameters: none
|
|
79
79
|
|
|
@@ -7,3 +7,43 @@ export function hrefFor(calendarUrl, uid) {
|
|
|
7
7
|
const base = calendarUrl.endsWith("/") ? calendarUrl : `${calendarUrl}/`;
|
|
8
8
|
return `${base}${uid}.ics`;
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Resolves a server-relative calendar href (as ts-caldav returns it) against
|
|
12
|
+
* the configured base URL, so agents get a URL they can pass back verbatim
|
|
13
|
+
* instead of guessing how to prefix it. Hrefs that are already absolute are
|
|
14
|
+
* left as they are. Credentials in the base URL are dropped: the result is
|
|
15
|
+
* shown to the LLM.
|
|
16
|
+
*/
|
|
17
|
+
export function toAbsoluteUrl(href, baseUrl) {
|
|
18
|
+
if (!href || !baseUrl)
|
|
19
|
+
return href;
|
|
20
|
+
try {
|
|
21
|
+
const url = new URL(href, baseUrl);
|
|
22
|
+
url.username = "";
|
|
23
|
+
url.password = "";
|
|
24
|
+
return url.toString();
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return href;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Inverse of `toAbsoluteUrl`: turns an absolute calendar URL on the configured
|
|
32
|
+
* server back into the server-relative path. ts-caldav writes object hrefs
|
|
33
|
+
* into calendar-multiget bodies verbatim, and not every server accepts
|
|
34
|
+
* absolute URLs there, so tools hand it paths only. Relative input and URLs
|
|
35
|
+
* on another origin pass through unchanged.
|
|
36
|
+
*/
|
|
37
|
+
export function toCalendarPath(calendarUrl, baseUrl) {
|
|
38
|
+
if (!baseUrl)
|
|
39
|
+
return calendarUrl;
|
|
40
|
+
try {
|
|
41
|
+
const url = new URL(calendarUrl);
|
|
42
|
+
if (url.origin !== new URL(baseUrl).origin)
|
|
43
|
+
return calendarUrl;
|
|
44
|
+
return `${url.pathname}${url.search}`;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return calendarUrl;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { hrefFor } from "./caldav-href.js";
|
|
2
|
+
import { hrefFor, toCalendarPath } from "./caldav-href.js";
|
|
3
3
|
export const completeTodoDefinition = {
|
|
4
4
|
name: "complete-todo",
|
|
5
5
|
description: "Marks a task (VTODO) as done. Sets its status to COMPLETED and records the completion time.",
|
|
@@ -16,7 +16,8 @@ export function registerCompleteTodo(client, server) {
|
|
|
16
16
|
description: completeTodoDefinition.description,
|
|
17
17
|
inputSchema: completeTodoDefinition.inputSchema,
|
|
18
18
|
}, async (args) => {
|
|
19
|
-
const { uid
|
|
19
|
+
const { uid } = args;
|
|
20
|
+
const calendarUrl = toCalendarPath(args.calendarUrl, client.baseUrl);
|
|
20
21
|
const href = hrefFor(calendarUrl, uid);
|
|
21
22
|
const [existing] = await client.getTodosByHref(calendarUrl, [href]);
|
|
22
23
|
if (!existing) {
|
|
@@ -1,31 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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 { toCalendarPath } from "./caldav-href.js";
|
|
3
|
+
import { recurrenceRuleSchema, toRecurrenceRule, } from "./recurrence-rule.js";
|
|
4
|
+
import { toWholeDayDate } from "./whole-day-date.js";
|
|
29
5
|
export const createEventDefinition = {
|
|
30
6
|
name: "create-event",
|
|
31
7
|
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.",
|
|
@@ -52,16 +28,17 @@ export function registerCreateEvent(client, server) {
|
|
|
52
28
|
description: createEventDefinition.description,
|
|
53
29
|
inputSchema: createEventDefinition.inputSchema,
|
|
54
30
|
}, async (args) => {
|
|
55
|
-
const {
|
|
31
|
+
const { summary, start, end, wholeDay, description, location, recurrenceRule, } = args;
|
|
32
|
+
const calendarUrl = toCalendarPath(args.calendarUrl, client.baseUrl);
|
|
56
33
|
const event = await client.createEvent(calendarUrl, {
|
|
57
34
|
summary: summary,
|
|
58
|
-
start: new Date(start),
|
|
59
|
-
end: new Date(end),
|
|
35
|
+
start: wholeDay ? toWholeDayDate(start) : new Date(start),
|
|
36
|
+
end: wholeDay ? toWholeDayDate(end) : new Date(end),
|
|
60
37
|
...(wholeDay !== undefined && { wholeDay }),
|
|
61
38
|
...(description !== undefined && { description }),
|
|
62
39
|
...(location !== undefined && { location }),
|
|
63
40
|
...(recurrenceRule !== undefined && {
|
|
64
|
-
recurrenceRule: toRecurrenceRule(recurrenceRule),
|
|
41
|
+
recurrenceRule: toRecurrenceRule(recurrenceRule, wholeDay),
|
|
65
42
|
}),
|
|
66
43
|
});
|
|
67
44
|
return {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { toCalendarPath } from "./caldav-href.js";
|
|
2
3
|
import { todoStatusSchema } from "./todo-status.js";
|
|
3
4
|
export const createTodoDefinition = {
|
|
4
5
|
name: "create-todo",
|
|
@@ -29,7 +30,8 @@ export function registerCreateTodo(client, server) {
|
|
|
29
30
|
description: createTodoDefinition.description,
|
|
30
31
|
inputSchema: createTodoDefinition.inputSchema,
|
|
31
32
|
}, async (args) => {
|
|
32
|
-
const {
|
|
33
|
+
const { summary, due, start, description, location, status } = args;
|
|
34
|
+
const calendarUrl = toCalendarPath(args.calendarUrl, client.baseUrl);
|
|
33
35
|
const todo = await client.createTodo(calendarUrl, {
|
|
34
36
|
summary,
|
|
35
37
|
...(due !== undefined && { due: new Date(due) }),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { hrefFor } from "./caldav-href.js";
|
|
2
|
+
import { hrefFor, toCalendarPath } from "./caldav-href.js";
|
|
3
3
|
export const deleteEventDefinition = {
|
|
4
4
|
name: "delete-event",
|
|
5
5
|
description: "Deletes an event in the calendar specified by its URL",
|
|
@@ -16,7 +16,8 @@ export function registerDeleteEvent(client, server) {
|
|
|
16
16
|
description: deleteEventDefinition.description,
|
|
17
17
|
inputSchema: deleteEventDefinition.inputSchema,
|
|
18
18
|
}, async (args) => {
|
|
19
|
-
const { uid
|
|
19
|
+
const { uid } = args;
|
|
20
|
+
const calendarUrl = toCalendarPath(args.calendarUrl, client.baseUrl);
|
|
20
21
|
const etag = await client.getETag(hrefFor(calendarUrl, uid));
|
|
21
22
|
await client.deleteEvent(calendarUrl, uid, etag);
|
|
22
23
|
return {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CalDAVError } from "ts-caldav";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { hrefFor } from "./caldav-href.js";
|
|
3
|
+
import { hrefFor, toCalendarPath } from "./caldav-href.js";
|
|
4
4
|
export const deleteTodoDefinition = {
|
|
5
5
|
name: "delete-todo",
|
|
6
6
|
description: "Deletes a task (VTODO) in the calendar specified by its URL",
|
|
@@ -17,7 +17,8 @@ export function registerDeleteTodo(client, server) {
|
|
|
17
17
|
description: deleteTodoDefinition.description,
|
|
18
18
|
inputSchema: deleteTodoDefinition.inputSchema,
|
|
19
19
|
}, async (args) => {
|
|
20
|
-
const { uid
|
|
20
|
+
const { uid } = args;
|
|
21
|
+
const calendarUrl = toCalendarPath(args.calendarUrl, client.baseUrl);
|
|
21
22
|
// Map a missing object onto the same friendly message complete-todo and
|
|
22
23
|
// update-todo raise, so all three todo tools report a missing task the
|
|
23
24
|
// same way. (delete-event still surfaces the raw transport error; the
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
+
import { toAbsoluteUrl } from "./caldav-href.js";
|
|
1
2
|
export const listCalendarsDefinition = {
|
|
2
3
|
name: "list-calendars",
|
|
3
|
-
description: "List all calendars returning both name and URL",
|
|
4
|
+
description: "List all calendars returning both name and absolute URL. Pass a calendar's `url` unchanged as `calendarUrl` to the other tools.",
|
|
4
5
|
inputSchema: {},
|
|
5
6
|
returns: "List of all available calendars",
|
|
6
7
|
};
|
|
7
8
|
export async function registerListCalendars(client, server) {
|
|
8
|
-
|
|
9
|
+
// ts-caldav returns server-relative hrefs; resolve them so agents don't
|
|
10
|
+
// have to guess how to prefix the base URL.
|
|
11
|
+
const calendars = (await client.getCalendars()).map((calendar) => ({
|
|
12
|
+
...calendar,
|
|
13
|
+
url: toAbsoluteUrl(calendar.url, client.baseUrl),
|
|
14
|
+
}));
|
|
9
15
|
server.registerTool(listCalendarsDefinition.name, {
|
|
10
16
|
description: listCalendarsDefinition.description,
|
|
11
17
|
inputSchema: listCalendarsDefinition.inputSchema,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { toCalendarPath } from "./caldav-href.js";
|
|
2
3
|
export const listEventsDefinition = {
|
|
3
4
|
name: "list-events",
|
|
4
5
|
description: "List all events between start and end date in the calendar specified by its URL",
|
|
@@ -24,7 +25,8 @@ export function registerListEvents(client, server) {
|
|
|
24
25
|
description: listEventsDefinition.description,
|
|
25
26
|
inputSchema: listEventsDefinition.inputSchema,
|
|
26
27
|
}, async (args) => {
|
|
27
|
-
const {
|
|
28
|
+
const { start, end } = args;
|
|
29
|
+
const calendarUrl = toCalendarPath(args.calendarUrl, client.baseUrl);
|
|
28
30
|
const options = {
|
|
29
31
|
start: new Date(start),
|
|
30
32
|
end: new Date(end),
|
package/dist/tools/list-todos.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { toCalendarPath } from "./caldav-href.js";
|
|
2
3
|
import { todoStatusSchema } from "./todo-status.js";
|
|
3
4
|
// `OPEN`/`ALL` are filter keywords expressing sets no single status can (a union
|
|
4
5
|
// and "no filter"); the four raw statuses allow an exact-status query. The raw
|
|
@@ -69,7 +70,7 @@ export function registerListTodos(client, server) {
|
|
|
69
70
|
description: listTodosDefinition.description,
|
|
70
71
|
inputSchema: listTodosDefinition.inputSchema,
|
|
71
72
|
}, async (args) => {
|
|
72
|
-
const
|
|
73
|
+
const calendarUrl = toCalendarPath(args.calendarUrl, client.baseUrl);
|
|
73
74
|
const status = args.status ?? "OPEN";
|
|
74
75
|
const limit = args.limit ?? 50;
|
|
75
76
|
const offset = args.offset ?? 0;
|
|
@@ -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
|
-
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
|
-
});
|
|
2
|
+
import { hrefFor, toCalendarPath } from "./caldav-href.js";
|
|
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.",
|
|
@@ -53,22 +28,31 @@ export function registerUpdateEvent(client, server) {
|
|
|
53
28
|
description: updateEventDefinition.description,
|
|
54
29
|
inputSchema: updateEventDefinition.inputSchema,
|
|
55
30
|
}, async (args) => {
|
|
56
|
-
const { uid,
|
|
31
|
+
const { uid, summary, start, end, wholeDay, description, location, recurrenceRule, } = args;
|
|
32
|
+
const calendarUrl = toCalendarPath(args.calendarUrl, client.baseUrl);
|
|
57
33
|
const href = hrefFor(calendarUrl, uid);
|
|
58
34
|
const [existing] = await client.getEventsByHref(calendarUrl, [href]);
|
|
59
35
|
if (!existing) {
|
|
60
36
|
throw new Error(`Event not found: ${uid}`);
|
|
61
37
|
}
|
|
38
|
+
const effectiveWholeDay = wholeDay ?? existing.wholeDay;
|
|
62
39
|
const updated = await client.updateEvent(calendarUrl, {
|
|
63
40
|
...existing,
|
|
41
|
+
// Dates the caller doesn't pass are carried over; reshape them so the
|
|
42
|
+
// writer stores the same days. Explicit values below override these.
|
|
43
|
+
...(effectiveWholeDay && carryOverWholeDayDates(existing)),
|
|
64
44
|
...(summary !== undefined && { summary }),
|
|
65
|
-
...(start !== undefined && {
|
|
66
|
-
|
|
45
|
+
...(start !== undefined && {
|
|
46
|
+
start: effectiveWholeDay ? toWholeDayDate(start) : new Date(start),
|
|
47
|
+
}),
|
|
48
|
+
...(end !== undefined && {
|
|
49
|
+
end: effectiveWholeDay ? toWholeDayDate(end) : new Date(end),
|
|
50
|
+
}),
|
|
67
51
|
...(wholeDay !== undefined && { wholeDay }),
|
|
68
52
|
...(description !== undefined && { description }),
|
|
69
53
|
...(location !== undefined && { location }),
|
|
70
54
|
...(recurrenceRule !== undefined && {
|
|
71
|
-
recurrenceRule: toRecurrenceRule(recurrenceRule),
|
|
55
|
+
recurrenceRule: toRecurrenceRule(recurrenceRule, effectiveWholeDay),
|
|
72
56
|
}),
|
|
73
57
|
});
|
|
74
58
|
return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { hrefFor } from "./caldav-href.js";
|
|
2
|
+
import { hrefFor, toCalendarPath } from "./caldav-href.js";
|
|
3
3
|
import { todoStatusSchema } from "./todo-status.js";
|
|
4
4
|
export const updateTodoDefinition = {
|
|
5
5
|
name: "update-todo",
|
|
@@ -23,7 +23,8 @@ export function registerUpdateTodo(client, server) {
|
|
|
23
23
|
description: updateTodoDefinition.description,
|
|
24
24
|
inputSchema: updateTodoDefinition.inputSchema,
|
|
25
25
|
}, async (args) => {
|
|
26
|
-
const { uid,
|
|
26
|
+
const { uid, summary, due, start, description, location, status } = args;
|
|
27
|
+
const calendarUrl = toCalendarPath(args.calendarUrl, client.baseUrl);
|
|
27
28
|
const href = hrefFor(calendarUrl, uid);
|
|
28
29
|
const [existing] = await client.getTodosByHref(calendarUrl, [href]);
|
|
29
30
|
if (!existing) {
|
|
@@ -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.3",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"bin": {
|