@miguelarios/cal-mcp 0.10.0 → 0.12.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,8 @@
1
- import { getTimezone, toPimError } from "@miguelarios/pim-core";
2
- import { addExdateToIcs, combineIcsComponents, createExceptionComponent, generateEventIcs, parseIcsEvents, } from "@miguelarios/pim-core/ics";
1
+ import { getLocalDateParts, getTimezone, zonedTimeToUtc } from "@miguelarios/pim-core";
2
+ import { addExdateToIcs, combineIcsComponents, createExceptionComponent, formatTriggerHuman, generateEventIcs, removeExceptionFromIcs, splitIcsByUid, updateMasterEventIcs, } from "@miguelarios/pim-core/ics";
3
+ import { confirmDestructive, fail, structured, toolError, } from "@miguelarios/pim-core/mcp";
3
4
  import { drainDebugTimings, } from "../services/CalDavService.js";
5
+ import { batchCreateSchema, calendarListSchema, deleteResultSchema, eventListSchema, freeSlotsSchema, importResultSchema, singleEventSchema, } from "./calendarSchemas.js";
4
6
  async function fetchEvents(service, calendar, start, end, detailLevel) {
5
7
  const full = detailLevel === "full";
6
8
  if (calendar) {
@@ -14,15 +16,135 @@ async function fetchEvents(service, calendar, start, end, detailLevel) {
14
16
  : service.listEvents(cal.calendar_id, start, end)));
15
17
  return results.flat();
16
18
  }
19
+ /**
20
+ * Timing diagnostics ride in the result's `_meta` rather than inside the
21
+ * payload, so they never have to be modelled in `outputSchema`.
22
+ */
23
+ function debugMeta() {
24
+ if (process.env.CAL_MCP_DEBUG !== "1")
25
+ return undefined;
26
+ const timings = drainDebugTimings();
27
+ if (timings.length === 0)
28
+ return undefined;
29
+ return { _meta: { "com.miguelarios.cal-mcp/debug": { timings } } };
30
+ }
31
+ function ok(payload) {
32
+ return { ...structured(payload), ...debugMeta() };
33
+ }
34
+ function calFail(code, message, retryable = false) {
35
+ return { ...fail(code, message, retryable), ...debugMeta() };
36
+ }
37
+ /**
38
+ * Preserves this server's external error vocabulary (`not_found`,
39
+ * `validation_error`, `backend_error`) while letting the underlying
40
+ * `PimError` message through.
41
+ */
42
+ function mapError(err) {
43
+ if (err && typeof err === "object" && "code" in err) {
44
+ const code = err.code;
45
+ if (code === "CALENDAR_NOT_FOUND" || code === "EVENT_NOT_FOUND") {
46
+ return { ...toolError(err, () => "not_found"), ...debugMeta() };
47
+ }
48
+ }
49
+ return { ...toolError(err, () => "backend_error"), ...debugMeta() };
50
+ }
51
+ /**
52
+ * Widens an attendee from the tool's input shape (`{ email }`) to the shape a
53
+ * read returns. `generateEventIcs` writes a bare `ATTENDEE:mailto:…` with no
54
+ * CN/PARTSTAT/ROLE/CUTYPE, so re-reading it yields nulls and the RFC 5545
55
+ * §3.2.3 default CUTYPE of INDIVIDUAL — which the parser maps to "person".
56
+ */
57
+ function toResponseAttendee(attendee) {
58
+ return {
59
+ email: attendee.email,
60
+ name: null,
61
+ status: null,
62
+ role: null,
63
+ type: "person",
64
+ };
65
+ }
66
+ /** Widens an alarm from the tool's input shape by rendering `trigger_human`. */
67
+ function toResponseAlarm(alarm) {
68
+ return {
69
+ ...alarm,
70
+ trigger_human: alarm.type === "absolute"
71
+ ? new Date(alarm.trigger).toISOString()
72
+ : formatTriggerHuman(Number(alarm.trigger)),
73
+ };
74
+ }
75
+ /** Runs a handler body, converting anything thrown into this server's error shape. */
76
+ async function run(body) {
77
+ try {
78
+ return await body();
79
+ }
80
+ catch (err) {
81
+ return mapError(err);
82
+ }
83
+ }
84
+ const CALENDAR_PROP = {
85
+ type: "string",
86
+ description: "Provider-prefixed calendar ID",
87
+ };
88
+ const DETAIL_LEVEL_PROP = {
89
+ type: "string",
90
+ enum: ["summary", "full"],
91
+ description: "Response verbosity (default: summary)",
92
+ };
93
+ const ATTENDEES_PROP = (description) => ({
94
+ type: "array",
95
+ items: {
96
+ type: "object",
97
+ properties: {
98
+ email: {
99
+ type: "string",
100
+ description: "Attendee email address. Display name is resolved server-side from the invitee's address book.",
101
+ },
102
+ },
103
+ required: ["email"],
104
+ },
105
+ description,
106
+ });
107
+ const ALARMS_PROP = {
108
+ type: "array",
109
+ items: {
110
+ type: "object",
111
+ properties: {
112
+ type: { type: "string", enum: ["relative", "absolute"], description: "Alarm type" },
113
+ trigger: {
114
+ type: ["string", "number"],
115
+ description: "Seconds offset (negative=before event) for relative, or ISO 8601 datetime for absolute",
116
+ },
117
+ },
118
+ required: ["type", "trigger"],
119
+ },
120
+ description: "Event reminders/alarms",
121
+ };
122
+ const CATEGORIES_PROP = {
123
+ type: "array",
124
+ items: { type: "string", description: "Category / tag name" },
125
+ description: "Event categories/tags",
126
+ };
127
+ const READ_ONLY = {
128
+ readOnlyHint: true,
129
+ destructiveHint: false,
130
+ idempotentHint: true,
131
+ openWorldHint: true,
132
+ };
17
133
  export const CALENDAR_TOOLS = [
18
134
  {
19
135
  name: "list_calendars",
136
+ title: "List Calendars",
20
137
  description: "List all calendars across all configured CalDAV providers. Returns provider-prefixed IDs (e.g., mailbox/work).",
138
+ annotations: READ_ONLY,
21
139
  inputSchema: { type: "object", properties: {} },
140
+ outputSchema: calendarListSchema,
141
+ handler: (_args, service) => run(async () => ok({ calendars: await service.listCalendars() })),
22
142
  },
23
143
  {
24
144
  name: "list_events",
145
+ title: "List Events",
25
146
  description: "Query events in a date range. Recurring events are expanded into individual instances.",
147
+ annotations: READ_ONLY,
26
148
  inputSchema: {
27
149
  type: "object",
28
150
  properties: {
@@ -30,26 +152,22 @@ export const CALENDAR_TOOLS = [
30
152
  type: "string",
31
153
  description: "Provider-prefixed calendar ID (e.g., mailbox/Work). If omitted, queries all calendars.",
32
154
  },
33
- start: {
34
- type: "string",
35
- description: "Start of date range (ISO 8601)",
36
- },
37
- end: {
38
- type: "string",
39
- description: "End of date range (ISO 8601)",
40
- },
41
- detail_level: {
42
- type: "string",
43
- enum: ["summary", "full"],
44
- description: "Response verbosity (default: summary)",
45
- },
155
+ start: { type: "string", description: "Start of date range (ISO 8601)" },
156
+ end: { type: "string", description: "End of date range (ISO 8601)" },
157
+ detail_level: DETAIL_LEVEL_PROP,
46
158
  },
47
159
  required: ["start", "end"],
48
160
  },
161
+ outputSchema: eventListSchema,
162
+ handler: (args, service) => run(async () => ok({
163
+ events: await fetchEvents(service, args.calendar, args.start, args.end, args.detail_level ?? "summary"),
164
+ })),
49
165
  },
50
166
  {
51
167
  name: "get_today_events",
168
+ title: "Get Today's Events",
52
169
  description: "Get all events for today. Convenience wrapper over list_events.",
170
+ annotations: READ_ONLY,
53
171
  inputSchema: {
54
172
  type: "object",
55
173
  properties: {
@@ -57,24 +175,29 @@ export const CALENDAR_TOOLS = [
57
175
  type: "string",
58
176
  description: "Provider-prefixed calendar ID. If omitted, queries all calendars.",
59
177
  },
60
- detail_level: {
61
- type: "string",
62
- enum: ["summary", "full"],
63
- description: "Response verbosity (default: summary)",
64
- },
178
+ detail_level: DETAIL_LEVEL_PROP,
65
179
  },
66
180
  },
181
+ outputSchema: eventListSchema,
182
+ handler: (args, service) => run(async () => {
183
+ const tz = getTimezone();
184
+ const { year, month, day } = getLocalDateParts(new Date(), tz);
185
+ const todayStart = zonedTimeToUtc(year, month, day, 0, 0, tz).toISOString();
186
+ const todayEnd = zonedTimeToUtc(year, month, day + 1, 0, 0, tz).toISOString();
187
+ return ok({
188
+ events: await fetchEvents(service, args.calendar, todayStart, todayEnd, args.detail_level ?? "summary"),
189
+ });
190
+ }),
67
191
  },
68
192
  {
69
193
  name: "search_events",
194
+ title: "Search Events",
70
195
  description: "Keyword search across event title, description, and location.",
196
+ annotations: READ_ONLY,
71
197
  inputSchema: {
72
198
  type: "object",
73
199
  properties: {
74
- query: {
75
- type: "string",
76
- description: "Search term",
77
- },
200
+ query: { type: "string", description: "Search term" },
78
201
  calendar: {
79
202
  type: "string",
80
203
  description: "Provider-prefixed calendar ID. If omitted, searches all calendars.",
@@ -87,89 +210,66 @@ export const CALENDAR_TOOLS = [
87
210
  type: "string",
88
211
  description: "Range end (ISO 8601). Defaults to 90 days ahead.",
89
212
  },
90
- detail_level: {
91
- type: "string",
92
- enum: ["summary", "full"],
93
- description: "Response verbosity (default: summary)",
94
- },
213
+ detail_level: DETAIL_LEVEL_PROP,
95
214
  },
96
215
  required: ["query"],
97
216
  },
217
+ outputSchema: eventListSchema,
218
+ handler: (args, service) => run(async () => {
219
+ const query = args.query.toLowerCase();
220
+ const detailLevel = args.detail_level ?? "summary";
221
+ const now = new Date();
222
+ const start = args.start ?? new Date(now.getTime() - 90 * 86400000).toISOString();
223
+ const end = args.end ?? new Date(now.getTime() + 90 * 86400000).toISOString();
224
+ const events = await fetchEvents(service, args.calendar, start, end, detailLevel);
225
+ const matched = events.filter((e) => {
226
+ const title = e.title?.toLowerCase() ?? "";
227
+ const location = e.location?.toLowerCase() ?? "";
228
+ const description = detailLevel === "full" ? (e.description?.toLowerCase() ?? "") : "";
229
+ return title.includes(query) || location.includes(query) || description.includes(query);
230
+ });
231
+ return ok({ events: matched });
232
+ }),
98
233
  },
99
234
  {
100
235
  name: "get_event",
236
+ title: "Get Event",
101
237
  description: "Get full details of a single event by calendar and UID.",
238
+ annotations: READ_ONLY,
102
239
  inputSchema: {
103
240
  type: "object",
104
241
  properties: {
105
- calendar: {
106
- type: "string",
107
- description: "Provider-prefixed calendar ID",
108
- },
242
+ calendar: CALENDAR_PROP,
109
243
  uid: { type: "string", description: "Event UID" },
110
244
  },
111
245
  required: ["calendar", "uid"],
112
246
  },
247
+ outputSchema: singleEventSchema,
248
+ handler: (args, service) => run(async () => ok({ event: await service.getEvent(args.calendar, args.uid) })),
113
249
  },
114
250
  {
115
251
  name: "create_event",
252
+ title: "Create Event",
116
253
  description: "Create a new calendar event.",
254
+ annotations: {
255
+ readOnlyHint: false,
256
+ destructiveHint: false,
257
+ idempotentHint: false,
258
+ openWorldHint: true,
259
+ },
117
260
  inputSchema: {
118
261
  type: "object",
119
262
  properties: {
120
- calendar: {
121
- type: "string",
122
- description: "Provider-prefixed calendar ID",
123
- },
263
+ calendar: CALENDAR_PROP,
124
264
  title: { type: "string", description: "Event title" },
125
- start: {
126
- type: "string",
127
- description: "Start time (ISO 8601)",
128
- },
265
+ start: { type: "string", description: "Start time (ISO 8601)" },
129
266
  end: { type: "string", description: "End time (ISO 8601)" },
130
- all_day: {
131
- type: "boolean",
132
- description: "All-day event flag (default: false)",
133
- },
267
+ all_day: { type: "boolean", description: "All-day event flag (default: false)" },
134
268
  location: { type: "string", description: "Event location" },
135
- description: {
136
- type: "string",
137
- description: "Event description",
138
- },
139
- attendees: {
140
- type: "array",
141
- items: {
142
- type: "object",
143
- properties: {
144
- email: {
145
- type: "string",
146
- description: "Attendee email address. Display name is resolved server-side from the invitee's address book.",
147
- },
148
- },
149
- required: ["email"],
150
- },
151
- description: "List of attendee email addresses to invite.",
152
- },
153
- alarms: {
154
- type: "array",
155
- items: {
156
- type: "object",
157
- properties: {
158
- type: { type: "string", enum: ["relative", "absolute"], description: "Alarm type" },
159
- trigger: {
160
- type: ["string", "number"],
161
- description: "Seconds offset (negative=before event) for relative, or ISO 8601 datetime for absolute",
162
- },
163
- },
164
- required: ["type", "trigger"],
165
- },
166
- description: "Event reminders/alarms",
167
- },
168
- categories: {
169
- type: "array",
170
- items: { type: "string", description: "Category / tag name" },
171
- description: "Event categories/tags",
172
- },
269
+ description: { type: "string", description: "Event description" },
270
+ attendees: ATTENDEES_PROP("List of attendee email addresses to invite."),
271
+ alarms: ALARMS_PROP,
272
+ categories: CATEGORIES_PROP,
173
273
  recurrence_rule: {
174
274
  type: "string",
175
275
  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.",
@@ -182,73 +282,65 @@ export const CALENDAR_TOOLS = [
182
282
  },
183
283
  required: ["calendar", "title", "start", "end"],
184
284
  },
285
+ outputSchema: singleEventSchema,
286
+ handler: (args, service) => run(async () => {
287
+ try {
288
+ // Populate ORGANIZER whenever attendees are present — CalDAV servers
289
+ // (SOGo/mailbox.org) reject ATTENDEE-without-ORGANIZER PUTs with 412.
290
+ const organizer = args.attendees && args.attendees.length > 0
291
+ ? { email: service.getAccountEmail(args.calendar) }
292
+ : undefined;
293
+ const icsString = generateEventIcs({
294
+ title: args.title,
295
+ start: args.start,
296
+ end: args.end,
297
+ all_day: args.all_day ?? false,
298
+ location: args.location,
299
+ description: args.description,
300
+ attendees: args.attendees,
301
+ alarms: args.alarms,
302
+ categories: args.categories,
303
+ recurrence_rule: args.recurrence_rule,
304
+ organizer,
305
+ availability: args.availability,
306
+ timezone: getTimezone(),
307
+ });
308
+ const uidMatch = icsString.match(/UID:(.+)/);
309
+ const uid = uidMatch ? uidMatch[1].trim() : crypto.randomUUID();
310
+ return ok({ event: await service.createEvent(args.calendar, icsString, uid) });
311
+ }
312
+ catch (err) {
313
+ if (err instanceof Error && err.message.startsWith("Invalid recurrence_rule:")) {
314
+ return calFail("validation_error", err.message);
315
+ }
316
+ throw err;
317
+ }
318
+ }),
185
319
  },
186
320
  {
187
321
  name: "update_event",
322
+ title: "Update Event",
188
323
  description: "Update an existing event. Only provided fields are changed.",
324
+ annotations: {
325
+ readOnlyHint: false,
326
+ destructiveHint: false,
327
+ idempotentHint: true,
328
+ openWorldHint: true,
329
+ },
189
330
  inputSchema: {
190
331
  type: "object",
191
332
  properties: {
192
- calendar: {
193
- type: "string",
194
- description: "Provider-prefixed calendar ID",
195
- },
196
- uid: {
197
- type: "string",
198
- description: "Event UID to update",
199
- },
333
+ calendar: CALENDAR_PROP,
334
+ uid: { type: "string", description: "Event UID to update" },
200
335
  title: { type: "string", description: "New event title" },
201
- start: {
202
- type: "string",
203
- description: "New start time (ISO 8601)",
204
- },
205
- end: {
206
- type: "string",
207
- description: "New end time (ISO 8601)",
208
- },
209
- all_day: {
210
- type: "boolean",
211
- description: "All-day event flag",
212
- },
336
+ start: { type: "string", description: "New start time (ISO 8601)" },
337
+ end: { type: "string", description: "New end time (ISO 8601)" },
338
+ all_day: { type: "boolean", description: "All-day event flag" },
213
339
  location: { type: "string", description: "New location" },
214
- description: {
215
- type: "string",
216
- description: "New description",
217
- },
218
- attendees: {
219
- type: "array",
220
- items: {
221
- type: "object",
222
- properties: {
223
- email: {
224
- type: "string",
225
- description: "Attendee email address. Display name is resolved server-side from the invitee's address book.",
226
- },
227
- },
228
- required: ["email"],
229
- },
230
- description: "New attendee list (replaces existing).",
231
- },
232
- alarms: {
233
- type: "array",
234
- items: {
235
- type: "object",
236
- properties: {
237
- type: { type: "string", enum: ["relative", "absolute"], description: "Alarm type" },
238
- trigger: {
239
- type: ["string", "number"],
240
- description: "Seconds offset (negative=before event) for relative, or ISO 8601 datetime for absolute",
241
- },
242
- },
243
- required: ["type", "trigger"],
244
- },
245
- description: "Event reminders/alarms",
246
- },
247
- categories: {
248
- type: "array",
249
- items: { type: "string", description: "Category / tag name" },
250
- description: "Event categories/tags",
251
- },
340
+ description: { type: "string", description: "New description" },
341
+ attendees: ATTENDEES_PROP("New attendee list (replaces existing)."),
342
+ alarms: ALARMS_PROP,
343
+ categories: CATEGORIES_PROP,
252
344
  occurrence_date: {
253
345
  type: "string",
254
346
  description: "ISO 8601 date of the specific occurrence to modify. Required when span is 'this' on a recurring event. Get this value from list_events results.",
@@ -266,21 +358,158 @@ export const CALENDAR_TOOLS = [
266
358
  },
267
359
  required: ["calendar", "uid"],
268
360
  },
361
+ outputSchema: singleEventSchema,
362
+ handler: (args, service) => run(async () => {
363
+ const span = args.span ?? "this";
364
+ const { event: existing } = await service.getEventWithMeta(args.calendar, args.uid);
365
+ // span="this" on a recurring event: create exception VEVENT
366
+ if (existing.is_recurring && span === "this") {
367
+ if (!args.occurrence_date) {
368
+ return calFail("validation_error", "occurrence_date is required when span is 'this' on a recurring event");
369
+ }
370
+ const occurrenceDate = args.occurrence_date;
371
+ const rawObj = await service.fetchRawCalendarObject(args.calendar, args.uid);
372
+ const overrides = {};
373
+ for (const field of [
374
+ "title",
375
+ "start",
376
+ "end",
377
+ "all_day",
378
+ "location",
379
+ "description",
380
+ "attendees",
381
+ "alarms",
382
+ "categories",
383
+ "availability",
384
+ ]) {
385
+ if (args[field] !== undefined) {
386
+ // field-by-field copy across a union of value types
387
+ overrides[field] = args[field];
388
+ }
389
+ }
390
+ // If the effective event will have attendees but no organizer yet,
391
+ // inject one so the CalDAV PUT satisfies server scheduling preconditions.
392
+ const effectiveAttendees = overrides.attendees ?? existing.attendees;
393
+ if (effectiveAttendees && effectiveAttendees.length > 0 && !existing.organizer) {
394
+ overrides.organizer = { email: service.getAccountEmail(args.calendar) };
395
+ }
396
+ const exceptionVevent = createExceptionComponent(rawObj.data, "vevent", occurrenceDate, overrides, existing.all_day);
397
+ const combinedIcs = combineIcsComponents(rawObj.data, exceptionVevent);
398
+ await service.updateEvent(args.calendar, args.uid, combinedIcs, {
399
+ url: rawObj.url,
400
+ etag: rawObj.etag,
401
+ });
402
+ // Build response from overrides + existing. Unlike every other write
403
+ // path, this one does not re-read the event afterwards, so anything
404
+ // taken from `overrides` is in the tool's *input* shape and has to be
405
+ // widened to the shape a read would return — otherwise the result
406
+ // fails validation against this tool's own outputSchema.
407
+ const occDuration = new Date(existing.end).getTime() - new Date(existing.start).getTime();
408
+ return ok({
409
+ event: {
410
+ ...existing,
411
+ title: overrides.title ?? existing.title,
412
+ start: overrides.start ?? occurrenceDate,
413
+ end: overrides.end ??
414
+ new Date(new Date(occurrenceDate).getTime() + occDuration).toISOString(),
415
+ all_day: overrides.all_day ?? existing.all_day,
416
+ location: overrides.location ?? existing.location,
417
+ description: overrides.description ?? existing.description,
418
+ attendees: overrides.attendees
419
+ ? overrides.attendees.map(toResponseAttendee)
420
+ : existing.attendees,
421
+ alarms: overrides.alarms ? overrides.alarms.map(toResponseAlarm) : existing.alarms,
422
+ organizer: overrides.organizer
423
+ ? { name: overrides.organizer.name ?? null, email: overrides.organizer.email }
424
+ : existing.organizer,
425
+ categories: overrides.categories ?? existing.categories,
426
+ occurrence_date: occurrenceDate,
427
+ recurrence_rule: null,
428
+ },
429
+ });
430
+ }
431
+ // Non-exception path (span "all", or non-recurring event): mutate the
432
+ // existing object in place — preserves RRULE/EXDATE/RDATE, exception
433
+ // overrides, attendee participation state, STATUS, and unknown props.
434
+ const rawObj = await service.fetchRawCalendarObject(args.calendar, args.uid);
435
+ const updates = { timezone: getTimezone() };
436
+ for (const field of [
437
+ "title",
438
+ "start",
439
+ "end",
440
+ "all_day",
441
+ "location",
442
+ "description",
443
+ "attendees",
444
+ "alarms",
445
+ "categories",
446
+ "availability",
447
+ ]) {
448
+ if (args[field] !== undefined) {
449
+ // field-by-field copy across a union of value types
450
+ updates[field] = args[field];
451
+ }
452
+ }
453
+ // Inject ORGANIZER only when the event will have attendees but has none
454
+ // (CalDAV scheduling servers reject ATTENDEE-without-ORGANIZER, RFC 6638).
455
+ const effectiveAttendees = updates.attendees ?? existing.attendees;
456
+ if (effectiveAttendees && effectiveAttendees.length > 0 && !existing.organizer) {
457
+ updates.organizer = { email: service.getAccountEmail(args.calendar) };
458
+ }
459
+ const updatedIcs = updateMasterEventIcs(rawObj.data, updates);
460
+ return ok({
461
+ event: await service.updateEvent(args.calendar, args.uid, updatedIcs, {
462
+ url: rawObj.url,
463
+ etag: rawObj.etag,
464
+ }),
465
+ });
466
+ }),
269
467
  },
270
468
  {
271
- name: "delete_event",
272
- description: "Delete a calendar event by UID.",
469
+ name: "move_event",
470
+ title: "Move Event",
471
+ description: "Move an event to another calendar, equivalent to reassigning its calendar in a CalDAV client. Both calendars must belong to the same account.",
472
+ annotations: {
473
+ readOnlyHint: false,
474
+ destructiveHint: false,
475
+ idempotentHint: true,
476
+ openWorldHint: true,
477
+ },
273
478
  inputSchema: {
274
479
  type: "object",
275
480
  properties: {
276
- calendar: {
481
+ calendar: CALENDAR_PROP,
482
+ uid: { type: "string", description: "Event UID to move" },
483
+ target_calendar: {
277
484
  type: "string",
278
- description: "Provider-prefixed calendar ID",
279
- },
280
- uid: {
281
- type: "string",
282
- description: "Event UID to delete",
485
+ description: "Destination provider-prefixed calendar ID, on the same account",
283
486
  },
487
+ },
488
+ required: ["calendar", "uid", "target_calendar"],
489
+ },
490
+ outputSchema: singleEventSchema,
491
+ handler: (args, service) => run(async () => {
492
+ const { meta } = await service.getEventWithMeta(args.calendar, args.uid);
493
+ return ok({
494
+ event: await service.moveEvent(args.calendar, args.uid, args.target_calendar, meta),
495
+ });
496
+ }),
497
+ },
498
+ {
499
+ name: "delete_event",
500
+ title: "Delete Event",
501
+ description: "Delete a calendar event by UID. Asks the user to confirm first, unless it is excluding a single occurrence of a recurring event (span 'this'), which is recoverable.",
502
+ annotations: {
503
+ readOnlyHint: false,
504
+ destructiveHint: true,
505
+ idempotentHint: true,
506
+ openWorldHint: true,
507
+ },
508
+ inputSchema: {
509
+ type: "object",
510
+ properties: {
511
+ calendar: CALENDAR_PROP,
512
+ uid: { type: "string", description: "Event UID to delete" },
284
513
  occurrence_date: {
285
514
  type: "string",
286
515
  description: "ISO 8601 date of the specific occurrence to delete. Required when span is 'this' on a recurring event. Get this value from list_events results.",
@@ -293,51 +522,81 @@ export const CALENDAR_TOOLS = [
293
522
  },
294
523
  required: ["calendar", "uid"],
295
524
  },
525
+ outputSchema: deleteResultSchema,
526
+ handler: async (args, service, ctx) => {
527
+ const span = args.span ?? "all";
528
+ // Excluding one occurrence of a recurring event is recoverable — the
529
+ // occurrence can be re-added. EVERY other path removes the calendar
530
+ // object outright, including `span: "this"` on a NON-recurring event,
531
+ // which is the same irreversible delete as `span: "all"`. So recurrence
532
+ // has to be resolved before deciding whether to gate; keying the gate off
533
+ // `span` alone would let an agent delete a one-off event unconfirmed
534
+ // simply by passing the narrower-sounding span.
535
+ if (span === "this") {
536
+ return run(async () => {
537
+ const { event: existing, meta: eventMeta } = await service.getEventWithMeta(args.calendar, args.uid);
538
+ if (existing.is_recurring) {
539
+ if (!args.occurrence_date) {
540
+ return calFail("validation_error", "occurrence_date is required when span is 'this' on a recurring event");
541
+ }
542
+ const occurrenceDate = args.occurrence_date;
543
+ const rawObj = await service.fetchRawCalendarObject(args.calendar, args.uid);
544
+ let updatedIcs = addExdateToIcs(rawObj.data, occurrenceDate, existing.all_day);
545
+ // Remove any existing exception VEVENT/VTODO for this occurrence,
546
+ // matching by resolved instant (handles both UTC and TZID-form
547
+ // RECURRENCE-ID) rather than a literal-text regex.
548
+ updatedIcs = removeExceptionFromIcs(updatedIcs, occurrenceDate, existing.all_day);
549
+ await service.updateEvent(args.calendar, args.uid, updatedIcs, {
550
+ url: rawObj.url,
551
+ etag: rawObj.etag,
552
+ });
553
+ return ok({ deleted: true, uid: args.uid });
554
+ }
555
+ // Non-recurring: there is no occurrence to exclude, so this deletes
556
+ // the whole event. Gate it exactly like `span: "all"`.
557
+ const gate = confirmDestructive(ctx, "confirm_delete_event", `Delete event ${args.uid} from ${args.calendar}? This cannot be undone.`);
558
+ if (gate.status === "interrupt")
559
+ return gate.result;
560
+ await service.deleteEvent(args.calendar, args.uid, eventMeta);
561
+ return ok({ deleted: true, uid: args.uid });
562
+ });
563
+ }
564
+ // span="all" — removes the calendar object, series and all.
565
+ const gate = confirmDestructive(ctx, "confirm_delete_event", `Delete event ${args.uid} from ${args.calendar}? If it recurs, the entire series is removed. This cannot be undone.`);
566
+ if (gate.status === "interrupt")
567
+ return gate.result;
568
+ return run(async () => {
569
+ await service.deleteEvent(args.calendar, args.uid);
570
+ return ok({ deleted: true, uid: args.uid });
571
+ });
572
+ },
296
573
  },
297
574
  {
298
575
  name: "create_events_batch",
576
+ title: "Create Events (Batch)",
299
577
  description: "Create multiple events at once. Returns created event count.",
578
+ annotations: {
579
+ readOnlyHint: false,
580
+ destructiveHint: false,
581
+ idempotentHint: false,
582
+ openWorldHint: true,
583
+ },
300
584
  inputSchema: {
301
585
  type: "object",
302
586
  properties: {
303
- calendar: {
304
- type: "string",
305
- description: "Provider-prefixed calendar ID",
306
- },
587
+ calendar: CALENDAR_PROP,
307
588
  events: {
308
589
  type: "array",
309
590
  items: {
310
591
  type: "object",
311
592
  properties: {
312
593
  title: { type: "string", description: "Event title" },
313
- start: {
314
- type: "string",
315
- description: "Start time (ISO 8601)",
316
- },
594
+ start: { type: "string", description: "Start time (ISO 8601)" },
317
595
  end: { type: "string", description: "End time (ISO 8601)" },
318
- all_day: {
319
- type: "boolean",
320
- description: "All-day event flag (default: false)",
321
- },
596
+ all_day: { type: "boolean", description: "All-day event flag (default: false)" },
322
597
  location: { type: "string", description: "Event location" },
323
- description: {
324
- type: "string",
325
- description: "Event description",
326
- },
327
- attendees: {
328
- type: "array",
329
- items: {
330
- type: "object",
331
- properties: {
332
- email: {
333
- type: "string",
334
- description: "Attendee email address. Display name is resolved server-side from the invitee's address book.",
335
- },
336
- },
337
- required: ["email"],
338
- },
339
- description: "List of attendee email addresses to invite.",
340
- },
598
+ description: { type: "string", description: "Event description" },
599
+ attendees: ATTENDEES_PROP("List of attendee email addresses to invite."),
341
600
  alarms: {
342
601
  type: "array",
343
602
  items: {
@@ -356,11 +615,7 @@ export const CALENDAR_TOOLS = [
356
615
  },
357
616
  description: "Event reminders/alarms",
358
617
  },
359
- categories: {
360
- type: "array",
361
- items: { type: "string", description: "Category / tag name" },
362
- description: "Event categories/tags",
363
- },
618
+ categories: CATEGORIES_PROP,
364
619
  recurrence_rule: {
365
620
  type: "string",
366
621
  description: "RFC 5545 RRULE string for a recurring event (e.g., 'FREQ=WEEKLY;BYDAY=MO'). FREQ is required.",
@@ -378,28 +633,87 @@ export const CALENDAR_TOOLS = [
378
633
  },
379
634
  required: ["calendar", "events"],
380
635
  },
636
+ outputSchema: batchCreateSchema,
637
+ handler: (args, service) => run(async () => {
638
+ const accountEmail = service.getAccountEmail(args.calendar);
639
+ const createdEvents = [];
640
+ try {
641
+ for (const input of args.events) {
642
+ const organizer = input.attendees && input.attendees.length > 0 ? { email: accountEmail } : undefined;
643
+ const icsString = generateEventIcs({
644
+ ...input,
645
+ organizer,
646
+ timezone: getTimezone(),
647
+ });
648
+ const uidMatch = icsString.match(/UID:(.+)/);
649
+ const uid = uidMatch ? uidMatch[1].trim() : crypto.randomUUID();
650
+ createdEvents.push(await service.createEvent(args.calendar, icsString, uid));
651
+ }
652
+ }
653
+ catch (err) {
654
+ if (err instanceof Error && err.message.startsWith("Invalid recurrence_rule:")) {
655
+ return calFail("validation_error", err.message);
656
+ }
657
+ throw err;
658
+ }
659
+ return ok({ created: createdEvents.length, events: createdEvents });
660
+ }),
381
661
  },
382
662
  {
383
663
  name: "import_ics",
664
+ title: "Import iCalendar",
384
665
  description: "Import events from iCalendar (.ics) content into a calendar.",
666
+ annotations: {
667
+ readOnlyHint: false,
668
+ destructiveHint: false,
669
+ idempotentHint: false,
670
+ openWorldHint: true,
671
+ },
385
672
  inputSchema: {
386
673
  type: "object",
387
674
  properties: {
388
- calendar: {
389
- type: "string",
390
- description: "Provider-prefixed calendar ID",
391
- },
392
- ics_content: {
393
- type: "string",
394
- description: "Raw iCalendar content string",
395
- },
675
+ calendar: CALENDAR_PROP,
676
+ ics_content: { type: "string", description: "Raw iCalendar content string" },
396
677
  },
397
678
  required: ["calendar", "ics_content"],
398
679
  },
680
+ outputSchema: importResultSchema,
681
+ handler: (args, service) => run(async () => {
682
+ const groups = splitIcsByUid(args.ics_content);
683
+ if (groups.length === 0) {
684
+ return calFail("validation_error", "No events found in ICS content");
685
+ }
686
+ const importedEvents = [];
687
+ const failed = [];
688
+ for (const group of groups) {
689
+ try {
690
+ await service.createEvent(args.calendar, group.ics, group.uid);
691
+ try {
692
+ importedEvents.push(await service.getEvent(args.calendar, group.uid));
693
+ }
694
+ catch {
695
+ importedEvents.push({ uid: group.uid });
696
+ }
697
+ }
698
+ catch (err) {
699
+ failed.push({
700
+ uid: group.uid,
701
+ message: err instanceof Error ? err.message : String(err),
702
+ });
703
+ }
704
+ }
705
+ return ok({
706
+ imported: importedEvents.length,
707
+ ...(failed.length > 0 ? { failed } : {}),
708
+ events: importedEvents,
709
+ });
710
+ }),
399
711
  },
400
712
  {
401
713
  name: "find_free_slots",
714
+ title: "Find Free Slots",
402
715
  description: "Find available time slots across specified calendars. Returns free windows matching the requested duration.",
716
+ annotations: READ_ONLY,
403
717
  inputSchema: {
404
718
  type: "object",
405
719
  properties: {
@@ -408,18 +722,9 @@ export const CALENDAR_TOOLS = [
408
722
  items: { type: "string", description: "Provider-prefixed calendar ID" },
409
723
  description: "Provider-prefixed calendar IDs to check availability against. If omitted, uses all calendars.",
410
724
  },
411
- start: {
412
- type: "string",
413
- description: "Start of search range (ISO 8601)",
414
- },
415
- end: {
416
- type: "string",
417
- description: "End of search range (ISO 8601)",
418
- },
419
- duration: {
420
- type: "number",
421
- description: "Minimum slot duration in minutes",
422
- },
725
+ start: { type: "string", description: "Start of search range (ISO 8601)" },
726
+ end: { type: "string", description: "End of search range (ISO 8601)" },
727
+ duration: { type: "number", description: "Minimum slot duration in minutes" },
423
728
  preferred_start: {
424
729
  type: "string",
425
730
  description: "Preferred earliest time (HH:MM, e.g., 08:00)",
@@ -444,321 +749,22 @@ export const CALENDAR_TOOLS = [
444
749
  },
445
750
  required: ["start", "end", "duration"],
446
751
  },
752
+ outputSchema: freeSlotsSchema,
753
+ handler: (args, service) => run(async () => {
754
+ let calendarIds = args.calendars;
755
+ if (!calendarIds || calendarIds.length === 0) {
756
+ const allCals = await service.listCalendars();
757
+ calendarIds = allCals.map((c) => c.calendar_id);
758
+ }
759
+ const slots = await service.findFreeSlots(calendarIds, args.start, args.end, args.duration, {
760
+ preferredStart: args.preferred_start,
761
+ preferredEnd: args.preferred_end,
762
+ ignoreTentative: args.ignore_tentative ?? false,
763
+ excludeCalendars: args.exclude_calendars,
764
+ includeAllDayAsBusy: args.include_all_day_as_busy ?? false,
765
+ });
766
+ return ok({ slots, count: slots.length });
767
+ }),
447
768
  },
448
769
  ];
449
- function withDebug(payload) {
450
- if (process.env.CAL_MCP_DEBUG !== "1")
451
- return payload;
452
- const timings = drainDebugTimings();
453
- if (timings.length === 0)
454
- return payload;
455
- return { ...payload, _debug: { timings } };
456
- }
457
- function ok(payload) {
458
- return {
459
- content: [{ type: "text", text: JSON.stringify(withDebug(payload), null, 2) }],
460
- };
461
- }
462
- function error(code, message) {
463
- return {
464
- content: [
465
- {
466
- type: "text",
467
- text: JSON.stringify(withDebug({ error: code, message })),
468
- },
469
- ],
470
- isError: true,
471
- };
472
- }
473
- export async function handleCalendarTool(name, args, service) {
474
- try {
475
- switch (name) {
476
- case "list_calendars": {
477
- const calendars = await service.listCalendars();
478
- return ok({ calendars });
479
- }
480
- case "list_events": {
481
- const calendar = args.calendar;
482
- const detailLevel = args.detail_level ?? "summary";
483
- const events = await fetchEvents(service, calendar, args.start, args.end, detailLevel);
484
- return ok({ events });
485
- }
486
- case "get_today_events": {
487
- const calendar = args.calendar;
488
- const detailLevel = args.detail_level ?? "summary";
489
- const now = new Date();
490
- const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate()).toISOString();
491
- const todayEnd = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59).toISOString();
492
- const events = await fetchEvents(service, calendar, todayStart, todayEnd, detailLevel);
493
- return ok({ events });
494
- }
495
- case "search_events": {
496
- const query = args.query.toLowerCase();
497
- const calendar = args.calendar;
498
- const detailLevel = args.detail_level ?? "summary";
499
- const now = new Date();
500
- const start = args.start ?? new Date(now.getTime() - 90 * 86400000).toISOString();
501
- const end = args.end ?? new Date(now.getTime() + 90 * 86400000).toISOString();
502
- const events = await fetchEvents(service, calendar, start, end, detailLevel);
503
- const matched = events.filter((e) => {
504
- const title = e.title?.toLowerCase() ?? "";
505
- const location = e.location?.toLowerCase() ?? "";
506
- const description = detailLevel === "full" ? (e.description?.toLowerCase() ?? "") : "";
507
- return title.includes(query) || location.includes(query) || description.includes(query);
508
- });
509
- return ok({ events: matched });
510
- }
511
- case "get_event": {
512
- const event = await service.getEvent(args.calendar, args.uid);
513
- return ok({ event });
514
- }
515
- case "create_event": {
516
- try {
517
- const attendees = args.attendees;
518
- const calendarId = args.calendar;
519
- // Populate ORGANIZER whenever attendees are present — CalDAV servers
520
- // (SOGo/mailbox.org) reject ATTENDEE-without-ORGANIZER PUTs with 412.
521
- const organizer = attendees && attendees.length > 0
522
- ? { email: service.getAccountEmail(calendarId) }
523
- : undefined;
524
- const icsString = generateEventIcs({
525
- title: args.title,
526
- start: args.start,
527
- end: args.end,
528
- all_day: args.all_day ?? false,
529
- location: args.location,
530
- description: args.description,
531
- attendees,
532
- alarms: args.alarms,
533
- categories: args.categories,
534
- recurrence_rule: args.recurrence_rule,
535
- organizer,
536
- availability: args.availability,
537
- timezone: getTimezone(),
538
- });
539
- const uidMatch = icsString.match(/UID:(.+)/);
540
- const uid = uidMatch ? uidMatch[1].trim() : crypto.randomUUID();
541
- const event = await service.createEvent(args.calendar, icsString, uid);
542
- return ok({ event });
543
- }
544
- catch (err) {
545
- if (err instanceof Error && err.message.startsWith("Invalid recurrence_rule:")) {
546
- return error("validation_error", err.message);
547
- }
548
- throw err;
549
- }
550
- }
551
- case "update_event": {
552
- const span = args.span ?? "this";
553
- const { event: existing, meta } = await service.getEventWithMeta(args.calendar, args.uid);
554
- // span="this" on a recurring event: create exception VEVENT
555
- if (existing.is_recurring && span === "this") {
556
- const occurrenceDate = args.occurrence_date;
557
- if (!occurrenceDate) {
558
- return error("validation_error", "occurrence_date is required when span is 'this' on a recurring event");
559
- }
560
- const rawObj = await service.fetchRawCalendarObject(args.calendar, args.uid);
561
- const overrides = {};
562
- if (args.title !== undefined)
563
- overrides.title = args.title;
564
- if (args.start !== undefined)
565
- overrides.start = args.start;
566
- if (args.end !== undefined)
567
- overrides.end = args.end;
568
- if (args.all_day !== undefined)
569
- overrides.all_day = args.all_day;
570
- if (args.location !== undefined)
571
- overrides.location = args.location;
572
- if (args.description !== undefined)
573
- overrides.description = args.description;
574
- if (args.attendees !== undefined)
575
- overrides.attendees = args.attendees;
576
- if (args.alarms !== undefined)
577
- overrides.alarms = args.alarms;
578
- if (args.categories !== undefined)
579
- overrides.categories = args.categories;
580
- if (args.availability !== undefined)
581
- overrides.availability = args.availability;
582
- // If the effective event will have attendees but no organizer yet,
583
- // inject one so the CalDAV PUT satisfies server scheduling preconditions.
584
- const effectiveAttendees = overrides.attendees ?? existing.attendees;
585
- if (effectiveAttendees && effectiveAttendees.length > 0 && !existing.organizer) {
586
- overrides.organizer = { email: service.getAccountEmail(args.calendar) };
587
- }
588
- const exceptionVevent = createExceptionComponent(rawObj.data, "vevent", occurrenceDate, overrides, existing.all_day);
589
- const combinedIcs = combineIcsComponents(rawObj.data, exceptionVevent);
590
- await service.updateEvent(args.calendar, args.uid, combinedIcs, {
591
- url: rawObj.url,
592
- etag: rawObj.etag,
593
- });
594
- // Build response from overrides + existing
595
- const occDuration = new Date(existing.end).getTime() - new Date(existing.start).getTime();
596
- const responseEvent = {
597
- ...existing,
598
- title: overrides.title ?? existing.title,
599
- start: overrides.start ?? occurrenceDate,
600
- end: overrides.end ??
601
- new Date(new Date(occurrenceDate).getTime() + occDuration).toISOString(),
602
- all_day: overrides.all_day ?? existing.all_day,
603
- location: overrides.location ?? existing.location,
604
- description: overrides.description ?? existing.description,
605
- attendees: overrides.attendees ?? existing.attendees,
606
- alarms: overrides.alarms ?? existing.alarms,
607
- categories: overrides.categories ?? existing.categories,
608
- occurrence_date: occurrenceDate,
609
- recurrence_rule: null,
610
- };
611
- return ok({ event: responseEvent });
612
- }
613
- const effectiveAttendees = args.attendees ??
614
- existing.attendees?.map((a) => ({
615
- email: a.email,
616
- name: a.name ?? undefined,
617
- }));
618
- // Preserve existing ORGANIZER if present; otherwise inject account-owner
619
- // when the resulting event has attendees. Without this, CalDAV servers
620
- // (SOGo/mailbox.org) reject the PUT with 412 because ATTENDEE requires
621
- // ORGANIZER per RFC 5545 §3.6.1 / RFC 6638 scheduling preconditions.
622
- let organizer;
623
- if (existing.organizer) {
624
- organizer = { email: existing.organizer.email, name: existing.organizer.name };
625
- }
626
- else if (effectiveAttendees && effectiveAttendees.length > 0) {
627
- organizer = { email: service.getAccountEmail(args.calendar) };
628
- }
629
- const effectiveAvailability = args.availability ??
630
- (existing.availability === "free" || existing.availability === "busy"
631
- ? existing.availability
632
- : undefined);
633
- const icsString = generateEventIcs({
634
- uid: args.uid,
635
- title: args.title ?? existing.title,
636
- start: args.start ?? existing.start,
637
- end: args.end ?? existing.end,
638
- all_day: args.all_day ?? existing.all_day,
639
- location: args.location ?? existing.location ?? undefined,
640
- description: args.description ?? existing.description ?? undefined,
641
- attendees: effectiveAttendees,
642
- alarms: args.alarms ??
643
- existing.alarms?.map((a) => ({ type: a.type, trigger: a.trigger })),
644
- categories: args.categories ?? existing.categories,
645
- organizer,
646
- availability: effectiveAvailability,
647
- timezone: getTimezone(),
648
- });
649
- const event = await service.updateEvent(args.calendar, args.uid, icsString, meta);
650
- return ok({ event });
651
- }
652
- case "delete_event": {
653
- const span = args.span ?? "all";
654
- // span="this" on a recurring event: add EXDATE to exclude this occurrence
655
- if (span === "this") {
656
- const { event: existing, meta: eventMeta } = await service.getEventWithMeta(args.calendar, args.uid);
657
- if (existing.is_recurring) {
658
- const occurrenceDate = args.occurrence_date;
659
- if (!occurrenceDate) {
660
- return error("validation_error", "occurrence_date is required when span is 'this' on a recurring event");
661
- }
662
- const rawObj = await service.fetchRawCalendarObject(args.calendar, args.uid);
663
- let updatedIcs = addExdateToIcs(rawObj.data, occurrenceDate, existing.all_day);
664
- // Remove any existing exception VEVENT for this date
665
- const recIdDate = new Date(occurrenceDate);
666
- const formattedRecId = existing.all_day
667
- ? recIdDate.toISOString().slice(0, 10).replace(/-/g, "")
668
- : recIdDate
669
- .toISOString()
670
- .replace(/[-:]/g, "")
671
- .replace(/\.\d{3}/, "");
672
- const exceptionRegex = new RegExp(`BEGIN:VEVENT\\r?\\n(?:(?!BEGIN:VEVENT)[\\s\\S])*?RECURRENCE-ID[^:]*:${formattedRecId}[\\s\\S]*?END:VEVENT\\r?\\n?`);
673
- updatedIcs = updatedIcs.replace(exceptionRegex, "");
674
- await service.updateEvent(args.calendar, args.uid, updatedIcs, {
675
- url: rawObj.url,
676
- etag: rawObj.etag,
677
- });
678
- return ok({ deleted: true, uid: args.uid });
679
- }
680
- // Non-recurring with span="this" — just delete normally
681
- await service.deleteEvent(args.calendar, args.uid, eventMeta);
682
- return ok({ deleted: true, uid: args.uid });
683
- }
684
- // span="all" — delete the entire calendar object
685
- await service.deleteEvent(args.calendar, args.uid);
686
- return ok({ deleted: true, uid: args.uid });
687
- }
688
- case "create_events_batch": {
689
- const eventInputs = args.events;
690
- const calendarId = args.calendar;
691
- const accountEmail = service.getAccountEmail(calendarId);
692
- const createdEvents = [];
693
- try {
694
- for (const input of eventInputs) {
695
- const organizer = input.attendees && input.attendees.length > 0 ? { email: accountEmail } : undefined;
696
- const icsString = generateEventIcs({
697
- ...input,
698
- organizer,
699
- timezone: getTimezone(),
700
- });
701
- const uidMatch = icsString.match(/UID:(.+)/);
702
- const uid = uidMatch ? uidMatch[1].trim() : crypto.randomUUID();
703
- const event = await service.createEvent(calendarId, icsString, uid);
704
- createdEvents.push(event);
705
- }
706
- }
707
- catch (err) {
708
- if (err instanceof Error && err.message.startsWith("Invalid recurrence_rule:")) {
709
- return error("validation_error", err.message);
710
- }
711
- throw err;
712
- }
713
- return ok({ created: createdEvents.length, events: createdEvents });
714
- }
715
- case "import_ics": {
716
- const icsContent = args.ics_content;
717
- const parsed = parseIcsEvents(icsContent);
718
- if (parsed.length === 0) {
719
- return error("validation_error", "No events found in ICS content");
720
- }
721
- await service.createEvent(args.calendar, icsContent, parsed[0].uid);
722
- const importedEvents = [];
723
- for (const evt of parsed) {
724
- try {
725
- const event = await service.getEvent(args.calendar, evt.uid);
726
- importedEvents.push(event);
727
- }
728
- catch {
729
- // Event may not be fetchable individually if multi-event ICS — skip
730
- }
731
- }
732
- return ok({ imported: parsed.length, events: importedEvents });
733
- }
734
- case "find_free_slots": {
735
- let calendarIds = args.calendars;
736
- if (!calendarIds || calendarIds.length === 0) {
737
- const allCals = await service.listCalendars();
738
- calendarIds = allCals.map((c) => c.calendar_id);
739
- }
740
- const slots = await service.findFreeSlots(calendarIds, args.start, args.end, args.duration, {
741
- preferredStart: args.preferred_start,
742
- preferredEnd: args.preferred_end,
743
- ignoreTentative: args.ignore_tentative ?? false,
744
- excludeCalendars: args.exclude_calendars,
745
- includeAllDayAsBusy: args.include_all_day_as_busy ?? false,
746
- });
747
- return ok({ slots, count: slots.length });
748
- }
749
- default:
750
- return error("validation_error", `Unknown tool: ${name}`);
751
- }
752
- }
753
- catch (err) {
754
- if (err && typeof err === "object" && "code" in err) {
755
- const calErr = err;
756
- if (calErr.code === "CALENDAR_NOT_FOUND" || calErr.code === "EVENT_NOT_FOUND") {
757
- return error("not_found", calErr.message);
758
- }
759
- }
760
- const pimError = toPimError(err instanceof Error ? err : new Error(String(err)));
761
- return error("backend_error", pimError.message);
762
- }
763
- }
764
770
  //# sourceMappingURL=calendarTools.js.map