calendar_get_upcoming_events
Retrieve upcoming calendar events within a specified date range to help users view and manage their schedule.
Instructions
Get upcoming events in date range
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| days | No | Number of days ahead to look (default: 7) |
Implementation Reference
- src/index.ts:266-277 (registration)Registration of the calendar_get_upcoming_events tool, including name, description, and input schema definition.name: 'calendar_get_upcoming_events', description: 'Get upcoming events in date range', inputSchema: { type: 'object', properties: { days: { type: 'number', description: 'Number of days ahead to look (default: 7)', }, }, }, },
- src/index.ts:1630-1697 (handler)The handler for calendar_get_upcoming_events executes an AppleScript command via execAsync to retrieve upcoming calendar events within the specified number of days (default 7), formats the output, and returns it as text content.case 'calendar_get_upcoming_events': try { const days = (args?.days as number) || 7; const command = `osascript -e 'on run argv set numDays to (item 1 of argv) as number tell application "Calendar" set upcomingEvents to {} set startDate to (current date) set endDate to startDate + (numDays * 24 * 60 * 60) repeat with aCal in calendars set calName to title of aCal repeat with anEvent in events of aCal set eventStart to start date of anEvent if eventStart ≥ startDate and eventStart ≤ endDate then set eventSummary to summary of anEvent set eventTime to (eventStart as string) set end of upcomingEvents to (eventSummary & " (" & calName & ") - " & eventTime) end if end repeat end repeat return upcomingEvents as string end tell end run' -- ${days}`; const { stdout, stderr } = await execAsync(command); if (stderr.trim()) { return { content: [ { type: 'text', text: `Error getting upcoming events: ${stderr.trim()}`, }, ], }; } const output = stdout.trim(); if (!output || output === '') { return { content: [ { type: 'text', text: `No events scheduled in the next ${days} days`, }, ], }; } return { content: [ { type: 'text', text: `Upcoming Events (next ${days} days):\n${output}`, }, ], }; } catch (error: any) { return { content: [ { type: 'text', text: `Error executing upcoming events command: ${error.message}`, }, ], }; }