Skip to main content
Glama

Find available appointment slots

find_available_slot

Find open appointment slots for a specific medical specialty within a date range. Filters by clinic and excludes conflicts with existing appointments.

Instructions

Return open appointment slots for a given specialty in a date range. Filters by clinic_id and skips conflicts with existing appointments.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
clinic_idYes
specialtyYes
from_isoYesInclusive start of the search window, ISO 8601
to_isoYesExclusive end of the search window, ISO 8601
duration_minutesNo
limitNo

Implementation Reference

  • Main handler function that finds available appointment slots for a given clinic, specialty, and date range. It iterates over providers, checks working hours, splits days into slots of the requested duration, filters out conflicts with existing appointments, and returns sorted results capped by the limit.
    export function findAvailableSlot(
      store: ClinicStore,
      raw: unknown,
    ): { slots: AvailableSlot[] } {
      const args = Args.parse(raw);
      const from = new Date(args.from_iso);
      const to = new Date(args.to_iso);
      if (Number.isNaN(from.getTime()) || Number.isNaN(to.getTime())) {
        throw new ValidationError("from_iso and to_iso must be valid ISO 8601");
      }
      if (from.getTime() >= to.getTime()) {
        throw new ValidationError("from_iso must be before to_iso");
      }
    
      const providers = store.listProviders(args.clinic_id, args.specialty);
      const slots: AvailableSlot[] = [];
    
      for (const provider of providers) {
        const existing = store
          .listProviderAppointments(args.clinic_id, provider.id)
          .map((a) => ({
            start: new Date(a.start_iso).getTime(),
            end: new Date(a.end_iso).getTime(),
          }));
    
        const startDay = startOfUtcDay(from);
        const endDay = startOfUtcDay(new Date(to.getTime() - 1));
    
        for (let day = startDay; day <= endDay; day += MS_PER_DAY) {
          const date = new Date(day);
          const weekday = date.getUTCDay();
          if (!provider.working_hours.days.includes(weekday)) continue;
    
          const dayStart =
            day + provider.working_hours.start_hour * 60 * MS_PER_MINUTE;
          const dayEnd =
            day + provider.working_hours.end_hour * 60 * MS_PER_MINUTE;
          const slotMs = args.duration_minutes * MS_PER_MINUTE;
    
          for (let s = dayStart; s + slotMs <= dayEnd; s += slotMs) {
            if (s < from.getTime() || s + slotMs > to.getTime()) continue;
            const conflicts = existing.some((a) => s < a.end && s + slotMs > a.start);
            if (conflicts) continue;
    
            slots.push({
              provider_id: provider.id,
              provider_name: provider.name,
              start_iso: new Date(s).toISOString(),
              end_iso: new Date(s + slotMs).toISOString(),
            });
          }
        }
      }
    
      slots.sort((a, b) => a.start_iso.localeCompare(b.start_iso));
      return { slots: slots.slice(0, args.limit) };
    }
  • Input schema definition using Zod — defines the input parameters: clinic_id, specialty, from_iso, to_iso, duration_minutes (default 30), and limit (default 10).
    export const findAvailableSlotInput = {
      clinic_id: z.string(),
      specialty: Specialty,
      from_iso: z.string().describe("Inclusive start of the search window, ISO 8601"),
      to_iso: z.string().describe("Exclusive end of the search window, ISO 8601"),
      duration_minutes: z.number().int().min(15).max(120).default(30),
      limit: z.number().int().min(1).max(50).default(10),
    };
  • TypeScript interface defining the output shape of each available slot returned by the handler.
    export interface AvailableSlot {
      provider_id: string;
      provider_name: string;
      start_iso: string;
      end_iso: string;
    }
  • src/server.ts:50-59 (registration)
    Registration of the tool with the MCP server using registerTool, with title, description, input schema, and the handler wrapped in an error-handling wrapper.
    server.registerTool(
      "find_available_slot",
      {
        title: "Find available appointment slots",
        description:
          "Return open appointment slots for a given specialty in a date range. Filters by clinic_id and skips conflicts with existing appointments.",
        inputSchema: findAvailableSlotInput,
      },
      wrap((args) => findAvailableSlot(store, args)),
    );
  • Helper function that returns the epoch milliseconds for the start (midnight) of a given date's UTC day, used for day-by-day iteration in the handler.
    function startOfUtcDay(d: Date): number {
      return Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());
    }
Behavior3/5

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

With no annotations, the description carries full burden. It discloses that it 'skips conflicts with existing appointments,' indicating a read-only, availability-checking behavior. However, it does not mention whether it requires authentication, whether it is idempotent, or any side effects. The behavioral disclosure is partial but not misleading.

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?

Two sentences, front-loaded with the main action. Every word serves a purpose: what it returns, the key filters, and the conflict avoidance. No fluff.

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?

Despite moderate complexity (6 params, no output schema), the description omits important details: return format (list of slot times?), ordering, pagination, error conditions. The sibling 'book_appointment' suggests a workflow, but no linkage is provided. The description is too sparse for complete agent understanding.

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 low (33%, only from/to have descriptions). The description adds meaning for specialty and date range, and mentions clinic_id filtering. But it does not explain duration_minutes or limit parameters. Given low coverage, the description partially compensates but leaves gaps.

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

Purpose5/5

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

Description clearly states 'Return open appointment slots' with specific constraints ('given specialty in a date range', 'Filters by clinic_id'). This distinguishes it from sibling tools like 'book_appointment' (booking) and 'record_intake' (recording). The verb and resource are immediately clear.

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?

The description does not provide any guidance on when to use this tool versus alternatives, such as before booking an appointment or when an immediate slot is needed. It describes what it does but lacks explicit context for selection among siblings.

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

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/dominikstefanski/clinic-mcp'

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