ms365-mcp-server 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 MS365 MCP Server
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,497 @@
1
+ # ✉️ Microsoft 365 MCP Server
2
+
3
+ A powerful **Model Context Protocol (MCP) server** that enables seamless Microsoft 365 email integration through natural language interactions. Built for **Claude Desktop**, **LLMs**, and any MCP-compatible application.
4
+
5
+ This project provides an **MCP (Model Context Protocol) server** that enables **Claude Desktop** to access your **Microsoft 365 email** seamlessly. It acts as a bridge between AI models and email services by exposing mailbox capabilities through a **secure, standardized interface**.
6
+
7
+ ## ✨ Key Features
8
+
9
+ - **Complete Microsoft 365 integration** with OAuth2 security via Azure MSAL
10
+ - **Intuitive email management** - send, read, search, and organize emails
11
+ - **Smart email search** with advanced filtering and criteria support
12
+ - **Email organization** with read/unread marking and folder management
13
+ - **File attachment support** - send and receive attachments seamlessly
14
+ - **Multi-user support** for teams and shared environments
15
+ - **Contact management** - retrieve and search your contact directory
16
+ - **Secure authentication** with local token storage and automatic refresh
17
+ - **Cross-platform compatibility** (macOS, Linux, Windows)
18
+
19
+ ## 🛠️ Tools & Capabilities
20
+
21
+ ### 📧 Core Email Operations (11 tools)
22
+ - **`send_email`** - Send emails with attachments, HTML/text content, CC/BCC
23
+ - **`read_email`** - Read full email content including headers and attachments
24
+ - **`search_emails`** - Advanced search with filtering and date ranges
25
+ - **`list_emails`** - List emails in inbox, sent, or custom folders
26
+ - **`get_attachment`** - Download and retrieve email attachments
27
+ - **`mark_email`** - Mark emails as read or unread
28
+ - **`move_email`** - Move emails between folders
29
+ - **`delete_email`** - Permanently delete email messages
30
+ - **`list_folders`** - Browse all mail folders and their statistics
31
+ - **`get_contacts`** - Retrieve contact list from Microsoft 365
32
+ - **`search_contacts`** - Search contacts by name or email address
33
+
34
+ ### 🔐 Authentication Tools (10 tools)
35
+ - **`quick_authenticate`** - One-time authentication with auto browser launch (single-user mode)
36
+ - **`get_auth_link`** - Get clickable authentication link for manual control (single-user mode)
37
+ - **`device_code_login`** - Device code authentication flow (no browser auto-open)
38
+ - **`get_device_code`** - Get device code info for manual authentication
39
+ - **`verify_authentication`** - Check current authentication status
40
+ - **`list_authenticated_accounts`** - Show all authenticated accounts
41
+ - **`get_storage_info`** - Display credential storage method information
42
+ - **`logout`** - Clear authentication tokens for current user
43
+ - **`authenticate_user`** - Start authentication flow for new users (multi-user mode)
44
+ - **`get_my_session_info`** - View your own session information (multi-user mode)
45
+
46
+ **Total: 21 tools** (11 email operations + 10 authentication tools)
47
+
48
+ ## 🌟 Key Feature Highlights
49
+
50
+ ### ✅ Supported Email Features
51
+
52
+ * **Email Sending**
53
+ * Send plain text or HTML emails
54
+ * Add attachments and send in bulk
55
+ * Support for CC, BCC, and reply-to addresses
56
+ * Email importance levels (low, normal, high)
57
+
58
+ * **Email Receiving & Querying**
59
+ * List folders and retrieve email metadata
60
+ * Advanced queries: filter by sender, subject, date, or addressed recipient (To/CC)
61
+ * View full email contents with attachments
62
+ * **Filter emails addressed to you directly (in To or CC)**
63
+
64
+ * **Email Management**
65
+ * Mark emails as read/unread
66
+ * Delete or move emails between folders
67
+ * Organize emails with folder navigation
68
+
69
+ * **Attachment Handling**
70
+ * List and download attachments
71
+ * Send emails with multiple attachments
72
+ * Support for various file types
73
+
74
+ * **Contact Management**
75
+ * Retrieve contact list
76
+ * Perform smart contact searches
77
+ * Integration with Microsoft 365 address book
78
+
79
+ ### 🌟 Advanced Features
80
+
81
+ * **Advanced Search Filters**
82
+ * Multi-folder search capabilities
83
+ * Keyword, date range, sender/recipient matching
84
+ * **Identify and filter emails where the user is in To or CC**
85
+ * Attachment and importance level filtering
86
+
87
+ * **Smart Contact Intelligence**
88
+ * Automatically extract contact metadata
89
+ * Search by name, email, or company information
90
+
91
+ * **Content Range Control**
92
+ * Load large emails in parts to improve performance
93
+ * Efficient pagination for large result sets
94
+
95
+ * **Rich Email Format Support**
96
+ * Compose and display both plain text and HTML emails
97
+ * Proper MIME type handling
98
+
99
+ * **Secure and Local Processing**
100
+ * All email operations are handled **locally**
101
+ * No data is forwarded to third-party servers
102
+ * OAuth2 compliance with Azure MSAL
103
+
104
+ ## 🚀 Quick Start
105
+
106
+ ### Installation
107
+ ```bash
108
+ # Global installation (recommended)
109
+ npm install -g ms365-mcp-server
110
+
111
+ # Quick device code authentication (no Azure app needed!)
112
+ ms365-mcp-server --login
113
+
114
+ # Start the server
115
+ ms365-mcp-server
116
+ ```
117
+
118
+ ### Claude Desktop Integration
119
+ Add to your `claude_desktop_config.json`:
120
+
121
+ ```json
122
+ {
123
+ "mcpServers": {
124
+ "ms365": {
125
+ "command": "ms365-mcp-server",
126
+ "args": []
127
+ }
128
+ }
129
+ }
130
+ ```
131
+
132
+ ### First Time Authentication
133
+ **Option 1: Device Code Flow (Recommended)**
134
+ ```bash
135
+ ms365-mcp-server --login
136
+ # Follow the on-screen instructions - no Azure app registration needed!
137
+ ```
138
+
139
+ **Option 2: Interactive Setup**
140
+ ```bash
141
+ ms365-mcp-server --setup-auth
142
+ # Choose device code flow (recommended) or custom Azure app
143
+ ```
144
+
145
+ ## 🔐 **Enhanced Authentication System**
146
+
147
+ Our MS365 MCP Server features a **dual-layer authentication system** inspired by [Softeria's implementation](https://github.com/Softeria/ms-365-mcp-server) with significant enhancements:
148
+
149
+ ### **🎯 Authentication Methods**
150
+
151
+ 1. **🔥 Device Code Flow (Recommended)**
152
+ - **No Azure app registration required**
153
+ - **Built-in Microsoft app** for instant setup
154
+ - **Secure device code authentication**
155
+ - Perfect for personal use and secure environments
156
+
157
+ 2. **⚙️ Custom Azure App (Advanced)**
158
+ - **Full control** over permissions and settings
159
+ - **Redirect-based OAuth2** authentication
160
+ - **Custom tenant configuration**
161
+ - Ideal for enterprise environments
162
+
163
+ ### **🔒 Secure Credential Storage**
164
+
165
+ - **OS Keychain Integration** (macOS Keychain, Windows Credential Manager, Linux Secret Service)
166
+ - **Encrypted File Fallback** for cross-platform compatibility
167
+ - **Automatic token refresh** with MSAL library
168
+ - **Multi-account support** with isolated storage
169
+
170
+ ### **⚡ New Authentication Commands**
171
+
172
+ ```bash
173
+ # Device code authentication (easiest)
174
+ ms365-mcp-server --login
175
+
176
+ # Verify authentication status
177
+ ms365-mcp-server --verify-login
178
+
179
+ # Logout and clear tokens
180
+ ms365-mcp-server --logout
181
+
182
+ # Interactive credential setup
183
+ ms365-mcp-server --setup-auth
184
+ ```
185
+
186
+ ### **🔄 Authentication Flow Comparison**
187
+
188
+ | Feature | Device Code Flow *(Recommended)* | Redirect Flow *(Advanced)* |
189
+ |---------|----------------------------------|----------------------------|
190
+ | **Setup Required** | ❌ None (uses built-in app) | ✅ Azure app registration |
191
+ | **Callback Endpoint** | ❌ Not needed | ✅ `http://localhost:44001/oauth2callback` |
192
+ | **Port Requirements** | ❌ No ports needed | ✅ Port 44001 must be free |
193
+ | **Browser Auto-open** | ❌ Manual code entry | ✅ Automatic browser redirect |
194
+ | **Security** | 🔒 High (no local server) | 🔒 High (local callback) |
195
+ | **Enterprise Support** | ✅ Excellent | ✅ Full control |
196
+
197
+ **Most users should use Device Code Flow** - it's simpler, more secure, and requires no setup!
198
+
199
+ ## 🛠️ Installation & Setup
200
+
201
+ ### Global Installation
202
+
203
+ ```bash
204
+ npm install -g ms365-mcp-server
205
+ ```
206
+
207
+ ### Manual Installation
208
+
209
+ ```bash
210
+ # Clone and build
211
+ git clone <repository-url>
212
+ cd ms365-mcp-server
213
+ npm install
214
+ npm run build
215
+
216
+ # Set up authentication
217
+ node dist/index.js --setup-auth
218
+
219
+ # Start server
220
+ node dist/index.js
221
+ ```
222
+
223
+ ## 🔑 Authentication Setup
224
+
225
+ ### Step 1: Azure App Registration *(Optional - Only for Advanced Users)*
226
+
227
+ > **💡 Note**: Most users can skip this step! The recommended device code flow uses a built-in Microsoft app and doesn't require Azure app registration.
228
+
229
+ **Only needed if you want a custom Azure app with redirect-based authentication:**
230
+
231
+ 1. Go to [Azure Portal](https://portal.azure.com)
232
+ 2. Navigate to **Azure Active Directory** > **App registrations**
233
+ 3. Click **"New registration"**
234
+ 4. Configure your application:
235
+ - **Name**: MS365 MCP Server (or your preferred name)
236
+ - **Supported account types**: Choose appropriate option
237
+ - **Redirect URI**: `http://localhost:44001/oauth2callback` *(only needed for redirect flow)*
238
+ 5. **Grant API permissions** for Microsoft Graph:
239
+ - `Mail.ReadWrite` - Read and write access to user mail
240
+ - `Mail.Send` - Send mail as user
241
+ - `MailboxSettings.Read` - Read user mailbox settings
242
+ - `Contacts.Read` - Read user contacts
243
+ - `User.Read` - Sign in and read user profile
244
+ 6. **Create client secret** in "Certificates & secrets"
245
+ 7. Note down:
246
+ - **Application (client) ID**
247
+ - **Directory (tenant) ID**
248
+ - **Client secret value**
249
+
250
+ ### Step 2: Configure Credentials
251
+
252
+ **Method 1: Environment Variables (Recommended)**
253
+ ```bash
254
+ export MS365_CLIENT_ID="your_client_id_here"
255
+ export MS365_CLIENT_SECRET="your_client_secret_here"
256
+ export MS365_TENANT_ID="your_tenant_id_here"
257
+ ```
258
+
259
+ **Method 2: Interactive Setup**
260
+ ```bash
261
+ ms365-mcp-server --setup-auth
262
+ # Follow the prompts to enter your credentials
263
+ ```
264
+
265
+ **Method 3: Credentials File**
266
+ ```bash
267
+ # Save credentials to ~/.ms365-mcp/credentials.json
268
+ {
269
+ "clientId": "your_client_id",
270
+ "clientSecret": "your_client_secret",
271
+ "tenantId": "your_tenant_id",
272
+ "redirectUri": "http://localhost:44001/oauth2callback"
273
+ }
274
+ ```
275
+
276
+ ### Step 3: Authentication Modes
277
+
278
+ **Single-User Mode (Personal Use)**
279
+ ```bash
280
+ ms365-mcp-server
281
+ # Use quick_authenticate or get_auth_link tools
282
+ ```
283
+
284
+ **Multi-User Mode (Teams/Shared)**
285
+ ```bash
286
+ ms365-mcp-server --multi-user
287
+ # Use authenticate_user tool for each user
288
+ ```
289
+
290
+ ## 📖 Usage Examples
291
+
292
+ ### Sending Emails
293
+ ```javascript
294
+ {
295
+ "tool": "send_email",
296
+ "arguments": {
297
+ "to": ["colleague@company.com"],
298
+ "subject": "Project Update",
299
+ "body": "<h2>Status Report</h2><p>The project is <b>on track</b>!</p>",
300
+ "bodyType": "html",
301
+ "importance": "high",
302
+ "attachments": [{
303
+ "name": "report.pdf",
304
+ "contentBytes": "base64_encoded_content",
305
+ "contentType": "application/pdf"
306
+ }]
307
+ }
308
+ }
309
+ ```
310
+
311
+ ### Advanced Email Search
312
+ ```javascript
313
+ {
314
+ "tool": "search_emails",
315
+ "arguments": {
316
+ "from": "boss@company.com",
317
+ "after": "2024-01-01",
318
+ "hasAttachment": true,
319
+ "isUnread": true,
320
+ "maxResults": 20
321
+ }
322
+ }
323
+ ```
324
+
325
+ ### Contact Search
326
+ ```javascript
327
+ {
328
+ "tool": "search_contacts",
329
+ "arguments": {
330
+ "query": "John Smith",
331
+ "maxResults": 10
332
+ }
333
+ }
334
+ ```
335
+
336
+ ## 🎯 Command Line Options
337
+
338
+ - `--setup-auth` - Configure Microsoft 365 API credentials
339
+ - `--login` - Login using device code flow (recommended)
340
+ - `--logout` - Logout and clear stored authentication tokens
341
+ - `--verify-login` - Verify current authentication status
342
+ - `--reset-auth` - Clear stored authentication tokens
343
+ - `--multi-user` - Enable multi-user authentication mode
344
+ - `--debug` - Enable detailed debug logging
345
+ - `--help` - Show help information
346
+
347
+ ## 🔒 Security & Privacy
348
+
349
+ - **Local token storage** in `~/.ms365-mcp/token.json`
350
+ - **User isolation** in multi-user mode prevents cross-user data access
351
+ - **OAuth2 compliance** with Microsoft MSAL library
352
+ - **No external data transmission** - all data stays local
353
+ - **Automatic token refresh** with secure credential management
354
+
355
+ ## 📊 Logging & Debugging
356
+
357
+ Debug logs are written to: `/tmp/ms365-mcp-server.log`
358
+
359
+ Enable debug mode:
360
+ ```bash
361
+ ms365-mcp-server --debug
362
+ ```
363
+
364
+ ## 🚨 Troubleshooting
365
+
366
+ ### Common Issues
367
+
368
+ **"MS365 credentials not configured"**
369
+ - Set environment variables or run `--setup-auth`
370
+ - Ensure credentials file exists at correct path
371
+
372
+ **"Access blocked" during OAuth**
373
+ - Verify your app has required Microsoft Graph permissions
374
+ - Ensure redirect URI matches Azure app registration
375
+
376
+ **Authentication timeout**
377
+ - Use `--reset-auth` to clear old tokens
378
+ - Check that redirect URI matches Azure app settings
379
+
380
+ **Permission errors**
381
+ - Verify Microsoft Graph API permissions are granted in Azure Portal
382
+ - Ensure admin consent is provided if required
383
+
384
+ ### Reset Authentication
385
+ ```bash
386
+ ms365-mcp-server --reset-auth
387
+ ```
388
+
389
+ ## 🔧 Development
390
+
391
+ ### Local Development
392
+ ```bash
393
+ npm run dev
394
+ ```
395
+
396
+ ### Build Project
397
+ ```bash
398
+ npm run build
399
+ ```
400
+
401
+ ### Version Management
402
+ ```bash
403
+ # Bump patch version (1.0.0 → 1.0.1)
404
+ npm run version-bump
405
+
406
+ # Bump minor version (1.0.0 → 1.1.0)
407
+ npm run version-bump minor
408
+
409
+ # Bump major version (1.0.0 → 2.0.0)
410
+ npm run version-bump major
411
+ ```
412
+
413
+ ## 🧠 Perfect for AI Assistants
414
+
415
+ - **Claude Desktop integration** - Add Microsoft 365 to your Claude conversations
416
+ - **Personal email assistant** - Let AI help manage your inbox intelligently
417
+ - **Email automation** - Build smart workflows and email processing
418
+ - **Email analysis** - Extract insights and patterns from your email data
419
+ - **Customer support** - Streamline email-based customer interactions
420
+ - **Research assistance** - Query and analyze email communications
421
+ - **Email productivity** - Automate routine email tasks and responses
422
+
423
+ ## 🆚 **Enhanced Features vs Softeria's Implementation**
424
+
425
+ While inspired by [Softeria's excellent MS365 MCP server](https://github.com/Softeria/ms-365-mcp-server), our implementation focuses on **email specialization** with significant enhancements:
426
+
427
+ ### **🎯 Our Email-First Advantages**
428
+
429
+ | Feature | Our Implementation | Softeria's |
430
+ |---------|-------------------|------------|
431
+ | **Email Tools** | 11 comprehensive email tools | Basic mail operations |
432
+ | **Authentication** | Device code + Redirect flows | Device code only |
433
+ | **Storage Security** | OS Keychain + encrypted file | OS keychain fallback |
434
+ | **Multi-user Support** | ✅ Full user isolation | ❌ Single user only |
435
+ | **Email Search** | Advanced filtering & criteria | Basic search |
436
+ | **Attachment Handling** | Full send/receive support | Basic attachment support |
437
+ | **Documentation** | Comprehensive setup guides | Basic documentation |
438
+ | **CLI Features** | Rich authentication commands | Basic login/logout |
439
+
440
+ ### **🚀 Unique Email Features**
441
+
442
+ - **Advanced Email Filtering**: Filter by date ranges, attachments, importance, read status
443
+ - **Multi-folder Search**: Search across all mailbox folders simultaneously
444
+ - **Email Organization**: Move emails between folders, mark read/unread status
445
+ - **Contact Integration**: Full contact search and management
446
+ - **Professional Email Composition**: HTML/text emails with attachments and CC/BCC
447
+ - **Seamless Claude Integration**: Purpose-built for AI email assistance
448
+
449
+ ### **🔄 Migration from Softeria**
450
+
451
+ If you're currently using Softeria's server and want **enhanced email capabilities**:
452
+
453
+ ```bash
454
+ # Install our server
455
+ npm install -g ms365-mcp-server
456
+
457
+ # Quick authentication (uses built-in app like Softeria)
458
+ ms365-mcp-server --login
459
+
460
+ # Update Claude Desktop config
461
+ {
462
+ "mcpServers": {
463
+ "ms365": {
464
+ "command": "ms365-mcp-server",
465
+ "args": []
466
+ }
467
+ }
468
+ }
469
+ ```
470
+
471
+ **Why Choose Our Implementation?**
472
+ - **Email-specialized tools** for comprehensive mailbox management
473
+ - **Multi-user support** for teams and shared environments
474
+ - **Enhanced security** with OS keychain + encrypted file fallback
475
+ - **Professional documentation** and troubleshooting guides
476
+ - **Active development** focused on email productivity
477
+
478
+ Both implementations are excellent - choose ours for **deep email functionality** or Softeria's for **broad Microsoft 365 integration**.
479
+
480
+ ## 📝 License
481
+
482
+ MIT License - see LICENSE file for details.
483
+
484
+ ## 🤝 Contributing
485
+
486
+ Contributions are welcome! Please feel free to submit a Pull Request.
487
+
488
+ ## 📞 Support
489
+
490
+ For issues and questions:
491
+ - Check the troubleshooting section above
492
+ - Review debug logs in `/tmp/ms365-mcp-server.log`
493
+ - Open an issue on the project repository
494
+
495
+ ---
496
+
497
+ **Built with ❤️ for the AI and productivity community**