outlook-mcp/calendar/create.js
Seton Carmichael ba45f57b39 v1.0.1: Fix accept-event registration, edit-rule-sequence import, timezone config
Bug fixes (non-breaking):
- Register accept-event tool in calendar module (was dead code)
- Add missing callGraphAPI + ensureAuthenticated imports to rules/index.js
  (edit-rule-sequence would throw ReferenceError at runtime)
- Make calendar event timezone configurable via MS_TIMEZONE env var
  (was hardcoded to UTC; default is now Eastern Standard Time)

Version bump: 1.0.0 → 1.0.1
README updated: 21 tools, MS_TIMEZONE in config table, known issues pruned
2026-06-21 19:43:54 -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.`
}]
};
} 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;