UNPKG

outlook-mcp

Version:

Comprehensive MCP server for Claude to access Microsoft Outlook and Teams via Microsoft Graph API - including Email, Calendar, Contacts, Tasks, Teams, Chats, and Online Meetings

160 lines (139 loc) 4.16 kB
/** * Update event functionality */ const { callGraphAPI } = require('../utils/graph-api'); const { ensureAuthenticated } = require('../auth'); const config = require('../config'); /** * Update event handler * @param {object} args - Tool arguments * @returns {object} - MCP response */ async function handleUpdateEvent(args) { try { const { eventId, subject, start, end, location, body, attendees, isAllDay, importance, categories, calendarId } = args; if (!eventId) { return { error: { code: -32602, message: "Event ID is required" } }; } // Ensure user is authenticated const accessToken = await ensureAuthenticated(); // Build the update object (only include provided fields) const updateData = {}; if (subject !== undefined) updateData.subject = subject; if (isAllDay !== undefined) updateData.isAllDay = isAllDay; if (importance !== undefined) updateData.importance = importance; // Handle start time if (start !== undefined) { updateData.start = { dateTime: start, timeZone: config.DEFAULT_TIMEZONE }; } // Handle end time if (end !== undefined) { updateData.end = { dateTime: end, timeZone: config.DEFAULT_TIMEZONE }; } // Handle location if (location !== undefined) { updateData.location = { displayName: location }; } // Handle body if (body !== undefined) { updateData.body = { contentType: 'HTML', content: body }; } // Handle attendees if (attendees !== undefined) { updateData.attendees = Array.isArray(attendees) ? attendees.map(email => ({ emailAddress: { address: email, name: email }, type: 'required' })) : []; } // Handle categories if (categories !== undefined) { updateData.categories = Array.isArray(categories) ? categories : []; } // Ensure we have at least one field to update if (Object.keys(updateData).length === 0) { return { error: { code: -32602, message: "At least one field must be provided to update" } }; } // Build the API path let apiPath = `me/events/${eventId}`; if (calendarId) { apiPath = `me/calendars/${calendarId}/events/${eventId}`; } console.error(`Updating event: ${eventId}`); // Make API call const updatedEvent = await callGraphAPI(accessToken, 'PATCH', apiPath, updateData); // Format the response const formatDateTime = (dateObj) => { if (!dateObj) return 'Not set'; return new Date(dateObj.dateTime).toLocaleString(); }; const formatAttendees = (attendees) => { if (!attendees || attendees.length === 0) return 'None'; return attendees.map(a => a.emailAddress.name || a.emailAddress.address).join(', '); }; return { content: [ { type: "text", text: `✅ Event updated successfully! **Subject:** ${updatedEvent.subject} **Event ID:** ${updatedEvent.id} **Start:** ${formatDateTime(updatedEvent.start)} **End:** ${formatDateTime(updatedEvent.end)} **Location:** ${updatedEvent.location && updatedEvent.location.displayName ? updatedEvent.location.displayName : 'No location'} **All Day:** ${updatedEvent.isAllDay ? 'Yes' : 'No'} **Importance:** ${updatedEvent.importance || 'Normal'} **Attendees:** ${formatAttendees(updatedEvent.attendees)} **Categories:** ${updatedEvent.categories && updatedEvent.categories.length > 0 ? updatedEvent.categories.join(', ') : 'None'} The event has been updated with the provided information.` } ] }; } catch (error) { console.error('Error in handleUpdateEvent:', error); return { error: { code: -32603, message: `Failed to update event: ${error.message}` } }; } } module.exports = handleUpdateEvent;