Skip to main content
Glama
erickva

Google Calendar - No deletion

by erickva

meeting_suggestion

Identifies and suggests available meeting slots within the next 30 days based on working hours, meeting length, and specified calendar IDs, excluding bank holidays and weekends.

Instructions

Suggest available meeting slots within the next 30 days

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
bankHolidaysNoList of bank holiday dates in YYYY-MM-DD format
calendarIdsNoList of Google Calendar IDs (default: ["primary"])
daysToSearchNoNumber of days to find slots for (default: 3)
meetingLengthMinutesNoMeeting length in minutes (default: 60)
slotsPerDayNoNumber of slots per day to suggest (default: 1)
timezoneNoTimezone for scheduling (default: America/Sao_Paulo)
workingHoursEndNoEnd of working hours (24h format, default: 17)
workingHoursStartNoStart of working hours (24h format, default: 9)

Implementation Reference

  • Primary handler function implementing the meeting_suggestion tool. Queries Google Calendar freebusy API for availability across specified calendars and date range, filters for working hours (excluding weekends and bank holidays), computes free slots using the findFreeSlots helper, and returns suggested meeting times.
    private async handleMeetingSuggestion(args: any) { try { const meetingLength = args?.meetingLengthMinutes || 60; const workStartHour = args?.workingHoursStart || 9; const workEndHour = args?.workingHoursEnd || 17; const timezone = args?.timezone || 'America/Sao_Paulo'; const slotsPerDay = args?.slotsPerDay || 1; const daysToSearch = args?.daysToSearch || 3; const maxDaysToLookAhead = args?.maxDaysToLookAhead || 30; // New parameter with default const bankHolidays = args?.bankHolidays || []; const calendarIds = args?.calendarIds || ['primary']; // Corrected timezone-aware logic using Luxon const suggestions: any[] = []; let daysWithSlotsFound = 0; // Track days with slots let startDate; if (args?.startDate) { startDate = DateTime.fromISO(args.startDate, { zone: timezone }).startOf('day'); } else { // Default to tomorrow in the specified timezone startDate = DateTime.now().setZone(timezone).plus({ days: 1 }).startOf('day'); } const endDate = startDate.plus({ days: maxDaysToLookAhead }).endOf('day'); const busyResponse = await this.calendar.freebusy.query({ requestBody: { timeMin: startDate.toISO(), timeMax: endDate.toISO(), timeZone: timezone, items: calendarIds.map((id: string) => ({ id })), }, }); console.log("##########################################################################\n"); console.log("##########################################################################\n"); console.log("##########################################################################\n"); console.log("Freebusy Response:", JSON.stringify(busyResponse.data, null, 2)); const busySlots = calendarIds.flatMap( (id: string) => busyResponse.data.calendars?.[id]?.busy || [] ).filter((slot: { start?: string; end?: string }): slot is { start: string; end: string } => !!slot.start && !!slot.end); let dayPointer = startDate; // Luxon DateTime while (daysWithSlotsFound < daysToSearch && dayPointer < endDate) { const dayOfWeek = dayPointer.weekday; const formattedDate = dayPointer.toISODate(); if (dayOfWeek < 6 && !bankHolidays.includes(formattedDate)) { // Ensure dayPointer is a DateTime object in your timezone let dayStart = dayPointer.set({ hour: workStartHour, minute: 0, second: 0, millisecond: 0 }); let dayEnd = dayPointer.set({ hour: workEndHour, minute: 0, second: 0, millisecond: 0 }); // Now explicitly pass native Dates to your findFreeSlots const freeSlots = this.findFreeSlots( busySlots, dayStart.toJSDate(), dayEnd.toJSDate(), meetingLength ); console.log("###### Busy slots received####################################################################\n"); console.log('Busy slots received:', busySlots); console.log("###### FREE slots received####################################################################\n"); console.log('Free slots calculated:', freeSlots); // Collect up to `slotsPerDay` slots for this day let slotsAddedToday = 0; for (const slot of freeSlots) { if (slotsAddedToday >= slotsPerDay) break; suggestions.push({ start: DateTime.fromJSDate(slot.start).setZone(timezone).toISO(), end: DateTime.fromJSDate(slot.end).setZone(timezone).toISO(), }); slotsAddedToday++; } daysWithSlotsFound++; // counts this day as processed } dayPointer = dayPointer.plus({ days: 1 }); } return { content: [ { type: 'text', text: JSON.stringify(suggestions, null, 2), }, ], }; } catch (error: any) { return { content: [ { type: 'text', text: `Error suggesting meetings: ${error.message}`, }, ], isError: true, }; } }
  • Input schema for the meeting_suggestion tool, defining parameters such as calendars, duration, working hours, timezone, number of slots, search duration, and holidays.
    inputSchema: { type: 'object', properties: { calendarIds: { type: 'array', items: { type: 'string' }, description: 'List of Google Calendar IDs (default: ["primary"])',}, meetingLengthMinutes: { type: 'number', description: 'Meeting length in minutes (default: 60)' }, workingHoursStart: { type: 'number', description: 'Start of working hours (24h format, default: 9)' }, workingHoursEnd: { type: 'number', description: 'End of working hours (24h format, default: 17)' }, timezone: { type: 'string', description: 'Timezone for scheduling (default: America/Sao_Paulo)' }, slotsPerDay: { type: 'number', description: 'Number of slots per day to suggest (default: 1)' }, daysToSearch: { type: 'number', description: 'Number of days to find slots for (default: 3)' }, bankHolidays: { type: 'array', items: { type: 'string' }, description: 'List of bank holiday dates in YYYY-MM-DD format' }, }, },
  • src/index.ts:208-224 (registration)
    Registration of the meeting_suggestion tool in the ListToolsRequestSchema handler, including name, description, and input schema.
    { name: 'meeting_suggestion', description: 'Suggest available meeting slots within the next 30 days', inputSchema: { type: 'object', properties: { calendarIds: { type: 'array', items: { type: 'string' }, description: 'List of Google Calendar IDs (default: ["primary"])',}, meetingLengthMinutes: { type: 'number', description: 'Meeting length in minutes (default: 60)' }, workingHoursStart: { type: 'number', description: 'Start of working hours (24h format, default: 9)' }, workingHoursEnd: { type: 'number', description: 'End of working hours (24h format, default: 17)' }, timezone: { type: 'string', description: 'Timezone for scheduling (default: America/Sao_Paulo)' }, slotsPerDay: { type: 'number', description: 'Number of slots per day to suggest (default: 1)' }, daysToSearch: { type: 'number', description: 'Number of days to find slots for (default: 3)' }, bankHolidays: { type: 'array', items: { type: 'string' }, description: 'List of bank holiday dates in YYYY-MM-DD format' }, }, }, }
  • src/index.ts:242-243 (registration)
    Dispatch case in the CallToolRequestSchema handler that routes calls to the meeting_suggestion tool to its handler function.
    case 'meeting_suggestion': return await this.handleMeetingSuggestion(request.params.arguments);
  • Helper function that calculates free time slots within a given workday by identifying gaps between sorted busy periods, ensuring slots are at least the required meeting length.
    private findFreeSlots( busySlots: Array<{ start: string; end: string }>, dayStart: Date, dayEnd: Date, meetingLengthMinutes: number ): Array<{ start: Date; end: Date }> { const freeSlots: Array<{ start: Date; end: Date }> = []; let pointer = new Date(dayStart); // Sort busy slots const sortedBusySlots = busySlots .filter((slot) => new Date(slot.start) < dayEnd && new Date(slot.end) > dayStart) .sort((a, b) => new Date(a.start).getTime() - new Date(b.start).getTime()); for (const busy of sortedBusySlots) { const busyStart = new Date(busy.start); const busyEnd = new Date(busy.end); // While loop to add multiple slots before busyStart while ((busyStart.getTime() - pointer.getTime()) >= (meetingLengthMinutes * 60000)) { freeSlots.push({ start: new Date(pointer), end: new Date(pointer.getTime() + meetingLengthMinutes * 60000), }); pointer.setTime(pointer.getTime() + meetingLengthMinutes * 60000); } // Move pointer to after the busy slot if pointer overlaps busy if (pointer < busyEnd) pointer = new Date(busyEnd); } // After last busy slot: fill remaining time until dayEnd while ((dayEnd.getTime() - pointer.getTime()) >= (meetingLengthMinutes * 60000)) { freeSlots.push({ start: new Date(pointer), end: new Date(pointer.getTime() + meetingLengthMinutes * 60000), }); pointer.setTime(pointer.getTime() + meetingLengthMinutes * 60000); } return freeSlots; }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/erickva/google-workspace-mcp-server-no-calendar-deletetion'

If you have feedback or need assistance with the MCP directory API, please join our Discord server