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

117 lines (98 loc) 3.59 kB
/** * Read contact functionality */ const { callGraphAPI } = require('../utils/graph-api'); const { ensureAuthenticated } = require('../auth'); const config = require('../config'); /** * Read contact handler * @param {object} args - Tool arguments * @returns {object} - MCP response */ async function handleReadContact(args) { try { const { id } = args; if (!id) { return { error: { code: -32602, message: "Contact ID is required" } }; } // Ensure user is authenticated const accessToken = await ensureAuthenticated(); // Build the API path const apiPath = `me/contacts/${id}`; // Build query parameters const queryParams = { '$select': config.CONTACTS_DETAIL_FIELDS }; console.error(`Reading contact: ${id}`); // Make API call const contact = await callGraphAPI(accessToken, 'GET', apiPath, null, queryParams); // Format the contact information const formatAddress = (address) => { if (!address) return 'Not provided'; const parts = [ address.street, address.city, address.state, address.postalCode, address.countryOrRegion ].filter(Boolean); return parts.length > 0 ? parts.join(', ') : 'Not provided'; }; const formatPhones = (phones) => { if (!phones || phones.length === 0) return 'Not provided'; return phones.join(', '); }; const formatEmails = (emails) => { if (!emails || emails.length === 0) return 'Not provided'; return emails.map(e => `${e.address} (${e.name || 'Unknown'})`).join(', '); }; const birthday = contact.birthday ? new Date(contact.birthday).toLocaleDateString() : 'Not provided'; const categories = contact.categories && contact.categories.length > 0 ? contact.categories.join(', ') : 'None'; return { content: [ { type: "text", text: `📧 Contact Details **Name:** ${contact.displayName || 'Not provided'} **Full Name:** ${[contact.givenName, contact.middleName, contact.surname].filter(Boolean).join(' ') || 'Not provided'} **Nickname:** ${contact.nickname || 'Not provided'} **Company Information:** • Company: ${contact.companyName || 'Not provided'} • Job Title: ${contact.jobTitle || 'Not provided'} • Department: ${contact.department || 'Not provided'} • Office Location: ${contact.officeLocation || 'Not provided'} **Contact Information:** • Email Addresses: ${formatEmails(contact.emailAddresses)} • Business Phones: ${formatPhones(contact.businessPhones)} • Home Phones: ${formatPhones(contact.homePhones)} • Mobile Phone: ${contact.mobilePhone || 'Not provided'} **Addresses:** • Business Address: ${formatAddress(contact.businessAddress)} • Home Address: ${formatAddress(contact.homeAddress)} **Additional Information:** • Birthday: ${birthday} • Categories: ${categories} • Personal Notes: ${contact.personalNotes || 'None'} **System Information:** • Contact ID: ${contact.id} • Created: ${contact.createdDateTime ? new Date(contact.createdDateTime).toLocaleString() : 'Not available'} • Modified: ${contact.lastModifiedDateTime ? new Date(contact.lastModifiedDateTime).toLocaleString() : 'Not available'}` } ] }; } catch (error) { console.error('Error in handleReadContact:', error); return { error: { code: -32603, message: `Failed to read contact: ${error.message}` } }; } } module.exports = handleReadContact;