outlook-mcp/calendar/create.js
Seton Carmichael 68a64461eb fix(outlook-mcp): P0 audit fixes
- Handle empty 2xx Graph API responses without JSON parse errors
- Fix list-rules handler import (handleListRules named export)
- Add timezone-aware display formatting using MS_TIMEZONE / DEFAULT_TIMEZONE
- Return created event ID in create-event success message
- Change default timezone from Windows name to IANA (America/New_York)
2026-06-21 20:28:11 -04:00

69 lines
No EOL
1.8 KiB
JavaScript

/**
* Create event functionality
*/
const { callGraphAPI } = require('../utils/graph-api');
const { ensureAuthenticated } = require('../auth');
const config = require('../config');
/**
* Create event handler
* @param {object} args - Tool arguments
* @returns {object} - MCP response
*/
async function handleCreateEvent(args) {
const { subject, start, end, attendees, body } = args;
if (!subject || !start || !end) {
return {
content: [{
type: "text",
text: "Subject, start, and end times are required to create an event."
}]
};
}
try {
// Get access token
const accessToken = await ensureAuthenticated();
// Build API endpoint
const endpoint = `me/events`;
// Request body
const bodyContent = {
subject,
start: { dateTime: start, timeZone: config.DEFAULT_TIMEZONE },
end: { dateTime: end, timeZone: config.DEFAULT_TIMEZONE },
attendees: attendees?.map(email => ({ emailAddress: { address: email }, type: "required" })),
body: { contentType: "HTML", content: body || "" }
};
// Make API call
const response = await callGraphAPI(accessToken, 'POST', endpoint, bodyContent);
return {
content: [{
type: "text",
text: `Event '${subject}' has been successfully created. ID: ${response.id || '(not returned)'}`
}]
};
} catch (error) {
if (error.message === 'Authentication required') {
return {
content: [{
type: "text",
text: "Authentication required. Please use the 'authenticate' tool first."
}]
};
}
return {
content: [{
type: "text",
text: `Error creating event: ${error.message}`
}]
};
}
}
module.exports = handleCreateEvent;