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

83 lines (69 loc) 2.06 kB
/** * Delete contact functionality */ const { callGraphAPI } = require('../utils/graph-api'); const { ensureAuthenticated } = require('../auth'); /** * Delete contact handler * @param {object} args - Tool arguments * @returns {object} - MCP response */ async function handleDeleteContact(args) { try { const { id } = args; if (!id) { return { error: { code: -32602, message: "Contact ID is required" } }; } // Ensure user is authenticated const accessToken = await ensureAuthenticated(); // First, get the contact details for confirmation const contactPath = `me/contacts/${id}`; let contactName = 'Unknown'; try { const contact = await callGraphAPI(accessToken, 'GET', contactPath, null, { '$select': 'displayName' }); contactName = contact.displayName || 'Unknown'; } catch (error) { // If we can't get the contact, it might not exist console.error('Could not retrieve contact for deletion:', error); } // Build the API path const apiPath = `me/contacts/${id}`; console.error(`Deleting contact: ${id} (${contactName})`); // Make API call to delete the contact await callGraphAPI(accessToken, 'DELETE', apiPath); return { content: [ { type: "text", text: `✅ Contact deleted successfully! **Contact:** ${contactName} **Contact ID:** ${id} The contact has been permanently removed from your contacts.` } ] }; } catch (error) { console.error('Error in handleDeleteContact:', error); // Handle specific error cases if (error.message.includes('404') || error.message.includes('Not Found')) { return { error: { code: -32603, message: `Contact not found: ${id}` } }; } return { error: { code: -32603, message: `Failed to delete contact: ${error.message}` } }; } } module.exports = handleDeleteContact;