@miguelarios/cal-mcp 0.21.0 → 1.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,6 +1,6 @@
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";
@@ -14,7 +14,7 @@ const UPDATABLE_FIELDS = [
14
14
  "title",
15
15
  "start",
16
16
  "end",
17
- "all_day",
17
+ "allDay",
18
18
  "location",
19
19
  "description",
20
20
  "attendees",
@@ -39,7 +39,7 @@ function selectedCalendars(args) {
39
39
  }
40
40
  /** Spread into a listing result: the providers it skipped, when there were any. */
41
41
  function unavailableField(unavailable) {
42
- return unavailable.length > 0 ? { unavailable_providers: unavailable } : {};
42
+ return unavailable.length > 0 ? { unavailableProviders: unavailable } : {};
43
43
  }
44
44
  /**
45
45
  * Events in [start, end) on the selected calendars, or on every reachable
@@ -53,7 +53,7 @@ async function fetchEvents(service, selection, start, end, detailLevel) {
53
53
  let unavailable = [];
54
54
  if (calendarIds.length === 0) {
55
55
  const reachable = await service.listReachableCalendars();
56
- calendarIds = reachable.calendars.map((cal) => cal.calendar_id);
56
+ calendarIds = reachable.calendars.map((cal) => cal.calendarId);
57
57
  unavailable = reachable.unavailable;
58
58
  }
59
59
  const results = await Promise.all(calendarIds.map((id) => full ? service.listEventsFull(id, start, end) : service.listEvents(id, start, end)));
@@ -77,22 +77,33 @@ function ok(payload) {
77
77
  function calFail(code, message, retryable = false) {
78
78
  return { ...fail(code, message, retryable), ...debugMeta() };
79
79
  }
80
+ /** A `VALIDATION_FAILED` result unless `start` and `end` parse and `start` comes first. */
81
+ function checkRange(start, end) {
82
+ const startMs = new Date(start).getTime();
83
+ const endMs = new Date(end).getTime();
84
+ if (Number.isNaN(startMs) || Number.isNaN(endMs) || startMs >= endMs) {
85
+ return calFail(ErrorCode.VALIDATION_FAILED, "start and end must be ISO 8601 with start before end");
86
+ }
87
+ return undefined;
88
+ }
80
89
  /**
81
- * Preserves this server's external error vocabulary (`not_found`,
82
- * `validation_error`, `backend_error`) while letting the underlying
83
- * `PimError` message through.
90
+ * A `VALIDATION_FAILED` result unless `occurrenceDate` parses. Checked before
91
+ * anything is written: an unparseable date reaches the ICS helpers as `NaN`,
92
+ * and `addExdateToIcs` would store `EXDATE:NaN-aNNaN…` on the server.
84
93
  */
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
- }
94
+ function checkOccurrenceDate(occurrenceDate) {
95
+ if (Number.isNaN(new Date(occurrenceDate).getTime())) {
96
+ return calFail(ErrorCode.VALIDATION_FAILED, `Invalid occurrenceDate "${occurrenceDate}" — use an ISO 8601 date-time`);
94
97
  }
95
- return { ...toolError(err, () => "backend_error"), ...debugMeta() };
98
+ return undefined;
99
+ }
100
+ /**
101
+ * Reports a thrown error with its pim-core `ErrorCode` (`CALENDAR_NOT_FOUND`,
102
+ * `VALIDATION_FAILED`, `CONNECTION_FAILED`, …), the same vocabulary card-mcp
103
+ * and email-mcp return.
104
+ */
105
+ function mapError(err) {
106
+ return { ...toolError(err), ...debugMeta() };
96
107
  }
97
108
  /**
98
109
  * Widens an attendee from the tool's input shape (`{ email }`) to the shape a
@@ -109,11 +120,11 @@ function toResponseAttendee(attendee) {
109
120
  type: "person",
110
121
  };
111
122
  }
112
- /** Widens an alarm from the tool's input shape by rendering `trigger_human`. */
123
+ /** Widens an alarm from the tool's input shape by rendering `triggerHuman`. */
113
124
  function toResponseAlarm(alarm) {
114
125
  return {
115
126
  ...alarm,
116
- trigger_human: alarm.type === "absolute"
127
+ triggerHuman: alarm.type === "absolute"
117
128
  ? new Date(alarm.trigger).toISOString()
118
129
  : formatTriggerHuman(Number(alarm.trigger)),
119
130
  };
@@ -210,13 +221,16 @@ export const CALENDAR_TOOLS = [
210
221
  calendars: CALENDARS_PROP("query"),
211
222
  start: { type: "string", description: "Start of date range (ISO 8601)" },
212
223
  end: { type: "string", description: "End of date range (ISO 8601)" },
213
- detail_level: DETAIL_LEVEL_PROP,
224
+ detailLevel: DETAIL_LEVEL_PROP,
214
225
  },
215
226
  required: ["start", "end"],
216
227
  },
217
228
  outputSchema: eventListSchema,
218
229
  handler: (args, service) => run(async () => {
219
- const { events, unavailable } = await fetchEvents(service, args, args.start, args.end, args.detail_level ?? "summary");
230
+ const invalid = checkRange(args.start, args.end);
231
+ if (invalid)
232
+ return invalid;
233
+ const { events, unavailable } = await fetchEvents(service, args, args.start, args.end, args.detailLevel ?? "summary");
220
234
  return ok({ events, ...unavailableField(unavailable) });
221
235
  }),
222
236
  },
@@ -233,7 +247,7 @@ export const CALENDAR_TOOLS = [
233
247
  description: "Provider-prefixed calendar ID. If omitted, queries all calendars.",
234
248
  },
235
249
  calendars: CALENDARS_PROP("query"),
236
- detail_level: DETAIL_LEVEL_PROP,
250
+ detailLevel: DETAIL_LEVEL_PROP,
237
251
  },
238
252
  },
239
253
  outputSchema: eventListSchema,
@@ -242,7 +256,7 @@ export const CALENDAR_TOOLS = [
242
256
  const { year, month, day } = getLocalDateParts(new Date(), tz);
243
257
  const todayStart = zonedTimeToUtc(year, month, day, 0, 0, tz).toISOString();
244
258
  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");
259
+ const { events, unavailable } = await fetchEvents(service, args, todayStart, todayEnd, args.detailLevel ?? "summary");
246
260
  return ok({ events, ...unavailableField(unavailable) });
247
261
  }),
248
262
  },
@@ -268,17 +282,20 @@ export const CALENDAR_TOOLS = [
268
282
  type: "string",
269
283
  description: "Range end (ISO 8601). Defaults to 90 days ahead.",
270
284
  },
271
- detail_level: DETAIL_LEVEL_PROP,
285
+ detailLevel: DETAIL_LEVEL_PROP,
272
286
  },
273
287
  required: ["query"],
274
288
  },
275
289
  outputSchema: eventListSchema,
276
290
  handler: (args, service) => run(async () => {
277
291
  const query = args.query.toLowerCase();
278
- const detailLevel = args.detail_level ?? "summary";
292
+ const detailLevel = args.detailLevel ?? "summary";
279
293
  const now = new Date();
280
294
  const start = args.start ?? new Date(now.getTime() - 90 * 86400000).toISOString();
281
295
  const end = args.end ?? new Date(now.getTime() + 90 * 86400000).toISOString();
296
+ const invalid = checkRange(start, end);
297
+ if (invalid)
298
+ return invalid;
282
299
  const { events, unavailable } = await fetchEvents(service, args, start, end, detailLevel);
283
300
  const matched = events.filter((e) => {
284
301
  const title = e.title?.toLowerCase() ?? "";
@@ -292,14 +309,14 @@ export const CALENDAR_TOOLS = [
292
309
  {
293
310
  name: "get_event",
294
311
  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.",
312
+ 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
313
  annotations: READ_ONLY,
297
314
  inputSchema: {
298
315
  type: "object",
299
316
  properties: {
300
317
  calendar: CALENDAR_PROP,
301
318
  uid: { type: "string", description: "Event UID" },
302
- occurrence_date: {
319
+ occurrenceDate: {
303
320
  type: "string",
304
321
  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.",
305
322
  },
@@ -307,7 +324,7 @@ export const CALENDAR_TOOLS = [
307
324
  required: ["calendar", "uid"],
308
325
  },
309
326
  outputSchema: singleEventSchema,
310
- handler: (args, service) => run(async () => ok({ event: await service.getEvent(args.calendar, args.uid, args.occurrence_date) })),
327
+ handler: (args, service) => run(async () => ok({ event: await service.getEvent(args.calendar, args.uid, args.occurrenceDate) })),
311
328
  },
312
329
  {
313
330
  name: "create_event",
@@ -326,13 +343,13 @@ export const CALENDAR_TOOLS = [
326
343
  title: { type: "string", description: "Event title" },
327
344
  start: { type: "string", description: "Start time (ISO 8601)" },
328
345
  end: { type: "string", description: "End time (ISO 8601)" },
329
- all_day: { type: "boolean", description: "All-day event flag (default: false)" },
346
+ allDay: { type: "boolean", description: "All-day event flag (default: false)" },
330
347
  location: { type: "string", description: "Event location" },
331
348
  description: { type: "string", description: "Event description" },
332
349
  attendees: ATTENDEES_PROP("List of attendee email addresses to invite."),
333
350
  alarms: ALARMS_PROP,
334
351
  categories: CATEGORIES_PROP,
335
- recurrence_rule: {
352
+ recurrenceRule: {
336
353
  type: "string",
337
354
  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
355
  },
@@ -356,13 +373,13 @@ export const CALENDAR_TOOLS = [
356
373
  title: args.title,
357
374
  start: args.start,
358
375
  end: args.end,
359
- all_day: args.all_day ?? false,
376
+ allDay: args.allDay ?? false,
360
377
  location: args.location,
361
378
  description: args.description,
362
379
  attendees: args.attendees,
363
380
  alarms: args.alarms,
364
381
  categories: args.categories,
365
- recurrence_rule: args.recurrence_rule,
382
+ recurrenceRule: args.recurrenceRule,
366
383
  organizer,
367
384
  availability: args.availability,
368
385
  timezone: getTimezone(),
@@ -372,8 +389,8 @@ export const CALENDAR_TOOLS = [
372
389
  return ok({ event: await service.createEvent(args.calendar, icsString, uid) });
373
390
  }
374
391
  catch (err) {
375
- if (err instanceof Error && err.message.startsWith("Invalid recurrence_rule:")) {
376
- return calFail("validation_error", err.message);
392
+ if (err instanceof IcsGenerateError) {
393
+ return calFail(ErrorCode.VALIDATION_FAILED, err.message);
377
394
  }
378
395
  throw err;
379
396
  }
@@ -397,13 +414,13 @@ export const CALENDAR_TOOLS = [
397
414
  title: { type: "string", description: "New event title" },
398
415
  start: { type: "string", description: "New start time (ISO 8601)" },
399
416
  end: { type: "string", description: "New end time (ISO 8601)" },
400
- all_day: { type: "boolean", description: "All-day event flag" },
417
+ allDay: { type: "boolean", description: "All-day event flag" },
401
418
  location: { type: "string", description: "New location" },
402
419
  description: { type: "string", description: "New description" },
403
420
  attendees: ATTENDEES_PROP("New attendee list (replaces existing)."),
404
421
  alarms: ALARMS_PROP,
405
422
  categories: CATEGORIES_PROP,
406
- occurrence_date: {
423
+ occurrenceDate: {
407
424
  type: "string",
408
425
  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
426
  },
@@ -425,11 +442,14 @@ export const CALENDAR_TOOLS = [
425
442
  const span = args.span ?? "this";
426
443
  const { event: existing } = await service.getEventWithMeta(args.calendar, args.uid);
427
444
  // 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");
445
+ if (existing.isRecurring && span === "this") {
446
+ if (!args.occurrenceDate) {
447
+ return calFail(ErrorCode.VALIDATION_FAILED, "occurrenceDate is required when span is 'this' on a recurring event");
431
448
  }
432
- const occurrenceDate = args.occurrence_date;
449
+ const occurrenceDate = args.occurrenceDate;
450
+ const invalidDate = checkOccurrenceDate(occurrenceDate);
451
+ if (invalidDate)
452
+ return invalidDate;
433
453
  const rawObj = await service.fetchRawCalendarObject(args.calendar, args.uid);
434
454
  const overrides = {};
435
455
  for (const field of UPDATABLE_FIELDS)
@@ -440,7 +460,7 @@ export const CALENDAR_TOOLS = [
440
460
  if (effectiveAttendees && effectiveAttendees.length > 0 && !existing.organizer) {
441
461
  overrides.organizer = { email: service.getAccountEmail(args.calendar) };
442
462
  }
443
- const exceptionVevent = createExceptionComponent(rawObj.data, "vevent", occurrenceDate, overrides, existing.all_day);
463
+ const exceptionVevent = createExceptionComponent(rawObj.data, "vevent", occurrenceDate, overrides, existing.allDay);
444
464
  const combinedIcs = combineIcsComponents(rawObj.data, exceptionVevent);
445
465
  await service.updateEvent(args.calendar, args.uid, combinedIcs, {
446
466
  url: rawObj.url,
@@ -459,7 +479,7 @@ export const CALENDAR_TOOLS = [
459
479
  start: overrides.start ?? occurrenceDate,
460
480
  end: overrides.end ??
461
481
  new Date(new Date(occurrenceDate).getTime() + occDuration).toISOString(),
462
- all_day: overrides.all_day ?? existing.all_day,
482
+ allDay: overrides.allDay ?? existing.allDay,
463
483
  location: overrides.location ?? existing.location,
464
484
  description: overrides.description ?? existing.description,
465
485
  attendees: overrides.attendees
@@ -470,8 +490,8 @@ export const CALENDAR_TOOLS = [
470
490
  ? { name: overrides.organizer.name ?? null, email: overrides.organizer.email }
471
491
  : existing.organizer,
472
492
  categories: overrides.categories ?? existing.categories,
473
- occurrence_date: occurrenceDate,
474
- recurrence_rule: null,
493
+ occurrenceDate: occurrenceDate,
494
+ recurrenceRule: null,
475
495
  },
476
496
  });
477
497
  }
@@ -490,22 +510,22 @@ export const CALENDAR_TOOLS = [
490
510
  // (new UID) carries the remaining pattern with the changes applied.
491
511
  // A cut at the first occurrence has nothing to keep behind it, so it
492
512
  // 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`);
513
+ if (existing.isRecurring && span === "future") {
514
+ if (!args.occurrenceDate) {
515
+ return calFail(ErrorCode.VALIDATION_FAILED, "occurrenceDate is required when span is 'future' on a recurring event");
500
516
  }
517
+ const occurrenceDate = args.occurrenceDate;
518
+ const invalidDate = checkOccurrenceDate(occurrenceDate);
519
+ if (invalidDate)
520
+ return invalidDate;
501
521
  const newUid = `${randomUUID()}@pim-core`;
502
522
  let split;
503
523
  try {
504
- split = splitRecurrenceIcs(rawObj.data, occurrenceDate, existing.all_day, newUid);
524
+ split = splitRecurrenceIcs(rawObj.data, occurrenceDate, existing.allDay, newUid);
505
525
  }
506
526
  catch (err) {
507
527
  if (err instanceof Error && err.message.startsWith("No occurrence at")) {
508
- return calFail("validation_error", err.message);
528
+ return calFail(ErrorCode.VALIDATION_FAILED, err.message);
509
529
  }
510
530
  throw err;
511
531
  }
@@ -564,18 +584,18 @@ export const CALENDAR_TOOLS = [
564
584
  properties: {
565
585
  calendar: CALENDAR_PROP,
566
586
  uid: { type: "string", description: "Event UID to move" },
567
- target_calendar: {
587
+ targetCalendar: {
568
588
  type: "string",
569
589
  description: "Destination provider-prefixed calendar ID, on the same account",
570
590
  },
571
591
  },
572
- required: ["calendar", "uid", "target_calendar"],
592
+ required: ["calendar", "uid", "targetCalendar"],
573
593
  },
574
594
  outputSchema: singleEventSchema,
575
595
  handler: (args, service) => run(async () => {
576
596
  const { meta } = await service.getEventWithMeta(args.calendar, args.uid);
577
597
  return ok({
578
- event: await service.moveEvent(args.calendar, args.uid, args.target_calendar, meta),
598
+ event: await service.moveEvent(args.calendar, args.uid, args.targetCalendar, meta),
579
599
  });
580
600
  }),
581
601
  },
@@ -594,7 +614,7 @@ export const CALENDAR_TOOLS = [
594
614
  properties: {
595
615
  calendar: CALENDAR_PROP,
596
616
  uid: { type: "string", description: "Event UID to delete" },
597
- occurrence_date: {
617
+ occurrenceDate: {
598
618
  type: "string",
599
619
  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
620
  },
@@ -616,18 +636,18 @@ export const CALENDAR_TOOLS = [
616
636
  if (span === "future") {
617
637
  return run(async () => {
618
638
  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`);
639
+ if (!existing.isRecurring) {
640
+ return calFail(ErrorCode.VALIDATION_FAILED, `Event "${args.uid}" is not recurring — use span 'all' to delete it`);
621
641
  }
622
- if (!args.occurrence_date) {
623
- return calFail("validation_error", "occurrence_date is required when span is 'future' on a recurring event");
624
- }
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`);
642
+ if (!args.occurrenceDate) {
643
+ return calFail(ErrorCode.VALIDATION_FAILED, "occurrenceDate is required when span is 'future' on a recurring event");
628
644
  }
645
+ const occurrenceDate = args.occurrenceDate;
646
+ const invalidDate = checkOccurrenceDate(occurrenceDate);
647
+ if (invalidDate)
648
+ return invalidDate;
629
649
  const rawObj = await service.fetchRawCalendarObject(args.calendar, args.uid);
630
- const truncated = truncateRecurrenceIcs(rawObj.data, occurrenceDate, existing.all_day);
650
+ const truncated = truncateRecurrenceIcs(rawObj.data, occurrenceDate, existing.allDay);
631
651
  // Nothing would remain: the cut is at or before the first occurrence,
632
652
  // so this is a whole-series delete and is treated as one.
633
653
  if (truncated === null) {
@@ -657,17 +677,20 @@ export const CALENDAR_TOOLS = [
657
677
  if (span === "this") {
658
678
  return run(async () => {
659
679
  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");
680
+ if (existing.isRecurring) {
681
+ if (!args.occurrenceDate) {
682
+ return calFail(ErrorCode.VALIDATION_FAILED, "occurrenceDate is required when span is 'this' on a recurring event");
663
683
  }
664
- const occurrenceDate = args.occurrence_date;
684
+ const occurrenceDate = args.occurrenceDate;
685
+ const invalidDate = checkOccurrenceDate(occurrenceDate);
686
+ if (invalidDate)
687
+ return invalidDate;
665
688
  const rawObj = await service.fetchRawCalendarObject(args.calendar, args.uid);
666
- let updatedIcs = addExdateToIcs(rawObj.data, occurrenceDate, existing.all_day);
689
+ let updatedIcs = addExdateToIcs(rawObj.data, occurrenceDate, existing.allDay);
667
690
  // Remove any existing exception VEVENT/VTODO for this occurrence,
668
691
  // matching by resolved instant (handles both UTC and TZID-form
669
692
  // RECURRENCE-ID) rather than a literal-text regex.
670
- updatedIcs = removeExceptionFromIcs(updatedIcs, occurrenceDate, existing.all_day);
693
+ updatedIcs = removeExceptionFromIcs(updatedIcs, occurrenceDate, existing.allDay);
671
694
  await service.updateEvent(args.calendar, args.uid, updatedIcs, {
672
695
  url: rawObj.url,
673
696
  etag: rawObj.etag,
@@ -715,7 +738,7 @@ export const CALENDAR_TOOLS = [
715
738
  title: { type: "string", description: "Event title" },
716
739
  start: { type: "string", description: "Start time (ISO 8601)" },
717
740
  end: { type: "string", description: "End time (ISO 8601)" },
718
- all_day: { type: "boolean", description: "All-day event flag (default: false)" },
741
+ allDay: { type: "boolean", description: "All-day event flag (default: false)" },
719
742
  location: { type: "string", description: "Event location" },
720
743
  description: { type: "string", description: "Event description" },
721
744
  attendees: ATTENDEES_PROP("List of attendee email addresses to invite."),
@@ -738,7 +761,7 @@ export const CALENDAR_TOOLS = [
738
761
  description: "Event reminders/alarms",
739
762
  },
740
763
  categories: CATEGORIES_PROP,
741
- recurrence_rule: {
764
+ recurrenceRule: {
742
765
  type: "string",
743
766
  description: "RFC 5545 RRULE string for a recurring event (e.g., 'FREQ=WEEKLY;BYDAY=MO'). FREQ is required.",
744
767
  },
@@ -773,8 +796,8 @@ export const CALENDAR_TOOLS = [
773
796
  }
774
797
  }
775
798
  catch (err) {
776
- if (err instanceof Error && err.message.startsWith("Invalid recurrence_rule:")) {
777
- return calFail("validation_error", err.message);
799
+ if (err instanceof IcsGenerateError) {
800
+ return calFail(ErrorCode.VALIDATION_FAILED, err.message);
778
801
  }
779
802
  throw err;
780
803
  }
@@ -795,15 +818,23 @@ export const CALENDAR_TOOLS = [
795
818
  type: "object",
796
819
  properties: {
797
820
  calendar: CALENDAR_PROP,
798
- ics_content: { type: "string", description: "Raw iCalendar content string" },
821
+ icsContent: { type: "string", description: "Raw iCalendar content string" },
799
822
  },
800
- required: ["calendar", "ics_content"],
823
+ required: ["calendar", "icsContent"],
801
824
  },
802
825
  outputSchema: importResultSchema,
803
826
  handler: (args, service) => run(async () => {
804
- const groups = splitIcsByUid(args.ics_content);
827
+ let groups;
828
+ try {
829
+ groups = splitIcsByUid(args.icsContent);
830
+ }
831
+ catch (err) {
832
+ if (err instanceof IcsParseError)
833
+ return calFail(ErrorCode.INVALID_ICS, err.message);
834
+ throw err;
835
+ }
805
836
  if (groups.length === 0) {
806
- return calFail("validation_error", "No events found in ICS content");
837
+ return calFail(ErrorCode.INVALID_ICS, "No events found in ICS content");
807
838
  }
808
839
  const importedEvents = [];
809
840
  const failed = [];
@@ -846,11 +877,11 @@ export const CALENDAR_TOOLS = [
846
877
  },
847
878
  start: { type: "string", description: "Start of range (ISO 8601)" },
848
879
  end: { type: "string", description: "End of range (ISO 8601)" },
849
- include_all_day_as_busy: {
880
+ includeAllDayAsBusy: {
850
881
  type: "boolean",
851
882
  description: "Treat all-day events as busy when computing from events (default: false). A server-side answer decides this itself.",
852
883
  },
853
- ignore_tentative: {
884
+ ignoreTentative: {
854
885
  type: "boolean",
855
886
  description: "If true, tentative periods are left out (default: false)",
856
887
  },
@@ -859,22 +890,20 @@ export const CALENDAR_TOOLS = [
859
890
  },
860
891
  outputSchema: freeBusySchema,
861
892
  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
- }
893
+ const invalid = checkRange(args.start, args.end);
894
+ if (invalid)
895
+ return invalid;
867
896
  let calendarIds = args.calendars;
868
897
  if (!calendarIds || calendarIds.length === 0) {
869
- calendarIds = (await service.listCalendars()).map((c) => c.calendar_id);
898
+ calendarIds = (await service.listCalendars()).map((c) => c.calendarId);
870
899
  }
871
900
  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,
901
+ includeAllDayAsBusy: args.includeAllDayAsBusy ?? false,
902
+ ignoreTentative: args.ignoreTentative ?? false,
874
903
  });
875
904
  return ok({
876
- start: new Date(startMs).toISOString(),
877
- end: new Date(endMs).toISOString(),
905
+ start: new Date(args.start).toISOString(),
906
+ end: new Date(args.end).toISOString(),
878
907
  busy,
879
908
  count: busy.length,
880
909
  sources,
@@ -897,24 +926,24 @@ export const CALENDAR_TOOLS = [
897
926
  start: { type: "string", description: "Start of search range (ISO 8601)" },
898
927
  end: { type: "string", description: "End of search range (ISO 8601)" },
899
928
  duration: { type: "number", description: "Minimum slot duration in minutes" },
900
- preferred_start: {
929
+ preferredStart: {
901
930
  type: "string",
902
931
  description: "Preferred earliest time (HH:MM, e.g., 08:00)",
903
932
  },
904
- preferred_end: {
933
+ preferredEnd: {
905
934
  type: "string",
906
935
  description: "Preferred latest time (HH:MM, e.g., 17:00)",
907
936
  },
908
- exclude_calendars: {
937
+ excludeCalendars: {
909
938
  type: "array",
910
939
  items: { type: "string", description: "Provider-prefixed calendar ID to exclude" },
911
940
  description: "Calendar IDs to exclude from busy time calculation",
912
941
  },
913
- include_all_day_as_busy: {
942
+ includeAllDayAsBusy: {
914
943
  type: "boolean",
915
944
  description: "Treat all-day events as busy (default: false)",
916
945
  },
917
- ignore_tentative: {
946
+ ignoreTentative: {
918
947
  type: "boolean",
919
948
  description: "If true, tentative events don't block slots (default: false)",
920
949
  },
@@ -923,17 +952,20 @@ export const CALENDAR_TOOLS = [
923
952
  },
924
953
  outputSchema: freeSlotsSchema,
925
954
  handler: (args, service) => run(async () => {
955
+ const invalid = checkRange(args.start, args.end);
956
+ if (invalid)
957
+ return invalid;
926
958
  let calendarIds = args.calendars;
927
959
  if (!calendarIds || calendarIds.length === 0) {
928
960
  const allCals = await service.listCalendars();
929
- calendarIds = allCals.map((c) => c.calendar_id);
961
+ calendarIds = allCals.map((c) => c.calendarId);
930
962
  }
931
963
  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,
964
+ preferredStart: args.preferredStart,
965
+ preferredEnd: args.preferredEnd,
966
+ ignoreTentative: args.ignoreTentative ?? false,
967
+ excludeCalendars: args.excludeCalendars,
968
+ includeAllDayAsBusy: args.includeAllDayAsBusy ?? false,
937
969
  });
938
970
  return ok({ slots, count: slots.length });
939
971
  }),