Skip to main content
Glama
calendar.ts4.51 kB
import GoogleCalendar from "../utils/calendar"; import { isSetDefaultCalendarArgs, isListCalendarsArgs, isCreateEventArgs, isGetEventsArgs, isGetEventArgs, isUpdateEventArgs, isDeleteEventArgs, isFindFreeTimeArgs, } from "../utils/helper"; export async function handleCalendarSetDefault( args: any, googleCalendarInstance: GoogleCalendar ) { if (!isSetDefaultCalendarArgs(args)) { throw new Error("Invalid arguments for google_calendar_set_default"); } const { calendarId } = args; const result = googleCalendarInstance.setDefaultCalendarId(calendarId); return { content: [{ type: "text", text: result }], isError: false, }; } export async function handleCalendarListCalendars( args: any, googleCalendarInstance: GoogleCalendar ) { if (!isListCalendarsArgs(args)) { throw new Error("Invalid arguments for google_calendar_list_calendars"); } const calendars = await googleCalendarInstance.listCalendars(); const formattedResult = calendars .map( (cal: any) => `${cal.summary}${cal.primary ? " (Primary)" : ""} - ID: ${cal.id}` ) .join("\n"); return { content: [{ type: "text", text: formattedResult }], isError: false, }; } export async function handleCalendarCreateEvent( args: any, googleCalendarInstance: GoogleCalendar ) { if (!isCreateEventArgs(args)) { throw new Error("Invalid arguments for google_calendar_create_event"); } const { summary, start, end, calendarId, description, location, colorId, attendees, recurrence, } = args; if (!summary || !start || !end) throw new Error("Missing required arguments"); const result = await googleCalendarInstance.createEvent( summary, start, end, calendarId, description, location, colorId, attendees, recurrence ); return { content: [{ type: "text", text: result }], isError: false, }; } export async function handleCalendarGetEvents( args: any, googleCalendarInstance: GoogleCalendar ) { if (!isGetEventsArgs(args)) { throw new Error("Invalid arguments for google_calendar_get_events"); } const { limit, calendarId, timeMin, timeMax, q, showDeleted } = args; const result = await googleCalendarInstance.getEvents( limit || 10, calendarId, timeMin, timeMax, q, showDeleted ); return { content: [{ type: "text", text: result }], isError: false, }; } export async function handleCalendarGetEvent( args: any, googleCalendarInstance: GoogleCalendar ) { if (!isGetEventArgs(args)) { throw new Error("Invalid arguments for google_calendar_get_event"); } const { eventId, calendarId } = args; const result = await googleCalendarInstance.getEvent(eventId, calendarId); return { content: [{ type: "text", text: result }], isError: false, }; } export async function handleCalendarUpdateEvent( args: any, googleCalendarInstance: GoogleCalendar ) { if (!isUpdateEventArgs(args)) { throw new Error("Invalid arguments for google_calendar_update_event"); } const { eventId, calendarId, summary, description, start, end, location, colorId, attendees, recurrence, } = args; const changes = { summary, description, start, end, location, colorId, attendees, recurrence, }; const result = await googleCalendarInstance.updateEvent( eventId, changes, calendarId ); return { content: [{ type: "text", text: result }], isError: false, }; } export async function handleCalendarDeleteEvent( args: any, googleCalendarInstance: GoogleCalendar ) { if (!isDeleteEventArgs(args)) { throw new Error("Invalid arguments for google_calendar_delete_event"); } const { eventId, calendarId } = args; const result = await googleCalendarInstance.deleteEvent(eventId, calendarId); return { content: [{ type: "text", text: result }], isError: false, }; } 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, }; }

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