UNPKG

@softeria/ms-365-mcp-server

Version:

A Model Context Protocol (MCP) server for interacting with Microsoft 365 and Office services through the Graph API

107 lines (106 loc) 2.92 kB
import { readFileSync } from "fs"; import { fileURLToPath } from "url"; import path from "path"; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const endpointEntries = JSON.parse( readFileSync(path.join(__dirname, "endpoints.json"), "utf8") ); const PRESET_META = { mail: { description: "Email operations (read, send, manage folders, attachments)" }, calendar: { description: "Calendar and event management" }, files: { description: "OneDrive file and folder operations" }, personal: { description: "Personal productivity tools (mail, calendar, files, contacts, tasks, notes, search)" }, work: { description: "Organization/work tools (Teams, SharePoint, shared mailboxes, search)", requiresOrgMode: true }, excel: { description: "Excel spreadsheet operations" }, contacts: { description: "Outlook contacts management" }, tasks: { description: "Task and planning tools (To Do, Planner)" }, onenote: { description: "OneNote notebook operations" }, search: { description: "Microsoft Search capabilities" }, users: { description: "User directory access", requiresOrgMode: true }, outlook: { description: "Outlook app only: mail, calendar and contacts" }, onedrive: { description: "OneDrive app only: drive and file operations, excluding Excel" }, teams: { description: "Teams app only: chats, channels, meetings and presence", requiresOrgMode: true } }; function presetPattern(preset) { const names = [ ...new Set(endpointEntries.filter((e) => e.presets?.includes(preset)).map((e) => e.toolName)) ]; if (names.length === 0) { throw new Error(`Preset "${preset}" matches no endpoints in endpoints.json`); } return new RegExp(`^(?:${names.join("|")})$`); } const TOOL_CATEGORIES = { ...Object.fromEntries( Object.entries(PRESET_META).map(([name, meta]) => [ name, { name, pattern: presetPattern(name), ...meta } ]) ), all: { name: "all", pattern: /.*/, description: "All available tools" } }; function getCombinedPresetPattern(presets) { const patterns = presets.map((preset) => { const category = TOOL_CATEGORIES[preset]; if (!category) { throw new Error( `Unknown preset: ${preset}. Available presets: ${Object.keys(TOOL_CATEGORIES).join(", ")}` ); } return category.pattern.source; }); return patterns.join("|"); } function listPresets() { return Object.values(TOOL_CATEGORIES).map((category) => ({ name: category.name, description: category.description, requiresOrgMode: category.requiresOrgMode })); } function presetRequiresOrgMode(preset) { const category = TOOL_CATEGORIES[preset]; return category?.requiresOrgMode || false; } export { TOOL_CATEGORIES, getCombinedPresetPattern, listPresets, presetRequiresOrgMode };