ms365-mcp-server 1.0.0 → 1.0.2

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/README.md CHANGED
@@ -1,27 +1,25 @@
1
1
  # ✉️ Microsoft 365 MCP Server
2
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**.
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 with **production-ready security**.
6
4
 
7
5
  ## ✨ Key Features
8
6
 
9
7
  - **Complete Microsoft 365 integration** with OAuth2 security via Azure MSAL
10
8
  - **Intuitive email management** - send, read, search, and organize emails
11
9
  - **Smart email search** with advanced filtering and criteria support
12
- - **Email organization** with read/unread marking and folder management
13
10
  - **File attachment support** - send and receive attachments seamlessly
14
- - **Multi-user support** for teams and shared environments
11
+ - **Enhanced security** with simplified single-user authentication model
15
12
  - **Contact management** - retrieve and search your contact directory
16
- - **Secure authentication** with local token storage and automatic refresh
13
+ - **Secure authentication** with OS keychain storage and automatic refresh
17
14
  - **Cross-platform compatibility** (macOS, Linux, Windows)
18
15
 
19
16
  ## 🛠️ Tools & Capabilities
20
17
 
21
- ### 📧 Core Email Operations (11 tools)
18
+ ### 📧 Core Email Operations (12 tools)
22
19
  - **`send_email`** - Send emails with attachments, HTML/text content, CC/BCC
23
20
  - **`read_email`** - Read full email content including headers and attachments
24
21
  - **`search_emails`** - Advanced search with filtering and date ranges
22
+ - **`search_emails_to_me`** - Find emails addressed to YOU (both TO and CC fields)
25
23
  - **`list_emails`** - List emails in inbox, sent, or custom folders
26
24
  - **`get_attachment`** - Download and retrieve email attachments
27
25
  - **`mark_email`** - Mark emails as read or unread
@@ -31,84 +29,24 @@ This project provides an **MCP (Model Context Protocol) server** that enables **
31
29
  - **`get_contacts`** - Retrieve contact list from Microsoft 365
32
30
  - **`search_contacts`** - Search contacts by name or email address
33
31
 
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
32
+ ### 🔐 Authentication Tools (6 tools)
33
+ - **`authenticate_with_device_code`** - Complete authentication in MCP (RECOMMENDED)
34
+ - **`device_code_login`** - Start device code authentication flow
35
+ - **`check_pending_auth`** - Check for pending device code authentication
39
36
  - **`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
37
+ - **`logout`** - Clear authentication tokens and reset session
38
+ - **`get_device_code`** - Get device code info for manual authentication
39
+
40
+ **Total: 18 tools** (12 email operations + 6 authentication tools)
103
41
 
104
42
  ## 🚀 Quick Start
105
43
 
106
44
  ### Installation
107
45
  ```bash
108
- # Global installation (recommended)
46
+ # Global installation
109
47
  npm install -g ms365-mcp-server
110
48
 
111
- # Quick device code authentication (no Azure app needed!)
49
+ # Authenticate (no Azure app registration needed!)
112
50
  ms365-mcp-server --login
113
51
 
114
52
  # Start the server
@@ -129,353 +67,153 @@ Add to your `claude_desktop_config.json`:
129
67
  }
130
68
  ```
131
69
 
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
- ```
70
+ ## 🔐 Authentication
138
71
 
139
- **Option 2: Interactive Setup**
72
+ ### Simple Setup (Recommended)
140
73
  ```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)
74
+ # One-command authentication - no Azure registration required!
174
75
  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
76
  ```
206
77
 
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
78
+ ### MCP Authentication Flow
79
+ 1. **Call**: `authenticate_with_device_code`
80
+ 2. **Get**: Device code and URL in the response
81
+ 3. **Visit**: https://microsoft.com/devicelogin
82
+ 4. **Enter**: The provided device code
83
+ 5. **Call**: `authenticate_with_device_code` again
84
+ 6. **Done**: ✅ Authenticated and ready!
215
85
 
216
- # Set up authentication
217
- node dist/index.js --setup-auth
218
-
219
- # Start server
220
- node dist/index.js
221
- ```
86
+ ### Advanced Setup (Custom Azure App)
87
+ For advanced users who want custom Azure app configuration:
222
88
 
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
89
  ```bash
261
90
  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
91
+ # Follow prompts for custom client ID/secret
288
92
  ```
289
93
 
290
94
  ## 📖 Usage Examples
291
95
 
292
- ### Sending Emails
96
+ ### Email Operations
293
97
  ```javascript
98
+ // Send an email with attachment
294
99
  {
295
100
  "tool": "send_email",
296
101
  "arguments": {
297
102
  "to": ["colleague@company.com"],
298
103
  "subject": "Project Update",
299
- "body": "<h2>Status Report</h2><p>The project is <b>on track</b>!</p>",
104
+ "body": "<h2>Status Report</h2><p>Project is on track!</p>",
300
105
  "bodyType": "html",
301
- "importance": "high",
302
106
  "attachments": [{
303
107
  "name": "report.pdf",
304
- "contentBytes": "base64_encoded_content",
305
- "contentType": "application/pdf"
108
+ "contentBytes": "base64_encoded_content"
306
109
  }]
307
110
  }
308
111
  }
309
- ```
310
112
 
311
- ### Advanced Email Search
312
- ```javascript
113
+ // Search emails with advanced criteria
313
114
  {
314
- "tool": "search_emails",
115
+ "tool": "search_emails",
315
116
  "arguments": {
316
117
  "from": "boss@company.com",
317
118
  "after": "2024-01-01",
318
- "hasAttachment": true,
319
- "isUnread": true,
320
- "maxResults": 20
119
+ "hasAttachment": true
321
120
  }
322
121
  }
323
- ```
324
122
 
325
- ### Contact Search
326
- ```javascript
123
+ // Find all emails addressed to YOU (both TO and CC)
327
124
  {
328
- "tool": "search_contacts",
125
+ "tool": "search_emails_to_me",
329
126
  "arguments": {
330
- "query": "John Smith",
331
- "maxResults": 10
127
+ "from": "important-sender@company.com",
128
+ "isUnread": true,
129
+ "after": "2024-01-01"
332
130
  }
333
131
  }
132
+
133
+ // Check authentication
134
+ {
135
+ "tool": "verify_authentication",
136
+ "arguments": {}
137
+ }
334
138
  ```
335
139
 
336
- ## 🎯 Command Line Options
140
+ ### 🔍 Email Search Options
337
141
 
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
142
+ - **`search_emails`** - General search with manual recipient specification
143
+ - Requires you to specify email addresses in `to` or `cc` fields
144
+ - More flexible for searching any recipient combinations
145
+ - Example: `{"to": "someone@company.com", "from": "boss@company.com"}`
346
146
 
347
- ## 🔒 Security & Privacy
147
+ - **`search_emails_to_me`** - Automatic search for emails addressed to YOU
148
+ - Automatically uses your email address for both TO and CC searches
149
+ - Finds ALL emails where you are a recipient (direct or CC'd)
150
+ - No need to specify your email address manually
151
+ - Example: `{"from": "boss@company.com", "isUnread": true}`
348
152
 
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
153
+ ## 🎯 Command Line Options
354
154
 
355
- ## 📊 Logging & Debugging
155
+ - `--login` - Authenticate using device code flow (recommended)
156
+ - `--logout` - Clear stored authentication tokens
157
+ - `--verify-login` - Check current authentication status
158
+ - `--setup-auth` - Interactive credential setup
159
+ - `--reset-auth` - Clear all stored authentication data
160
+ - `--debug` - Enable detailed debug logging
356
161
 
357
- Debug logs are written to: `/tmp/ms365-mcp-server.log`
162
+ ## 🛡️ Security Features
358
163
 
359
- Enable debug mode:
360
- ```bash
361
- ms365-mcp-server --debug
362
- ```
164
+ - **Device Code Authentication** - No browser auto-open, manual code entry
165
+ - **OS Keychain Integration** - Secure token storage with encrypted fallback
166
+ - **Single-User Model** - Simplified security, no account enumeration
167
+ - **Privacy Protection** - Users see only their own information
168
+ - **OAuth2 Compliance** - Microsoft MSAL library with automatic refresh
169
+ - **Local Processing** - No data transmitted to third-party servers
363
170
 
364
171
  ## 🚨 Troubleshooting
365
172
 
366
173
  ### Common Issues
367
174
 
368
175
  **"MS365 credentials not configured"**
369
- - Set environment variables or run `--setup-auth`
370
- - Ensure credentials file exists at correct path
176
+ ```bash
177
+ ms365-mcp-server --login
178
+ ```
371
179
 
372
- **"Access blocked" during OAuth**
373
- - Verify your app has required Microsoft Graph permissions
374
- - Ensure redirect URI matches Azure app registration
180
+ **Device code authentication issues**
181
+ ```bash
182
+ ms365-mcp-server --verify-login # Check status
183
+ ms365-mcp-server --logout # Reset if needed
184
+ ms365-mcp-server --login # Re-authenticate
185
+ ```
375
186
 
376
187
  **Authentication timeout**
188
+ - Device codes expire in 15 minutes
377
189
  - Use `--reset-auth` to clear old tokens
378
- - Check that redirect URI matches Azure app settings
379
190
 
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
191
+ ### Debug Logs
385
192
  ```bash
386
- ms365-mcp-server --reset-auth
193
+ ms365-mcp-server --debug
194
+ # Logs written to: /tmp/ms365-mcp-server.log
387
195
  ```
388
196
 
389
197
  ## 🔧 Development
390
198
 
391
- ### Local Development
392
199
  ```bash
200
+ # Local development
393
201
  npm run dev
394
- ```
395
202
 
396
- ### Build Project
397
- ```bash
203
+ # Build project
398
204
  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
205
 
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
206
+ # Version management
207
+ npm run version-bump [patch|minor|major]
411
208
  ```
412
209
 
413
210
  ## 🧠 Perfect for AI Assistants
414
211
 
415
- - **Claude Desktop integration** - Add Microsoft 365 to your Claude conversations
416
- - **Personal email assistant** - Let AI help manage your inbox intelligently
212
+ - **Claude Desktop integration** - Add Microsoft 365 to Claude conversations
417
213
  - **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**.
214
+ - **Inbox management** - Let AI help organize and respond to emails
215
+ - **Email analysis** - Extract insights and patterns from email data
216
+ - **Customer support** - Streamline email-based interactions
479
217
 
480
218
  ## 📝 License
481
219
 
@@ -483,15 +221,10 @@ MIT License - see LICENSE file for details.
483
221
 
484
222
  ## 🤝 Contributing
485
223
 
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
224
+ Contributions welcome! Please feel free to submit a Pull Request.
494
225
 
495
226
  ---
496
227
 
497
- **Built with ❤️ for the AI and productivity community**
228
+ **Built with 🔒 Security and ❤️ for the AI community**
229
+
230
+ *Production-ready Microsoft 365 integration for Claude Desktop and MCP applications*