@miguelarios/cal-mcp 0.21.0 → 2.0.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.
@@ -1,9 +1,10 @@
1
1
  import { randomUUID } from "node:crypto";
2
- import { getLocalDateParts, getTimezone, zonedTimeToUtc } from "@miguelarios/pim-core";
3
- import { addExdateToIcs, combineIcsComponents, createExceptionComponent, formatTriggerHuman, generateEventIcs, removeExceptionFromIcs, splitIcsByUid, splitRecurrenceIcs, truncateRecurrenceIcs, updateMasterEventIcs, } from "@miguelarios/pim-core/ics";
2
+ import { ErrorCode, getLocalDateParts, getTimezone, zonedTimeToUtc } from "@miguelarios/pim-core";
3
+ import { IcsGenerateError, IcsParseError, addExdateToIcs, combineIcsComponents, createExceptionComponent, formatTriggerHuman, generateEventIcs, removeExceptionFromIcs, splitIcsByUid, splitRecurrenceIcs, truncateRecurrenceIcs, updateMasterEventIcs, } from "@miguelarios/pim-core/ics";
4
4
  import { confirmDestructive, fail, structured, toolError, } from "@miguelarios/pim-core/mcp";
5
5
  import { drainDebugTimings } from "../services/CalDavService.js";
6
6
  import { batchCreateSchema, calendarListSchema, deleteResultSchema, eventListSchema, freeBusySchema, freeSlotsSchema, importResultSchema, singleEventSchema, } from "./calendarSchemas.js";
7
+ import { presentPayload } from "./presentEvent.js";
7
8
  /**
8
9
  * The `update_event` fields that are forwarded verbatim to the ICS layer on
9
10
  * both branches. Typed against `ExceptionOverrides` and `MasterEventUpdates`
@@ -14,7 +15,7 @@ const UPDATABLE_FIELDS = [
14
15
  "title",
15
16
  "start",
16
17
  "end",
17
- "all_day",
18
+ "allDay",
18
19
  "location",
19
20
  "description",
20
21
  "attendees",
@@ -39,7 +40,7 @@ function selectedCalendars(args) {
39
40
  }
40
41
  /** Spread into a listing result: the providers it skipped, when there were any. */
41
42
  function unavailableField(unavailable) {
42
- return unavailable.length > 0 ? { unavailable_providers: unavailable } : {};
43
+ return unavailable.length > 0 ? { unavailableProviders: unavailable } : {};
43
44
  }
44
45
  /**
45
46
  * Events in [start, end) on the selected calendars, or on every reachable
@@ -53,7 +54,7 @@ async function fetchEvents(service, selection, start, end, detailLevel) {
53
54
  let unavailable = [];
54
55
  if (calendarIds.length === 0) {
55
56
  const reachable = await service.listReachableCalendars();
56
- calendarIds = reachable.calendars.map((cal) => cal.calendar_id);
57
+ calendarIds = reachable.calendars.map((cal) => cal.calendarId);
57
58
  unavailable = reachable.unavailable;
58
59
  }
59
60
  const results = await Promise.all(calendarIds.map((id) => full ? service.listEventsFull(id, start, end) : service.listEvents(id, start, end)));
@@ -71,28 +72,44 @@ function debugMeta() {
71
72
  return undefined;
72
73
  return { _meta: { "com.miguelarios.cal-mcp/debug": { timings } } };
73
74
  }
75
+ /**
76
+ * Every successful result goes out through here, so this is where event times
77
+ * are rendered for the caller (see `presentEvent`); handlers keep working in
78
+ * UTC instants.
79
+ */
74
80
  function ok(payload) {
75
- return { ...structured(payload), ...debugMeta() };
81
+ return { ...structured(presentPayload(payload, getTimezone())), ...debugMeta() };
76
82
  }
77
83
  function calFail(code, message, retryable = false) {
78
84
  return { ...fail(code, message, retryable), ...debugMeta() };
79
85
  }
86
+ /** A `VALIDATION_FAILED` result unless `start` and `end` parse and `start` comes first. */
87
+ function checkRange(start, end) {
88
+ const startMs = new Date(start).getTime();
89
+ const endMs = new Date(end).getTime();
90
+ if (Number.isNaN(startMs) || Number.isNaN(endMs) || startMs >= endMs) {
91
+ return calFail(ErrorCode.VALIDATION_FAILED, "start and end must be ISO 8601 with start before end");
92
+ }
93
+ return undefined;
94
+ }
80
95
  /**
81
- * Preserves this server's external error vocabulary (`not_found`,
82
- * `validation_error`, `backend_error`) while letting the underlying
83
- * `PimError` message through.
96
+ * A `VALIDATION_FAILED` result unless `occurrenceDate` parses. Checked before
97
+ * anything is written: an unparseable date reaches the ICS helpers as `NaN`,
98
+ * and `addExdateToIcs` would store `EXDATE:NaN-aNNaN…` on the server.
84
99
  */
85
- function mapError(err) {
86
- if (err && typeof err === "object" && "code" in err) {
87
- const code = err.code;
88
- if (code === "CALENDAR_NOT_FOUND" || code === "EVENT_NOT_FOUND") {
89
- return { ...toolError(err, () => "not_found"), ...debugMeta() };
90
- }
91
- if (code === "VALIDATION_FAILED") {
92
- return { ...toolError(err, () => "validation_error"), ...debugMeta() };
93
- }
100
+ function checkOccurrenceDate(occurrenceDate) {
101
+ if (Number.isNaN(new Date(occurrenceDate).getTime())) {
102
+ return calFail(ErrorCode.VALIDATION_FAILED, `Invalid occurrenceDate "${occurrenceDate}" — use an ISO 8601 date-time`);
94
103
  }
95
- return { ...toolError(err, () => "backend_error"), ...debugMeta() };
104
+ return undefined;
105
+ }
106
+ /**
107
+ * Reports a thrown error with its pim-core `ErrorCode` (`CALENDAR_NOT_FOUND`,
108
+ * `VALIDATION_FAILED`, `CONNECTION_FAILED`, …), the same vocabulary card-mcp
109
+ * and email-mcp return.
110
+ */
111
+ function mapError(err) {
112
+ return { ...toolError(err), ...debugMeta() };
96
113
  }
97
114
  /**
98
115
  * Widens an attendee from the tool's input shape (`{ email }`) to the shape a
@@ -109,11 +126,11 @@ function toResponseAttendee(attendee) {
109
126
  type: "person",
110
127
  };
111
128
  }
112
- /** Widens an alarm from the tool's input shape by rendering `trigger_human`. */
129
+ /** Widens an alarm from the tool's input shape by rendering `triggerHuman`. */
113
130
  function toResponseAlarm(alarm) {
114
131
  return {
115
132
  ...alarm,
116
- trigger_human: alarm.type === "absolute"
133
+ triggerHuman: alarm.type === "absolute"
117
134
  ? new Date(alarm.trigger).toISOString()
118
135
  : formatTriggerHuman(Number(alarm.trigger)),
119
136
  };
@@ -210,13 +227,16 @@ export const CALENDAR_TOOLS = [
210
227
  calendars: CALENDARS_PROP("query"),
211
228
  start: { type: "string", description: "Start of date range (ISO 8601)" },
212
229
  end: { type: "string", description: "End of date range (ISO 8601)" },
213
- detail_level: DETAIL_LEVEL_PROP,
230
+ detailLevel: DETAIL_LEVEL_PROP,
214
231
  },
215
232
  required: ["start", "end"],
216
233
  },
217
234
  outputSchema: eventListSchema,
218
235
  handler: (args, service) => run(async () => {
219
- const { events, unavailable } = await fetchEvents(service, args, args.start, args.end, args.detail_level ?? "summary");
236
+ const invalid = checkRange(args.start, args.end);
237
+ if (invalid)
238
+ return invalid;
239
+ const { events, unavailable } = await fetchEvents(service, args, args.start, args.end, args.detailLevel ?? "summary");
220
240
  return ok({ events, ...unavailableField(unavailable) });
221
241
  }),
222
242
  },
@@ -233,7 +253,7 @@ export const CALENDAR_TOOLS = [
233
253
  description: "Provider-prefixed calendar ID. If omitted, queries all calendars.",
234
254
  },
235
255
  calendars: CALENDARS_PROP("query"),
236
- detail_level: DETAIL_LEVEL_PROP,
256
+ detailLevel: DETAIL_LEVEL_PROP,
237
257
  },
238
258
  },
239
259
  outputSchema: eventListSchema,
@@ -242,7 +262,7 @@ export const CALENDAR_TOOLS = [
242
262
  const { year, month, day } = getLocalDateParts(new Date(), tz);
243
263
  const todayStart = zonedTimeToUtc(year, month, day, 0, 0, tz).toISOString();
244
264
  const todayEnd = zonedTimeToUtc(year, month, day + 1, 0, 0, tz).toISOString();
245
- const { events, unavailable } = await fetchEvents(service, args, todayStart, todayEnd, args.detail_level ?? "summary");
265
+ const { events, unavailable } = await fetchEvents(service, args, todayStart, todayEnd, args.detailLevel ?? "summary");
246
266
  return ok({ events, ...unavailableField(unavailable) });
247
267
  }),
248
268
  },
@@ -268,17 +288,20 @@ export const CALENDAR_TOOLS = [
268
288
  type: "string",
269
289
  description: "Range end (ISO 8601). Defaults to 90 days ahead.",
270
290
  },
271
- detail_level: DETAIL_LEVEL_PROP,
291
+ detailLevel: DETAIL_LEVEL_PROP,
272
292
  },
273
293
  required: ["query"],
274
294
  },
275
295
  outputSchema: eventListSchema,
276
296
  handler: (args, service) => run(async () => {
277
297
  const query = args.query.toLowerCase();
278
- const detailLevel = args.detail_level ?? "summary";
298
+ const detailLevel = args.detailLevel ?? "summary";
279
299
  const now = new Date();
280
300
  const start = args.start ?? new Date(now.getTime() - 90 * 86400000).toISOString();
281
301
  const end = args.end ?? new Date(now.getTime() + 90 * 86400000).toISOString();
302
+ const invalid = checkRange(start, end);
303
+ if (invalid)
304
+ return invalid;
282
305
  const { events, unavailable } = await fetchEvents(service, args, start, end, detailLevel);
283
306
  const matched = events.filter((e) => {
284
307
  const title = e.title?.toLowerCase() ?? "";
@@ -292,22 +315,22 @@ export const CALENDAR_TOOLS = [
292
315
  {
293
316
  name: "get_event",
294
317
  title: "Get Event",
295
- description: "Get full details of a single event by calendar and UID. For a recurring event, pass occurrence_date to get one occurrence as it will actually happen — including any changes made to just that occurrence — instead of the master series.",
318
+ description: "Get full details of a single event by calendar and UID. For a recurring event, pass occurrenceDate to get one occurrence as it will actually happen — including any changes made to just that occurrence — instead of the master series.",
296
319
  annotations: READ_ONLY,
297
320
  inputSchema: {
298
321
  type: "object",
299
322
  properties: {
300
323
  calendar: CALENDAR_PROP,
301
324
  uid: { type: "string", description: "Event UID" },
302
- occurrence_date: {
325
+ occurrenceDate: {
303
326
  type: "string",
304
- description: "ISO 8601 date-time of one occurrence of a recurring event, as returned in list_events results. Returns that occurrence (with any per-occurrence overrides applied) rather than the master series. Omit to get the master.",
327
+ description: "One occurrence of a recurring event, as the occurrenceDate list_events returned for it (an ISO 8601 date-time, or a date for an all-day series). Returns that occurrence (with any per-occurrence overrides applied) rather than the master series. Omit to get the master.",
305
328
  },
306
329
  },
307
330
  required: ["calendar", "uid"],
308
331
  },
309
332
  outputSchema: singleEventSchema,
310
- handler: (args, service) => run(async () => ok({ event: await service.getEvent(args.calendar, args.uid, args.occurrence_date) })),
333
+ handler: (args, service) => run(async () => ok({ event: await service.getEvent(args.calendar, args.uid, args.occurrenceDate) })),
311
334
  },
312
335
  {
313
336
  name: "create_event",
@@ -326,13 +349,13 @@ export const CALENDAR_TOOLS = [
326
349
  title: { type: "string", description: "Event title" },
327
350
  start: { type: "string", description: "Start time (ISO 8601)" },
328
351
  end: { type: "string", description: "End time (ISO 8601)" },
329
- all_day: { type: "boolean", description: "All-day event flag (default: false)" },
352
+ allDay: { type: "boolean", description: "All-day event flag (default: false)" },
330
353
  location: { type: "string", description: "Event location" },
331
354
  description: { type: "string", description: "Event description" },
332
355
  attendees: ATTENDEES_PROP("List of attendee email addresses to invite."),
333
356
  alarms: ALARMS_PROP,
334
357
  categories: CATEGORIES_PROP,
335
- recurrence_rule: {
358
+ recurrenceRule: {
336
359
  type: "string",
337
360
  description: "RFC 5545 RRULE string for a recurring event (e.g., 'FREQ=WEEKLY;BYDAY=MO,WE,FR' or 'FREQ=MONTHLY;BYDAY=+3FR;COUNT=12'). Accepted with or without the 'RRULE:' prefix. FREQ is required.",
338
361
  },
@@ -356,13 +379,13 @@ export const CALENDAR_TOOLS = [
356
379
  title: args.title,
357
380
  start: args.start,
358
381
  end: args.end,
359
- all_day: args.all_day ?? false,
382
+ allDay: args.allDay ?? false,
360
383
  location: args.location,
361
384
  description: args.description,
362
385
  attendees: args.attendees,
363
386
  alarms: args.alarms,
364
387
  categories: args.categories,
365
- recurrence_rule: args.recurrence_rule,
388
+ recurrenceRule: args.recurrenceRule,
366
389
  organizer,
367
390
  availability: args.availability,
368
391
  timezone: getTimezone(),
@@ -372,8 +395,8 @@ export const CALENDAR_TOOLS = [
372
395
  return ok({ event: await service.createEvent(args.calendar, icsString, uid) });
373
396
  }
374
397
  catch (err) {
375
- if (err instanceof Error && err.message.startsWith("Invalid recurrence_rule:")) {
376
- return calFail("validation_error", err.message);
398
+ if (err instanceof IcsGenerateError) {
399
+ return calFail(ErrorCode.VALIDATION_FAILED, err.message);
377
400
  }
378
401
  throw err;
379
402
  }
@@ -397,13 +420,13 @@ export const CALENDAR_TOOLS = [
397
420
  title: { type: "string", description: "New event title" },
398
421
  start: { type: "string", description: "New start time (ISO 8601)" },
399
422
  end: { type: "string", description: "New end time (ISO 8601)" },
400
- all_day: { type: "boolean", description: "All-day event flag" },
423
+ allDay: { type: "boolean", description: "All-day event flag" },
401
424
  location: { type: "string", description: "New location" },
402
425
  description: { type: "string", description: "New description" },
403
426
  attendees: ATTENDEES_PROP("New attendee list (replaces existing)."),
404
427
  alarms: ALARMS_PROP,
405
428
  categories: CATEGORIES_PROP,
406
- occurrence_date: {
429
+ occurrenceDate: {
407
430
  type: "string",
408
431
  description: "ISO 8601 date of the specific occurrence to modify. Required when span is 'this' or 'future' on a recurring event. Get this value from list_events results.",
409
432
  },
@@ -425,11 +448,14 @@ export const CALENDAR_TOOLS = [
425
448
  const span = args.span ?? "this";
426
449
  const { event: existing } = await service.getEventWithMeta(args.calendar, args.uid);
427
450
  // span="this" on a recurring event: create exception VEVENT
428
- if (existing.is_recurring && span === "this") {
429
- if (!args.occurrence_date) {
430
- return calFail("validation_error", "occurrence_date is required when span is 'this' on a recurring event");
451
+ if (existing.isRecurring && span === "this") {
452
+ if (!args.occurrenceDate) {
453
+ return calFail(ErrorCode.VALIDATION_FAILED, "occurrenceDate is required when span is 'this' on a recurring event");
431
454
  }
432
- const occurrenceDate = args.occurrence_date;
455
+ const occurrenceDate = args.occurrenceDate;
456
+ const invalidDate = checkOccurrenceDate(occurrenceDate);
457
+ if (invalidDate)
458
+ return invalidDate;
433
459
  const rawObj = await service.fetchRawCalendarObject(args.calendar, args.uid);
434
460
  const overrides = {};
435
461
  for (const field of UPDATABLE_FIELDS)
@@ -440,7 +466,7 @@ export const CALENDAR_TOOLS = [
440
466
  if (effectiveAttendees && effectiveAttendees.length > 0 && !existing.organizer) {
441
467
  overrides.organizer = { email: service.getAccountEmail(args.calendar) };
442
468
  }
443
- const exceptionVevent = createExceptionComponent(rawObj.data, "vevent", occurrenceDate, overrides, existing.all_day);
469
+ const exceptionVevent = createExceptionComponent(rawObj.data, "vevent", occurrenceDate, overrides, existing.allDay);
444
470
  const combinedIcs = combineIcsComponents(rawObj.data, exceptionVevent);
445
471
  await service.updateEvent(args.calendar, args.uid, combinedIcs, {
446
472
  url: rawObj.url,
@@ -459,7 +485,10 @@ export const CALENDAR_TOOLS = [
459
485
  start: overrides.start ?? occurrenceDate,
460
486
  end: overrides.end ??
461
487
  new Date(new Date(occurrenceDate).getTime() + occDuration).toISOString(),
462
- all_day: overrides.all_day ?? existing.all_day,
488
+ allDay: overrides.allDay ?? existing.allDay,
489
+ // createExceptionComponent writes the override's DTSTART in UTC,
490
+ // or as a date when it is all-day: report what a re-read would.
491
+ timeZone: (overrides.allDay ?? existing.allDay) ? null : "UTC",
463
492
  location: overrides.location ?? existing.location,
464
493
  description: overrides.description ?? existing.description,
465
494
  attendees: overrides.attendees
@@ -470,8 +499,8 @@ export const CALENDAR_TOOLS = [
470
499
  ? { name: overrides.organizer.name ?? null, email: overrides.organizer.email }
471
500
  : existing.organizer,
472
501
  categories: overrides.categories ?? existing.categories,
473
- occurrence_date: occurrenceDate,
474
- recurrence_rule: null,
502
+ occurrenceDate: occurrenceDate,
503
+ recurrenceRule: null,
475
504
  },
476
505
  });
477
506
  }
@@ -490,22 +519,22 @@ export const CALENDAR_TOOLS = [
490
519
  // (new UID) carries the remaining pattern with the changes applied.
491
520
  // A cut at the first occurrence has nothing to keep behind it, so it
492
521
  // falls through to the whole-series edit below (#38).
493
- if (existing.is_recurring && span === "future") {
494
- if (!args.occurrence_date) {
495
- return calFail("validation_error", "occurrence_date is required when span is 'future' on a recurring event");
496
- }
497
- const occurrenceDate = args.occurrence_date;
498
- if (Number.isNaN(new Date(occurrenceDate).getTime())) {
499
- return calFail("validation_error", `Invalid occurrence_date "${occurrenceDate}" — use an ISO 8601 date-time`);
522
+ if (existing.isRecurring && span === "future") {
523
+ if (!args.occurrenceDate) {
524
+ return calFail(ErrorCode.VALIDATION_FAILED, "occurrenceDate is required when span is 'future' on a recurring event");
500
525
  }
526
+ const occurrenceDate = args.occurrenceDate;
527
+ const invalidDate = checkOccurrenceDate(occurrenceDate);
528
+ if (invalidDate)
529
+ return invalidDate;
501
530
  const newUid = `${randomUUID()}@pim-core`;
502
531
  let split;
503
532
  try {
504
- split = splitRecurrenceIcs(rawObj.data, occurrenceDate, existing.all_day, newUid);
533
+ split = splitRecurrenceIcs(rawObj.data, occurrenceDate, existing.allDay, newUid);
505
534
  }
506
535
  catch (err) {
507
536
  if (err instanceof Error && err.message.startsWith("No occurrence at")) {
508
- return calFail("validation_error", err.message);
537
+ return calFail(ErrorCode.VALIDATION_FAILED, err.message);
509
538
  }
510
539
  throw err;
511
540
  }
@@ -564,18 +593,18 @@ export const CALENDAR_TOOLS = [
564
593
  properties: {
565
594
  calendar: CALENDAR_PROP,
566
595
  uid: { type: "string", description: "Event UID to move" },
567
- target_calendar: {
596
+ targetCalendar: {
568
597
  type: "string",
569
598
  description: "Destination provider-prefixed calendar ID, on the same account",
570
599
  },
571
600
  },
572
- required: ["calendar", "uid", "target_calendar"],
601
+ required: ["calendar", "uid", "targetCalendar"],
573
602
  },
574
603
  outputSchema: singleEventSchema,
575
604
  handler: (args, service) => run(async () => {
576
605
  const { meta } = await service.getEventWithMeta(args.calendar, args.uid);
577
606
  return ok({
578
- event: await service.moveEvent(args.calendar, args.uid, args.target_calendar, meta),
607
+ event: await service.moveEvent(args.calendar, args.uid, args.targetCalendar, meta),
579
608
  });
580
609
  }),
581
610
  },
@@ -594,7 +623,7 @@ export const CALENDAR_TOOLS = [
594
623
  properties: {
595
624
  calendar: CALENDAR_PROP,
596
625
  uid: { type: "string", description: "Event UID to delete" },
597
- occurrence_date: {
626
+ occurrenceDate: {
598
627
  type: "string",
599
628
  description: "ISO 8601 date of the specific occurrence to delete. Required when span is 'this' or 'future' on a recurring event. Get this value from list_events results.",
600
629
  },
@@ -616,18 +645,18 @@ export const CALENDAR_TOOLS = [
616
645
  if (span === "future") {
617
646
  return run(async () => {
618
647
  const { event: existing, meta: eventMeta } = await service.getEventWithMeta(args.calendar, args.uid);
619
- if (!existing.is_recurring) {
620
- return calFail("validation_error", `Event "${args.uid}" is not recurring — use span 'all' to delete it`);
621
- }
622
- if (!args.occurrence_date) {
623
- return calFail("validation_error", "occurrence_date is required when span is 'future' on a recurring event");
648
+ if (!existing.isRecurring) {
649
+ return calFail(ErrorCode.VALIDATION_FAILED, `Event "${args.uid}" is not recurring — use span 'all' to delete it`);
624
650
  }
625
- const occurrenceDate = args.occurrence_date;
626
- if (Number.isNaN(new Date(occurrenceDate).getTime())) {
627
- return calFail("validation_error", `Invalid occurrence_date "${occurrenceDate}" — use an ISO 8601 date-time`);
651
+ if (!args.occurrenceDate) {
652
+ return calFail(ErrorCode.VALIDATION_FAILED, "occurrenceDate is required when span is 'future' on a recurring event");
628
653
  }
654
+ const occurrenceDate = args.occurrenceDate;
655
+ const invalidDate = checkOccurrenceDate(occurrenceDate);
656
+ if (invalidDate)
657
+ return invalidDate;
629
658
  const rawObj = await service.fetchRawCalendarObject(args.calendar, args.uid);
630
- const truncated = truncateRecurrenceIcs(rawObj.data, occurrenceDate, existing.all_day);
659
+ const truncated = truncateRecurrenceIcs(rawObj.data, occurrenceDate, existing.allDay);
631
660
  // Nothing would remain: the cut is at or before the first occurrence,
632
661
  // so this is a whole-series delete and is treated as one.
633
662
  if (truncated === null) {
@@ -657,17 +686,20 @@ export const CALENDAR_TOOLS = [
657
686
  if (span === "this") {
658
687
  return run(async () => {
659
688
  const { event: existing, meta: eventMeta } = await service.getEventWithMeta(args.calendar, args.uid);
660
- if (existing.is_recurring) {
661
- if (!args.occurrence_date) {
662
- return calFail("validation_error", "occurrence_date is required when span is 'this' on a recurring event");
689
+ if (existing.isRecurring) {
690
+ if (!args.occurrenceDate) {
691
+ return calFail(ErrorCode.VALIDATION_FAILED, "occurrenceDate is required when span is 'this' on a recurring event");
663
692
  }
664
- const occurrenceDate = args.occurrence_date;
693
+ const occurrenceDate = args.occurrenceDate;
694
+ const invalidDate = checkOccurrenceDate(occurrenceDate);
695
+ if (invalidDate)
696
+ return invalidDate;
665
697
  const rawObj = await service.fetchRawCalendarObject(args.calendar, args.uid);
666
- let updatedIcs = addExdateToIcs(rawObj.data, occurrenceDate, existing.all_day);
698
+ let updatedIcs = addExdateToIcs(rawObj.data, occurrenceDate, existing.allDay);
667
699
  // Remove any existing exception VEVENT/VTODO for this occurrence,
668
700
  // matching by resolved instant (handles both UTC and TZID-form
669
701
  // RECURRENCE-ID) rather than a literal-text regex.
670
- updatedIcs = removeExceptionFromIcs(updatedIcs, occurrenceDate, existing.all_day);
702
+ updatedIcs = removeExceptionFromIcs(updatedIcs, occurrenceDate, existing.allDay);
671
703
  await service.updateEvent(args.calendar, args.uid, updatedIcs, {
672
704
  url: rawObj.url,
673
705
  etag: rawObj.etag,
@@ -715,7 +747,7 @@ export const CALENDAR_TOOLS = [
715
747
  title: { type: "string", description: "Event title" },
716
748
  start: { type: "string", description: "Start time (ISO 8601)" },
717
749
  end: { type: "string", description: "End time (ISO 8601)" },
718
- all_day: { type: "boolean", description: "All-day event flag (default: false)" },
750
+ allDay: { type: "boolean", description: "All-day event flag (default: false)" },
719
751
  location: { type: "string", description: "Event location" },
720
752
  description: { type: "string", description: "Event description" },
721
753
  attendees: ATTENDEES_PROP("List of attendee email addresses to invite."),
@@ -738,7 +770,7 @@ export const CALENDAR_TOOLS = [
738
770
  description: "Event reminders/alarms",
739
771
  },
740
772
  categories: CATEGORIES_PROP,
741
- recurrence_rule: {
773
+ recurrenceRule: {
742
774
  type: "string",
743
775
  description: "RFC 5545 RRULE string for a recurring event (e.g., 'FREQ=WEEKLY;BYDAY=MO'). FREQ is required.",
744
776
  },
@@ -773,8 +805,8 @@ export const CALENDAR_TOOLS = [
773
805
  }
774
806
  }
775
807
  catch (err) {
776
- if (err instanceof Error && err.message.startsWith("Invalid recurrence_rule:")) {
777
- return calFail("validation_error", err.message);
808
+ if (err instanceof IcsGenerateError) {
809
+ return calFail(ErrorCode.VALIDATION_FAILED, err.message);
778
810
  }
779
811
  throw err;
780
812
  }
@@ -795,15 +827,23 @@ export const CALENDAR_TOOLS = [
795
827
  type: "object",
796
828
  properties: {
797
829
  calendar: CALENDAR_PROP,
798
- ics_content: { type: "string", description: "Raw iCalendar content string" },
830
+ icsContent: { type: "string", description: "Raw iCalendar content string" },
799
831
  },
800
- required: ["calendar", "ics_content"],
832
+ required: ["calendar", "icsContent"],
801
833
  },
802
834
  outputSchema: importResultSchema,
803
835
  handler: (args, service) => run(async () => {
804
- const groups = splitIcsByUid(args.ics_content);
836
+ let groups;
837
+ try {
838
+ groups = splitIcsByUid(args.icsContent);
839
+ }
840
+ catch (err) {
841
+ if (err instanceof IcsParseError)
842
+ return calFail(ErrorCode.INVALID_ICS, err.message);
843
+ throw err;
844
+ }
805
845
  if (groups.length === 0) {
806
- return calFail("validation_error", "No events found in ICS content");
846
+ return calFail(ErrorCode.INVALID_ICS, "No events found in ICS content");
807
847
  }
808
848
  const importedEvents = [];
809
849
  const failed = [];
@@ -846,11 +886,11 @@ export const CALENDAR_TOOLS = [
846
886
  },
847
887
  start: { type: "string", description: "Start of range (ISO 8601)" },
848
888
  end: { type: "string", description: "End of range (ISO 8601)" },
849
- include_all_day_as_busy: {
889
+ includeAllDayAsBusy: {
850
890
  type: "boolean",
851
891
  description: "Treat all-day events as busy when computing from events (default: false). A server-side answer decides this itself.",
852
892
  },
853
- ignore_tentative: {
893
+ ignoreTentative: {
854
894
  type: "boolean",
855
895
  description: "If true, tentative periods are left out (default: false)",
856
896
  },
@@ -859,22 +899,20 @@ export const CALENDAR_TOOLS = [
859
899
  },
860
900
  outputSchema: freeBusySchema,
861
901
  handler: (args, service) => run(async () => {
862
- const startMs = new Date(args.start).getTime();
863
- const endMs = new Date(args.end).getTime();
864
- if (Number.isNaN(startMs) || Number.isNaN(endMs) || startMs >= endMs) {
865
- return calFail("validation_error", "start and end must be ISO 8601 with start before end");
866
- }
902
+ const invalid = checkRange(args.start, args.end);
903
+ if (invalid)
904
+ return invalid;
867
905
  let calendarIds = args.calendars;
868
906
  if (!calendarIds || calendarIds.length === 0) {
869
- calendarIds = (await service.listCalendars()).map((c) => c.calendar_id);
907
+ calendarIds = (await service.listCalendars()).map((c) => c.calendarId);
870
908
  }
871
909
  const { busy, sources } = await service.getFreeBusy(calendarIds, args.start, args.end, {
872
- includeAllDayAsBusy: args.include_all_day_as_busy ?? false,
873
- ignoreTentative: args.ignore_tentative ?? false,
910
+ includeAllDayAsBusy: args.includeAllDayAsBusy ?? false,
911
+ ignoreTentative: args.ignoreTentative ?? false,
874
912
  });
875
913
  return ok({
876
- start: new Date(startMs).toISOString(),
877
- end: new Date(endMs).toISOString(),
914
+ start: new Date(args.start).toISOString(),
915
+ end: new Date(args.end).toISOString(),
878
916
  busy,
879
917
  count: busy.length,
880
918
  sources,
@@ -897,24 +935,24 @@ export const CALENDAR_TOOLS = [
897
935
  start: { type: "string", description: "Start of search range (ISO 8601)" },
898
936
  end: { type: "string", description: "End of search range (ISO 8601)" },
899
937
  duration: { type: "number", description: "Minimum slot duration in minutes" },
900
- preferred_start: {
938
+ preferredStart: {
901
939
  type: "string",
902
940
  description: "Preferred earliest time (HH:MM, e.g., 08:00)",
903
941
  },
904
- preferred_end: {
942
+ preferredEnd: {
905
943
  type: "string",
906
944
  description: "Preferred latest time (HH:MM, e.g., 17:00)",
907
945
  },
908
- exclude_calendars: {
946
+ excludeCalendars: {
909
947
  type: "array",
910
948
  items: { type: "string", description: "Provider-prefixed calendar ID to exclude" },
911
949
  description: "Calendar IDs to exclude from busy time calculation",
912
950
  },
913
- include_all_day_as_busy: {
951
+ includeAllDayAsBusy: {
914
952
  type: "boolean",
915
953
  description: "Treat all-day events as busy (default: false)",
916
954
  },
917
- ignore_tentative: {
955
+ ignoreTentative: {
918
956
  type: "boolean",
919
957
  description: "If true, tentative events don't block slots (default: false)",
920
958
  },
@@ -923,17 +961,20 @@ export const CALENDAR_TOOLS = [
923
961
  },
924
962
  outputSchema: freeSlotsSchema,
925
963
  handler: (args, service) => run(async () => {
964
+ const invalid = checkRange(args.start, args.end);
965
+ if (invalid)
966
+ return invalid;
926
967
  let calendarIds = args.calendars;
927
968
  if (!calendarIds || calendarIds.length === 0) {
928
969
  const allCals = await service.listCalendars();
929
- calendarIds = allCals.map((c) => c.calendar_id);
970
+ calendarIds = allCals.map((c) => c.calendarId);
930
971
  }
931
972
  const slots = await service.findFreeSlots(calendarIds, args.start, args.end, args.duration, {
932
- preferredStart: args.preferred_start,
933
- preferredEnd: args.preferred_end,
934
- ignoreTentative: args.ignore_tentative ?? false,
935
- excludeCalendars: args.exclude_calendars,
936
- includeAllDayAsBusy: args.include_all_day_as_busy ?? false,
973
+ preferredStart: args.preferredStart,
974
+ preferredEnd: args.preferredEnd,
975
+ ignoreTentative: args.ignoreTentative ?? false,
976
+ excludeCalendars: args.excludeCalendars,
977
+ includeAllDayAsBusy: args.includeAllDayAsBusy ?? false,
937
978
  });
938
979
  return ok({ slots, count: slots.length });
939
980
  }),