create-event
Schedule Microsoft Outlook calendar events with defined subject, body, start, end times, and time zone using the Microsoft Graph API for efficient meeting management.
Instructions
Create a calendar event using Microsoft Graph API
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| 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 | |
| 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:24-92 (handler)Executes the core logic for creating a calendar event: handles authentication, default times, Graph API call, and response formatting.async ({ subject, body, start, end, timeZone = "GMT Standard Time" }) => { 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`; // 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 } }; // 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} User: ${userEmail} Event ID: ${eventId} Event URL: ${eventUrl} `; return { content: [ { type: "text", text: successMessage, }, ], }; }
- src/tools/event-create.ts:17-23 (schema)Zod input schema defining parameters for the create-event tool.{ 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"), },
- src/tools/event-create.ts:13-93 (registration)Registers the 'create-event' tool on the MCP server using the registerTool helper, including schema and handler.registerTool( server, "create-event", "Create a calendar event 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"), }, async ({ subject, body, start, end, timeZone = "GMT Standard Time" }) => { 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`; // 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 } }; // 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} User: ${userEmail} Event ID: ${eventId} Event URL: ${eventUrl} `; return { content: [ { type: "text", text: successMessage, }, ], }; } );
- src/index.ts:33-33 (registration)Top-level invocation of registerEventCreateTools during server setup, which in turn registers the create-event tool.registerEventCreateTools(server);
- src/utils/tool-registration.ts:8-39 (helper)Helper utility that registers tools on the MCP server with standardized logging and error handling wrapping.export function registerTool( server: McpServer, name: string, description: string, params: any, handler: (args: any) => Promise<any> ): void { server.tool( name, description, params, async (args: any) => { // Common logging pattern for all tools logger.info(`ℹ️ Executing ${name} tool with params: ${JSON.stringify(args)}`); try { // Call the actual handler function return await handler(args); } catch (error) { logger.error(`Error in ${name}:`, error); return { content: [ { type: "text", text: `Error: ${error instanceof Error ? error.message : 'Unknown error'}` } ] }; } } ); }