create-event-with-attendees
Schedule Microsoft Outlook calendar events with attendees by defining subject, body, start/end times, time zone, location, and attendee details using Microsoft Graph API.
Instructions
Create a calendar event with attendees using Microsoft Graph API
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| attendees | Yes | List of attendees for the event | |
| body | Yes | Content/body of the calendar event | |
| end | No | End time in ISO format (e.g. 2025-04-20T13:00:00). Defaults to next business day at 1PM | |
| location | No | Location of the event | |
| start | No | Start time in ISO format (e.g. 2025-04-20T12:00:00). Defaults to next business day at noon | |
| subject | Yes | Subject of the calendar event | |
| timeZone | No | Time zone for the event. Defaults to GMT Standard Time |
Implementation Reference
- src/tools/event-create.ts:115-207 (handler)The main handler function for the 'create-event-with-attendees' tool. It handles authentication, computes default times, formats attendees, constructs the Microsoft Graph Event object, calls the Graph API to create the event, and formats the response.async ({ subject, body, start, end, timeZone = "GMT Standard Time", location, attendees }) => { const { graph, userEmail, authError } = await getGraphConfig(); if (authError) { return { content: [{ type: "text", text: `🔐 Authentication Required\n\n${authError}\n\nPlease complete the authentication and try again.` }] }; } // Calculate default times if not provided const nextDay: string = format(addBusinessDays(new Date(), 1), 'yyyy-MM-dd'); const startTime: string = start ? start : `${nextDay}T12:00:00`; const endTime: string = end ? end : `${nextDay}T13:00:00`; // Format attendees for the event const formattedAttendees: Attendee[] = attendees.map((attendee: any) => ({ emailAddress: { address: attendee.email, name: attendee.name || attendee.email }, type: attendee.type || "required" })); // Create the event object const event: Event = { subject, body: { contentType: "html", content: `${body}<br/>Request submitted around ${format(new Date(), 'dd-MMM-yyyy HH:mm')}` }, start: { dateTime: startTime, timeZone }, end: { dateTime: endTime, timeZone }, attendees: formattedAttendees }; // Add location if provided if (location) { event.location = { displayName: location }; } // Call the Graph API to create the event const result = await graph.createEvent(event, userEmail); if (!result) { return { content: [ { type: "text", text: "Failed to create calendar event. Check the logs for details.", }, ], }; } // Format the result for response const eventUrl = result.webLink || "No event URL available"; const eventId = result.id || "No event ID available"; const successMessage = ` Calendar event created successfully! Subject: ${subject} Start: ${startTime} End: ${endTime} Time Zone: ${timeZone} ${location ? `Location: ${location}\n ` : ''}User: ${userEmail} Attendees: ${formattedAttendees.map(a => { const name = a.emailAddress?.name || 'No name'; const email = a.emailAddress?.address || 'No email'; const type = a.type || 'required'; return `${name} (${email}) - ${type}`; }).join("\n ")} Event ID: ${eventId} Event URL: ${eventUrl} `; return { content: [ { type: "text", text: successMessage, }, ], }; }
- src/tools/event-create.ts:100-114 (schema)Zod input schema defining parameters for creating an event with attendees: subject, body, start/end times, timezone, location, and list of attendees.{ subject: z.string().describe("Subject of the calendar event"), body: z.string().describe("Content/body of the calendar event"), start: z.string().optional().describe("Start time in ISO format (e.g. 2025-04-20T12:00:00). Defaults to next business day at noon"), end: z.string().optional().describe("End time in ISO format (e.g. 2025-04-20T13:00:00). Defaults to next business day at 1PM"), timeZone: z.string().optional().describe("Time zone for the event. Defaults to GMT Standard Time"), location: z.string().optional().describe("Location of the event"), attendees: z.array( z.object({ email: z.string().describe("Email address of the attendee"), name: z.string().optional().describe("Name of the attendee"), type: z.enum(["required", "optional"]).optional().describe("Type of attendee: required or optional") }) ).describe("List of attendees for the event") },
- src/tools/event-create.ts:96-208 (registration)Registration of the 'create-event-with-attendees' tool using registerTool, including name, description, schema, and handler.registerTool( server, "create-event-with-attendees", "Create a calendar event with attendees using Microsoft Graph API", { subject: z.string().describe("Subject of the calendar event"), body: z.string().describe("Content/body of the calendar event"), start: z.string().optional().describe("Start time in ISO format (e.g. 2025-04-20T12:00:00). Defaults to next business day at noon"), end: z.string().optional().describe("End time in ISO format (e.g. 2025-04-20T13:00:00). Defaults to next business day at 1PM"), timeZone: z.string().optional().describe("Time zone for the event. Defaults to GMT Standard Time"), location: z.string().optional().describe("Location of the event"), attendees: z.array( z.object({ email: z.string().describe("Email address of the attendee"), name: z.string().optional().describe("Name of the attendee"), type: z.enum(["required", "optional"]).optional().describe("Type of attendee: required or optional") }) ).describe("List of attendees for the event") }, async ({ subject, body, start, end, timeZone = "GMT Standard Time", location, attendees }) => { const { graph, userEmail, authError } = await getGraphConfig(); if (authError) { return { content: [{ type: "text", text: `🔐 Authentication Required\n\n${authError}\n\nPlease complete the authentication and try again.` }] }; } // Calculate default times if not provided const nextDay: string = format(addBusinessDays(new Date(), 1), 'yyyy-MM-dd'); const startTime: string = start ? start : `${nextDay}T12:00:00`; const endTime: string = end ? end : `${nextDay}T13:00:00`; // Format attendees for the event const formattedAttendees: Attendee[] = attendees.map((attendee: any) => ({ emailAddress: { address: attendee.email, name: attendee.name || attendee.email }, type: attendee.type || "required" })); // Create the event object const event: Event = { subject, body: { contentType: "html", content: `${body}<br/>Request submitted around ${format(new Date(), 'dd-MMM-yyyy HH:mm')}` }, start: { dateTime: startTime, timeZone }, end: { dateTime: endTime, timeZone }, attendees: formattedAttendees }; // Add location if provided if (location) { event.location = { displayName: location }; } // Call the Graph API to create the event const result = await graph.createEvent(event, userEmail); if (!result) { return { content: [ { type: "text", text: "Failed to create calendar event. Check the logs for details.", }, ], }; } // Format the result for response const eventUrl = result.webLink || "No event URL available"; const eventId = result.id || "No event ID available"; const successMessage = ` Calendar event created successfully! Subject: ${subject} Start: ${startTime} End: ${endTime} Time Zone: ${timeZone} ${location ? `Location: ${location}\n ` : ''}User: ${userEmail} Attendees: ${formattedAttendees.map(a => { const name = a.emailAddress?.name || 'No name'; const email = a.emailAddress?.address || 'No email'; const type = a.type || 'required'; return `${name} (${email}) - ${type}`; }).join("\n ")} Event ID: ${eventId} Event URL: ${eventUrl} `; return { content: [ { type: "text", text: successMessage, }, ], }; } );
- src/index.ts:33-33 (registration)Top-level call to register event creation tools, which includes the 'create-event-with-attendees' tool.registerEventCreateTools(server);