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

123 lines (105 loc) 3.1 kB
/** * Contact folders functionality */ const { callGraphAPI } = require('../utils/graph-api'); const { ensureAuthenticated } = require('../auth'); /** * List contact folders handler * @param {object} args - Tool arguments * @returns {object} - MCP response */ async function handleListContactFolders(args) { try { // Ensure user is authenticated const accessToken = await ensureAuthenticated(); // Build the API path const apiPath = 'me/contactFolders'; // Build query parameters const queryParams = { '$select': 'id,displayName,parentFolderId,childFolderCount,totalItemCount', '$orderby': 'displayName asc' }; console.error('Fetching contact folders'); // Make API call const response = await callGraphAPI(accessToken, 'GET', apiPath, null, queryParams); const folders = response.value || []; return { content: [ { type: "text", text: `Found ${folders.length} contact folders:\n\n${folders.map(folder => { return `📁 ${folder.displayName} ID: ${folder.id} Items: ${folder.totalItemCount || 0} Child Folders: ${folder.childFolderCount || 0} ${folder.parentFolderId ? `Parent: ${folder.parentFolderId}` : 'Root folder'}`; }).join('\n\n')}` } ] }; } catch (error) { console.error('Error in handleListContactFolders:', error); return { error: { code: -32603, message: `Failed to list contact folders: ${error.message}` } }; } } /** * Create contact folder handler * @param {object} args - Tool arguments * @returns {object} - MCP response */ async function handleCreateContactFolder(args) { try { const { displayName, parentFolderId } = args; if (!displayName) { return { error: { code: -32602, message: "displayName is required" } }; } // Ensure user is authenticated const accessToken = await ensureAuthenticated(); // Build the folder object const folderData = { displayName }; // Build the API path let apiPath = 'me/contactFolders'; if (parentFolderId) { apiPath = `me/contactFolders/${parentFolderId}/childFolders`; } console.error(`Creating contact folder: ${displayName}`); // Make API call const newFolder = await callGraphAPI(accessToken, 'POST', apiPath, folderData); return { content: [ { type: "text", text: `✅ Contact folder created successfully! **Name:** ${newFolder.displayName} **Folder ID:** ${newFolder.id} **Parent:** ${newFolder.parentFolderId || 'Root'} The contact folder has been created and is ready to use.` } ] }; } catch (error) { console.error('Error in handleCreateContactFolder:', error); return { error: { code: -32603, message: `Failed to create contact folder: ${error.message}` } }; } } module.exports = { handleListContactFolders, handleCreateContactFolder };