Skip to main content
Glama

google_calendar_find_free_time

Identify open time slots in Google Calendar between events for a specified period and duration. Input start and end dates, desired duration, and optional calendar IDs to find available time.

Instructions

Find available time slots between events

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
calendarIdsNoOptional: Calendar IDs to check (defaults to primary if not specified)
durationYesMinimum slot duration in minutes
endDateYesEnd of search period (ISO format)
startDateYesStart of search period (ISO format)

Implementation Reference

  • The main handler function for the 'google_calendar_find_free_time' tool. Validates arguments and delegates to GoogleCalendar.findFreeTime method.
    export async function handleCalendarFindFreeTime(
      args: any,
      googleCalendarInstance: GoogleCalendar
    ) {
      if (!isFindFreeTimeArgs(args)) {
        throw new Error("Invalid arguments for google_calendar_find_free_time");
      }
    
      const { startDate, endDate, duration, calendarIds } = args;
      const result = await googleCalendarInstance.findFreeTime(
        startDate,
        endDate,
        duration,
        calendarIds
      );
      return {
        content: [{ type: "text", text: result }],
        isError: false,
      };
    }
  • Core logic implementation in GoogleCalendar class that fetches events from Google Calendar API and computes free time slots of specified duration.
    async findFreeTime(
      startDate: string,
      endDate: string,
      durationMinutes: number,
      calendarIds?: string[]
    ) {
      try {
        // If no calendar IDs specified, use the default one
        const targetCalendarIds = calendarIds || [this.defaultCalendarId];
    
        // Get all events in the date range for each calendar
        const allEvents: any[] = [];
    
        for (const calId of targetCalendarIds) {
          const params: any = {
            calendarId: calId,
            timeMin: startDate,
            timeMax: endDate,
            singleEvents: true,
            orderBy: "startTime",
          };
    
          const res = await this.calendar.events.list(params);
          allEvents.push(...(res.data.items || []));
        }
    
        // Sort events by start time
        allEvents.sort((a, b) => {
          const aStart = new Date(a.start.dateTime || a.start.date).getTime();
          const bStart = new Date(b.start.dateTime || b.start.date).getTime();
          return aStart - bStart;
        });
    
        // Convert duration from minutes to milliseconds
        const durationMs = durationMinutes * 60 * 1000;
    
        // Start from the search period start date
        let currentTime = new Date(startDate).getTime();
        const endTime = new Date(endDate).getTime();
    
        // Store free time slots
        const freeSlots = [];
    
        // Process all events to find gaps between them
        for (const event of allEvents) {
          const eventStart = new Date(
            event.start.dateTime || event.start.date
          ).getTime();
    
          // Check if there's enough free time before this event starts
          if (eventStart - currentTime >= durationMs) {
            // We found a free slot
            const slotStart = new Date(currentTime).toISOString();
            const slotEnd = new Date(eventStart).toISOString();
            freeSlots.push({ start: slotStart, end: slotEnd });
          }
    
          // Move current time to the end of this event
          const eventEnd = new Date(
            event.end.dateTime || event.end.date
          ).getTime();
          currentTime = Math.max(currentTime, eventEnd);
        }
    
        // Check if there's free time after the last event
        if (endTime - currentTime >= durationMs) {
          const slotStart = new Date(currentTime).toISOString();
          const slotEnd = new Date(endTime).toISOString();
          freeSlots.push({ start: slotStart, end: slotEnd });
        }
    
        // Format results
        if (freeSlots.length === 0) {
          return "No free time slots found that meet the criteria.";
        }
    
        return (
          "Available time slots:\n" +
          freeSlots
            .map(
              (slot) =>
                `${new Date(slot.start).toLocaleString()} - ${new Date(
                  slot.end
                ).toLocaleString()} ` +
                `(${Math.round(
                  (new Date(slot.end).getTime() -
                    new Date(slot.start).getTime()) /
                    (60 * 1000)
                )} minutes)`
            )
            .join("\n")
        );
      } catch (error) {
        throw new Error(
          `Failed to find free time: ${
            error instanceof Error ? error.message : String(error)
          }`
        );
      }
    }
  • Tool schema definition with input validation schema for 'google_calendar_find_free_time'.
    export const FIND_FREE_TIME_TOOL: Tool = {
      name: "google_calendar_find_free_time",
      description: "Find available time slots between events",
      inputSchema: {
        type: "object",
        properties: {
          startDate: {
            type: "string",
            description: "Start of search period (ISO format)",
          },
          endDate: {
            type: "string",
            description: "End of search period (ISO format)",
          },
          duration: {
            type: "number",
            description: "Minimum slot duration in minutes",
          },
          calendarIds: {
            type: "array",
            items: { type: "string" },
            description:
              "Optional: Calendar IDs to check (defaults to primary if not specified)",
          },
        },
        required: ["startDate", "endDate", "duration"],
      },
    };
  • Registration in the main server tool dispatch switch statement, routing calls to the handler.
    case "google_calendar_find_free_time":
      return await calendarHandlers.handleCalendarFindFreeTime(
        args,
        googleCalendarInstance
      );
  • Type guard function for validating arguments to the 'google_calendar_find_free_time' tool.
    export function isFindFreeTimeArgs(args: any): args is {
      startDate: string;
      endDate: string;
      duration: number;
      calendarIds?: string[];
    } {
      return (
        args &&
        typeof args.startDate === "string" &&
        typeof args.endDate === "string" &&
        typeof args.duration === "number" &&
        (args.calendarIds === undefined || Array.isArray(args.calendarIds))
      );
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It mentions 'available time slots' but doesn't disclose how availability is determined (e.g., considering event busy status, working hours, or permissions). No information on rate limits, authentication needs, or output format is included, leaving significant gaps for a tool that likely interacts with calendar data.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's function without unnecessary words. It's front-loaded with the core purpose, making it easy to parse quickly. Every word earns its place, adhering to conciseness best practices.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is incomplete for a tool with 4 parameters that likely involves complex calendar logic. It doesn't explain behavioral aspects like how free time is calculated, what happens with multiple calendars, or the return format. For a tool of this complexity, more context is needed to guide effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all parameters. The description adds no additional meaning beyond the schema's details, such as explaining how 'calendarIds' interact with availability or what constitutes a 'slot'. Baseline 3 is appropriate as the schema handles parameter documentation adequately.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('find') and resource ('available time slots between events'), making the purpose understandable. It distinguishes itself from siblings like 'get_events' by focusing on free time rather than events themselves. However, it doesn't explicitly differentiate from other calendar tools beyond the general concept.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. While the purpose implies it's for scheduling or checking availability, there's no mention of prerequisites, constraints, or comparison with other tools like 'get_events' for overlapping functionality. The description lacks explicit usage context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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/vakharwalad23/google-mcp'

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