calendar-list-calendars
Retrieve all available calendars from Google Calendar to view and manage your schedule across multiple calendars.
Instructions
List all available calendars
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| maxResults | No | Maximum number of calendars to return |
Implementation Reference
- src/calendar.ts:577-619 (handler)Main handler function that fetches the list of calendars from Google Calendar API using calendarList.list, maps the data, formats it to markdown using formatCalendarsToMarkdown, and returns structured content.export async function listCalendars( params: z.infer<ReturnType<typeof listCalendarsSchema>> ) { try { const auth = createCalendarAuth(); const calendar = google.calendar({ version: "v3", auth }); const response = await calendar.calendarList.list({ maxResults: params.maxResults, }); const calendars = response.data.items?.map((cal) => ({ id: cal.id, summary: cal.summary, description: cal.description, timeZone: cal.timeZone, accessRole: cal.accessRole, primary: cal.primary, backgroundColor: cal.backgroundColor, foregroundColor: cal.foregroundColor, })); return { content: [ { type: "text" as const, text: formatCalendarsToMarkdown(calendars || []), }, ], }; } catch (error) { return { content: [ { type: "text" as const, text: `Error listing calendars: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } }
- src/calendar.ts:235-243 (schema)Zod schema defining the input parameters for the listCalendars tool, specifically maxResults.export const listCalendarsSchema = () => z.object({ maxResults: z .number() .min(1) .max(250) .default(10) .describe("Maximum number of calendars to return"), });
- src/index.ts:260-267 (registration)Registration of the 'calendar-list-calendars' tool in the MCP server within registerCalendarTools function.server.tool( "calendar-list-calendars", "List all available calendars", listCalendarsSchema().shape, async (params) => { return await listCalendars(params); } );
- src/calendar.ts:79-95 (helper)Helper function used by the handler to format the calendars list into a readable markdown string.function formatCalendarsToMarkdown(calendars: any[]): string { if (!calendars.length) return "No calendars found."; let markdown = `# Available Calendars (${calendars.length})\n\n`; calendars.forEach((cal, index) => { markdown += `## ${index + 1}. ${cal.summary || cal.id}\n`; markdown += `ID: \`${cal.id}\` \n`; if (cal.description) markdown += `Description: ${cal.description} \n`; if (cal.timeZone) markdown += `Time Zone: ${cal.timeZone} \n`; if (cal.accessRole) markdown += `Access: ${cal.accessRole} \n`; if (cal.primary) markdown += `Primary: Yes β \n`; markdown += `\n`; }); return markdown; }