MCP server providing Microsoft Outlook integration via Graph API: - Email: list, search, read, send, thread reconstruction - Calendar: list, create, decline, cancel, delete events - Folders: list, create, move emails - Inbox rules: list, create, reorder - MSAL device code flow auth with persistent token cache - Test mode with mock data - Comprehensive README with setup, config, and tool reference 20 MCP tools across 5 modules. Node.js >= 14. MIT license.
68 lines
No EOL
1.7 KiB
JavaScript
68 lines
No EOL
1.7 KiB
JavaScript
/**
|
|
* Create event functionality
|
|
*/
|
|
const { callGraphAPI } = require('../utils/graph-api');
|
|
const { ensureAuthenticated } = require('../auth');
|
|
|
|
/**
|
|
* 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: "UTC" },
|
|
end: { dateTime: end, timeZone: "UTC" },
|
|
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; |