ms365-mcp-server 1.0.1 → 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 +89 -341
- package/dist/index.js +81 -1
- package/dist/utils/ms365-operations.js +58 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
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 with **
|
|
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
11
|
- **Enhanced security** with simplified single-user authentication model
|
|
15
12
|
- **Contact management** - retrieve and search your contact directory
|
|
@@ -18,10 +15,11 @@ This project provides an **MCP (Model Context Protocol) server** that enables **
|
|
|
18
15
|
|
|
19
16
|
## 🛠️ Tools & Capabilities
|
|
20
17
|
|
|
21
|
-
### 📧 Core Email Operations (
|
|
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,98 +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
|
-
### 🔐
|
|
35
|
-
- **`authenticate_with_device_code`** - Complete authentication in
|
|
36
|
-
- **`device_code_login`** -
|
|
32
|
+
### 🔐 Authentication Tools (6 tools)
|
|
33
|
+
- **`authenticate_with_device_code`** - Complete authentication in MCP (RECOMMENDED)
|
|
34
|
+
- **`device_code_login`** - Start device code authentication flow
|
|
37
35
|
- **`check_pending_auth`** - Check for pending device code authentication
|
|
38
|
-
- **`
|
|
39
|
-
- **`get_auth_link`** - Get authentication link without auto browser launch
|
|
40
|
-
- **`verify_authentication`** - Check current authentication status (secure)
|
|
36
|
+
- **`verify_authentication`** - Check current authentication status
|
|
41
37
|
- **`logout`** - Clear authentication tokens and reset session
|
|
38
|
+
- **`get_device_code`** - Get device code info for manual authentication
|
|
42
39
|
|
|
43
|
-
**Total: 18 tools** (
|
|
44
|
-
|
|
45
|
-
## 🌟 Key Feature Highlights
|
|
46
|
-
|
|
47
|
-
### ✅ Supported Email Features
|
|
48
|
-
|
|
49
|
-
* **Email Sending**
|
|
50
|
-
* Send plain text or HTML emails
|
|
51
|
-
* Add attachments and send in bulk
|
|
52
|
-
* Support for CC, BCC, and reply-to addresses
|
|
53
|
-
* Email importance levels (low, normal, high)
|
|
54
|
-
|
|
55
|
-
* **Email Receiving & Querying**
|
|
56
|
-
* List folders and retrieve email metadata
|
|
57
|
-
* Advanced queries: filter by sender, subject, date, or addressed recipient (To/CC)
|
|
58
|
-
* View full email contents with attachments
|
|
59
|
-
* **Filter emails addressed to you directly (in To or CC)**
|
|
60
|
-
|
|
61
|
-
* **Email Management**
|
|
62
|
-
* Mark emails as read/unread
|
|
63
|
-
* Delete or move emails between folders
|
|
64
|
-
* Organize emails with folder navigation
|
|
65
|
-
|
|
66
|
-
* **Attachment Handling**
|
|
67
|
-
* List and download attachments
|
|
68
|
-
* Send emails with multiple attachments
|
|
69
|
-
* Support for various file types
|
|
70
|
-
|
|
71
|
-
* **Contact Management**
|
|
72
|
-
* Retrieve contact list
|
|
73
|
-
* Perform smart contact searches
|
|
74
|
-
* Integration with Microsoft 365 address book
|
|
75
|
-
|
|
76
|
-
### 🛡️ Enhanced Security Features
|
|
77
|
-
|
|
78
|
-
* **Simplified Authentication Model**
|
|
79
|
-
* Single-user authentication for better security
|
|
80
|
-
* No account enumeration or information disclosure
|
|
81
|
-
* Secure credential storage with OS keychain integration
|
|
82
|
-
|
|
83
|
-
* **Privacy Protection**
|
|
84
|
-
* No sensitive system information exposed
|
|
85
|
-
* User can only see their own authentication status
|
|
86
|
-
* Secure token management with automatic refresh
|
|
87
|
-
|
|
88
|
-
* **Device Code Authentication**
|
|
89
|
-
* No browser auto-open for better security control
|
|
90
|
-
* Manual code entry prevents unauthorized access
|
|
91
|
-
* Built-in Microsoft app requires no Azure registration
|
|
92
|
-
|
|
93
|
-
### 🌟 Advanced Features
|
|
94
|
-
|
|
95
|
-
* **Advanced Search Filters**
|
|
96
|
-
* Multi-folder search capabilities
|
|
97
|
-
* Keyword, date range, sender/recipient matching
|
|
98
|
-
* **Identify and filter emails where the user is in To or CC**
|
|
99
|
-
* Attachment and importance level filtering
|
|
100
|
-
|
|
101
|
-
* **Smart Contact Intelligence**
|
|
102
|
-
* Automatically extract contact metadata
|
|
103
|
-
* Search by name, email, or company information
|
|
104
|
-
|
|
105
|
-
* **Content Range Control**
|
|
106
|
-
* Load large emails in parts to improve performance
|
|
107
|
-
* Efficient pagination for large result sets
|
|
108
|
-
|
|
109
|
-
* **Rich Email Format Support**
|
|
110
|
-
* Compose and display both plain text and HTML emails
|
|
111
|
-
* Proper MIME type handling
|
|
112
|
-
|
|
113
|
-
* **Secure and Local Processing**
|
|
114
|
-
* All email operations are handled **locally**
|
|
115
|
-
* No data is forwarded to third-party servers
|
|
116
|
-
* OAuth2 compliance with Azure MSAL
|
|
40
|
+
**Total: 18 tools** (12 email operations + 6 authentication tools)
|
|
117
41
|
|
|
118
42
|
## 🚀 Quick Start
|
|
119
43
|
|
|
120
44
|
### Installation
|
|
121
45
|
```bash
|
|
122
|
-
# Global installation
|
|
46
|
+
# Global installation
|
|
123
47
|
npm install -g ms365-mcp-server
|
|
124
48
|
|
|
125
|
-
#
|
|
49
|
+
# Authenticate (no Azure app registration needed!)
|
|
126
50
|
ms365-mcp-server --login
|
|
127
51
|
|
|
128
52
|
# Start the server
|
|
@@ -143,324 +67,153 @@ Add to your `claude_desktop_config.json`:
|
|
|
143
67
|
}
|
|
144
68
|
```
|
|
145
69
|
|
|
146
|
-
|
|
147
|
-
**Device Code Flow (Recommended & Secure)**
|
|
148
|
-
```bash
|
|
149
|
-
ms365-mcp-server --login
|
|
150
|
-
# Follow the on-screen instructions - no Azure app registration needed!
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
**Interactive Setup (Advanced)**
|
|
154
|
-
```bash
|
|
155
|
-
ms365-mcp-server --setup-auth
|
|
156
|
-
# Choose device code flow (recommended) or custom Azure app
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
## 🔐 **Enhanced Security & Authentication**
|
|
160
|
-
|
|
161
|
-
Our MS365 MCP Server features a **security-first authentication system** with simplified single-user model:
|
|
162
|
-
|
|
163
|
-
### **🔒 Security Improvements**
|
|
164
|
-
|
|
165
|
-
- **🚫 No Account Enumeration**: Removed tools that could expose user lists
|
|
166
|
-
- **🚫 No System Information Disclosure**: Hidden sensitive storage details
|
|
167
|
-
- **🚫 No Multi-User Complexity**: Simplified to single-user for better security
|
|
168
|
-
- **✅ Secure Credential Storage**: OS Keychain with encrypted file fallback
|
|
169
|
-
- **✅ Privacy Protection**: Users can only see their own information
|
|
170
|
-
- **✅ Token Security**: Automatic refresh with secure MSAL library
|
|
171
|
-
|
|
172
|
-
### **🎯 Secure Authentication Flow**
|
|
173
|
-
|
|
174
|
-
1. **🔥 Device Code Flow (Recommended)**
|
|
175
|
-
- **No Azure app registration required**
|
|
176
|
-
- **Built-in Microsoft app** for instant setup
|
|
177
|
-
- **Manual code entry** prevents unauthorized access
|
|
178
|
-
- **No local server** required (more secure)
|
|
179
|
-
|
|
180
|
-
2. **⚙️ Custom Azure App (Advanced)**
|
|
181
|
-
- **Full control** over permissions and settings
|
|
182
|
-
- **Redirect-based OAuth2** authentication
|
|
183
|
-
- **Custom tenant configuration**
|
|
184
|
-
- Requires Azure app registration
|
|
185
|
-
|
|
186
|
-
### **⚡ Secure Authentication Commands**
|
|
70
|
+
## 🔐 Authentication
|
|
187
71
|
|
|
72
|
+
### Simple Setup (Recommended)
|
|
188
73
|
```bash
|
|
189
|
-
#
|
|
74
|
+
# One-command authentication - no Azure registration required!
|
|
190
75
|
ms365-mcp-server --login
|
|
191
|
-
|
|
192
|
-
# Verify your authentication status
|
|
193
|
-
ms365-mcp-server --verify-login
|
|
194
|
-
|
|
195
|
-
# Secure logout and clear tokens
|
|
196
|
-
ms365-mcp-server --logout
|
|
197
|
-
|
|
198
|
-
# Interactive credential setup
|
|
199
|
-
ms365-mcp-server --setup-auth
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
### **🔄 Authentication Flow**
|
|
203
|
-
|
|
204
|
-
| Feature | Device Code Flow *(Recommended)* | Redirect Flow *(Advanced)* |
|
|
205
|
-
|---------|----------------------------------|----------------------------|
|
|
206
|
-
| **Setup Required** | ❌ None (uses built-in app) | ✅ Azure app registration |
|
|
207
|
-
| **Security** | 🔒 High (no local server) | 🔒 High (local callback) |
|
|
208
|
-
| **Privacy** | 🔒 Manual code entry | 🔒 Browser auto-open |
|
|
209
|
-
| **Ease of Use** | ✅ Simple setup | ⚙️ Advanced configuration |
|
|
210
|
-
|
|
211
|
-
**Most users should use Device Code Flow** - it's simpler, more secure, and requires no setup!
|
|
212
|
-
|
|
213
|
-
## 🛠️ Installation & Setup
|
|
214
|
-
|
|
215
|
-
### Global Installation
|
|
216
|
-
|
|
217
|
-
```bash
|
|
218
|
-
npm install -g ms365-mcp-server
|
|
219
|
-
```
|
|
220
|
-
|
|
221
|
-
### Manual Installation
|
|
222
|
-
|
|
223
|
-
```bash
|
|
224
|
-
# Clone and build
|
|
225
|
-
git clone <repository-url>
|
|
226
|
-
cd ms365-mcp-server
|
|
227
|
-
npm install
|
|
228
|
-
npm run build
|
|
229
|
-
|
|
230
|
-
# Set up authentication
|
|
231
|
-
node dist/index.js --setup-auth
|
|
232
|
-
|
|
233
|
-
# Start server
|
|
234
|
-
node dist/index.js
|
|
235
76
|
```
|
|
236
77
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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!
|
|
240
85
|
|
|
241
|
-
|
|
86
|
+
### Advanced Setup (Custom Azure App)
|
|
87
|
+
For advanced users who want custom Azure app configuration:
|
|
242
88
|
|
|
243
|
-
```bash
|
|
244
|
-
# One-command authentication
|
|
245
|
-
ms365-mcp-server --login
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
This uses a built-in Microsoft app with device code flow - **no Azure registration needed!**
|
|
249
|
-
|
|
250
|
-
### Step 2: Advanced Setup (Custom Azure App)
|
|
251
|
-
|
|
252
|
-
> **💡 Note**: Only needed for advanced users who want custom Azure app configuration.
|
|
253
|
-
|
|
254
|
-
1. Go to [Azure Portal](https://portal.azure.com)
|
|
255
|
-
2. Navigate to **Azure Active Directory** > **App registrations**
|
|
256
|
-
3. Click **"New registration"**
|
|
257
|
-
4. Configure your application:
|
|
258
|
-
- **Name**: MS365 MCP Server (or your preferred name)
|
|
259
|
-
- **Supported account types**: Choose appropriate option
|
|
260
|
-
- **Redirect URI**: `http://localhost:44001/oauth2callback` *(only for redirect flow)*
|
|
261
|
-
5. **Grant API permissions** for Microsoft Graph:
|
|
262
|
-
- `Mail.ReadWrite` - Read and write access to user mail
|
|
263
|
-
- `Mail.Send` - Send mail as user
|
|
264
|
-
- `MailboxSettings.Read` - Read user mailbox settings
|
|
265
|
-
- `Contacts.Read` - Read user contacts
|
|
266
|
-
- `User.Read` - Sign in and read user profile
|
|
267
|
-
6. **Create client secret** in "Certificates & secrets"
|
|
268
|
-
7. Note down:
|
|
269
|
-
- **Application (client) ID**
|
|
270
|
-
- **Directory (tenant) ID**
|
|
271
|
-
- **Client secret value**
|
|
272
|
-
|
|
273
|
-
### Step 3: Configure Credentials (Advanced Only)
|
|
274
|
-
|
|
275
|
-
**Method 1: Environment Variables**
|
|
276
|
-
```bash
|
|
277
|
-
export MS365_CLIENT_ID="your_client_id_here"
|
|
278
|
-
export MS365_CLIENT_SECRET="your_client_secret_here"
|
|
279
|
-
export MS365_TENANT_ID="your_tenant_id_here"
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
**Method 2: Interactive Setup**
|
|
283
89
|
```bash
|
|
284
90
|
ms365-mcp-server --setup-auth
|
|
285
|
-
# Follow
|
|
91
|
+
# Follow prompts for custom client ID/secret
|
|
286
92
|
```
|
|
287
93
|
|
|
288
94
|
## 📖 Usage Examples
|
|
289
95
|
|
|
290
|
-
###
|
|
96
|
+
### Email Operations
|
|
291
97
|
```javascript
|
|
98
|
+
// Send an email with attachment
|
|
292
99
|
{
|
|
293
100
|
"tool": "send_email",
|
|
294
101
|
"arguments": {
|
|
295
102
|
"to": ["colleague@company.com"],
|
|
296
103
|
"subject": "Project Update",
|
|
297
|
-
"body": "<h2>Status Report</h2><p>
|
|
104
|
+
"body": "<h2>Status Report</h2><p>Project is on track!</p>",
|
|
298
105
|
"bodyType": "html",
|
|
299
|
-
"importance": "high",
|
|
300
106
|
"attachments": [{
|
|
301
107
|
"name": "report.pdf",
|
|
302
|
-
"contentBytes": "base64_encoded_content"
|
|
303
|
-
"contentType": "application/pdf"
|
|
108
|
+
"contentBytes": "base64_encoded_content"
|
|
304
109
|
}]
|
|
305
110
|
}
|
|
306
111
|
}
|
|
307
|
-
```
|
|
308
112
|
|
|
309
|
-
|
|
310
|
-
```javascript
|
|
113
|
+
// Search emails with advanced criteria
|
|
311
114
|
{
|
|
312
|
-
"tool": "search_emails",
|
|
115
|
+
"tool": "search_emails",
|
|
313
116
|
"arguments": {
|
|
314
117
|
"from": "boss@company.com",
|
|
315
118
|
"after": "2024-01-01",
|
|
316
|
-
"hasAttachment": true
|
|
317
|
-
"isUnread": true,
|
|
318
|
-
"maxResults": 20
|
|
119
|
+
"hasAttachment": true
|
|
319
120
|
}
|
|
320
121
|
}
|
|
321
|
-
```
|
|
322
122
|
|
|
323
|
-
|
|
324
|
-
```javascript
|
|
123
|
+
// Find all emails addressed to YOU (both TO and CC)
|
|
325
124
|
{
|
|
326
|
-
"tool": "
|
|
327
|
-
"arguments": {
|
|
125
|
+
"tool": "search_emails_to_me",
|
|
126
|
+
"arguments": {
|
|
127
|
+
"from": "important-sender@company.com",
|
|
128
|
+
"isUnread": true,
|
|
129
|
+
"after": "2024-01-01"
|
|
130
|
+
}
|
|
328
131
|
}
|
|
329
|
-
```
|
|
330
132
|
|
|
331
|
-
|
|
332
|
-
```javascript
|
|
133
|
+
// Check authentication
|
|
333
134
|
{
|
|
334
|
-
"tool": "
|
|
335
|
-
"arguments": {
|
|
336
|
-
"query": "John Smith",
|
|
337
|
-
"maxResults": 10
|
|
338
|
-
}
|
|
135
|
+
"tool": "verify_authentication",
|
|
136
|
+
"arguments": {}
|
|
339
137
|
}
|
|
340
138
|
```
|
|
341
139
|
|
|
342
|
-
|
|
140
|
+
### 🔍 Email Search Options
|
|
343
141
|
|
|
344
|
-
-
|
|
345
|
-
-
|
|
346
|
-
-
|
|
347
|
-
-
|
|
348
|
-
- `--reset-auth` - Clear stored authentication tokens
|
|
349
|
-
- `--debug` - Enable detailed debug logging
|
|
350
|
-
- `--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"}`
|
|
351
146
|
|
|
352
|
-
|
|
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}`
|
|
353
152
|
|
|
354
|
-
##
|
|
355
|
-
|
|
356
|
-
- **Secure token storage** with OS Keychain integration
|
|
357
|
-
- **Encrypted file fallback** for cross-platform compatibility
|
|
358
|
-
- **OAuth2 compliance** with Microsoft MSAL library
|
|
359
|
-
- **No external data transmission** - all data stays local
|
|
360
|
-
- **Automatic token refresh** with secure credential management
|
|
361
|
-
- **Privacy protection** - users can only access their own data
|
|
362
|
-
- **No information disclosure** - system details are protected
|
|
153
|
+
## 🎯 Command Line Options
|
|
363
154
|
|
|
364
|
-
|
|
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
|
|
365
161
|
|
|
366
|
-
|
|
162
|
+
## 🛡️ Security Features
|
|
367
163
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
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
|
|
372
170
|
|
|
373
171
|
## 🚨 Troubleshooting
|
|
374
172
|
|
|
375
173
|
### Common Issues
|
|
376
174
|
|
|
377
175
|
**"MS365 credentials not configured"**
|
|
378
|
-
|
|
379
|
-
-
|
|
176
|
+
```bash
|
|
177
|
+
ms365-mcp-server --login
|
|
178
|
+
```
|
|
380
179
|
|
|
381
180
|
**Device code authentication issues**
|
|
382
|
-
|
|
383
|
-
|
|
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
|
+
```
|
|
384
186
|
|
|
385
187
|
**Authentication timeout**
|
|
386
188
|
- Device codes expire in 15 minutes
|
|
387
|
-
- Use `--reset-auth` to clear old tokens
|
|
388
|
-
|
|
389
|
-
**Permission errors**
|
|
390
|
-
- Verify Microsoft Graph API permissions if using custom Azure app
|
|
391
|
-
- Device code flow handles permissions automatically
|
|
189
|
+
- Use `--reset-auth` to clear old tokens
|
|
392
190
|
|
|
393
|
-
###
|
|
191
|
+
### Debug Logs
|
|
394
192
|
```bash
|
|
395
|
-
ms365-mcp-server --
|
|
193
|
+
ms365-mcp-server --debug
|
|
194
|
+
# Logs written to: /tmp/ms365-mcp-server.log
|
|
396
195
|
```
|
|
397
196
|
|
|
398
197
|
## 🔧 Development
|
|
399
198
|
|
|
400
|
-
### Local Development
|
|
401
199
|
```bash
|
|
200
|
+
# Local development
|
|
402
201
|
npm run dev
|
|
403
|
-
```
|
|
404
202
|
|
|
405
|
-
|
|
406
|
-
```bash
|
|
203
|
+
# Build project
|
|
407
204
|
npm run build
|
|
408
|
-
```
|
|
409
|
-
|
|
410
|
-
### Version Management
|
|
411
|
-
```bash
|
|
412
|
-
# Bump patch version (1.0.0 → 1.0.1)
|
|
413
|
-
npm run version-bump
|
|
414
|
-
|
|
415
|
-
# Bump minor version (1.0.0 → 1.1.0)
|
|
416
|
-
npm run version-bump minor
|
|
417
205
|
|
|
418
|
-
#
|
|
419
|
-
npm run version-bump major
|
|
206
|
+
# Version management
|
|
207
|
+
npm run version-bump [patch|minor|major]
|
|
420
208
|
```
|
|
421
209
|
|
|
422
210
|
## 🧠 Perfect for AI Assistants
|
|
423
211
|
|
|
424
|
-
- **Claude Desktop integration** - Add Microsoft 365 to
|
|
425
|
-
- **Personal email assistant** - Let AI help manage your inbox intelligently
|
|
212
|
+
- **Claude Desktop integration** - Add Microsoft 365 to Claude conversations
|
|
426
213
|
- **Email automation** - Build smart workflows and email processing
|
|
427
|
-
- **
|
|
428
|
-
- **
|
|
429
|
-
- **
|
|
430
|
-
- **Email productivity** - Automate routine email tasks and responses
|
|
431
|
-
|
|
432
|
-
## 🆚 **Enhanced Security vs Other Implementations**
|
|
433
|
-
|
|
434
|
-
Our implementation prioritizes **security and simplicity** over feature complexity:
|
|
435
|
-
|
|
436
|
-
### **🛡️ Our Security-First Advantages**
|
|
437
|
-
|
|
438
|
-
| Feature | Our Implementation | Other Implementations |
|
|
439
|
-
|---------|-------------------|----------------------|
|
|
440
|
-
| **Account Enumeration** | 🚫 Blocked (security risk) | ✅ Often exposed |
|
|
441
|
-
| **System Information** | 🚫 Hidden (privacy protection) | ✅ Often exposed |
|
|
442
|
-
| **Multi-User Complexity** | 🚫 Simplified to single-user | ✅ Complex multi-user |
|
|
443
|
-
| **Authentication Model** | ✅ Secure device code focus | ⚠️ Various approaches |
|
|
444
|
-
| **Information Disclosure** | 🚫 Minimized | ⚠️ Often excessive |
|
|
445
|
-
| **Privacy Protection** | ✅ User sees only own data | ⚠️ Variable |
|
|
446
|
-
|
|
447
|
-
### **🚀 Security Features**
|
|
448
|
-
|
|
449
|
-
- **Privacy by Design**: Users can only access their own information
|
|
450
|
-
- **Minimal Information Disclosure**: No sensitive system details exposed
|
|
451
|
-
- **Simplified Authentication**: Single-user model reduces attack surface
|
|
452
|
-
- **Secure Token Management**: OS keychain with automatic refresh
|
|
453
|
-
- **Device Code Focus**: More secure than redirect-based flows
|
|
454
|
-
|
|
455
|
-
### **🔄 Migration Considerations**
|
|
456
|
-
|
|
457
|
-
**Enhanced Security Benefits:**
|
|
458
|
-
- **Reduced Attack Surface**: Fewer tools mean less potential vulnerabilities
|
|
459
|
-
- **Privacy Protection**: No account enumeration or system information disclosure
|
|
460
|
-
- **Simplified Model**: Single-user approach is more secure and easier to audit
|
|
461
|
-
- **Security Transparency**: Clear notices about what information is protected
|
|
462
|
-
|
|
463
|
-
Choose our implementation for **maximum security and privacy protection** in your Microsoft 365 integrations.
|
|
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
|
|
464
217
|
|
|
465
218
|
## 📝 License
|
|
466
219
|
|
|
@@ -468,15 +221,10 @@ MIT License - see LICENSE file for details.
|
|
|
468
221
|
|
|
469
222
|
## 🤝 Contributing
|
|
470
223
|
|
|
471
|
-
Contributions
|
|
472
|
-
|
|
473
|
-
## 📞 Support
|
|
474
|
-
|
|
475
|
-
For issues and questions:
|
|
476
|
-
- Check the troubleshooting section above
|
|
477
|
-
- Review debug logs in `/tmp/ms365-mcp-server.log`
|
|
478
|
-
- Open an issue on the project repository
|
|
224
|
+
Contributions welcome! Please feel free to submit a Pull Request.
|
|
479
225
|
|
|
480
226
|
---
|
|
481
227
|
|
|
482
|
-
**Built with 🔒 Security and ❤️ for the AI
|
|
228
|
+
**Built with 🔒 Security and ❤️ for the AI community**
|
|
229
|
+
|
|
230
|
+
*Production-ready Microsoft 365 integration for Claude Desktop and MCP applications*
|
package/dist/index.js
CHANGED
|
@@ -55,7 +55,7 @@ function parseArgs() {
|
|
|
55
55
|
}
|
|
56
56
|
const server = new Server({
|
|
57
57
|
name: "ms365-mcp-server",
|
|
58
|
-
version: "1.0.
|
|
58
|
+
version: "1.0.2"
|
|
59
59
|
}, {
|
|
60
60
|
capabilities: {
|
|
61
61
|
resources: {
|
|
@@ -261,6 +261,64 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
|
261
261
|
additionalProperties: false
|
|
262
262
|
}
|
|
263
263
|
},
|
|
264
|
+
{
|
|
265
|
+
name: "search_emails_to_me",
|
|
266
|
+
description: "Search for emails addressed to YOU in both TO and CC fields. This automatically finds all emails where you are a recipient (direct TO or CC'd), without needing to specify your email address.",
|
|
267
|
+
inputSchema: {
|
|
268
|
+
type: "object",
|
|
269
|
+
properties: {
|
|
270
|
+
userId: {
|
|
271
|
+
type: "string",
|
|
272
|
+
description: "User ID for multi-user authentication (required if using multi-user mode)"
|
|
273
|
+
},
|
|
274
|
+
query: {
|
|
275
|
+
type: "string",
|
|
276
|
+
description: "General search query using natural language or specific terms"
|
|
277
|
+
},
|
|
278
|
+
from: {
|
|
279
|
+
type: "string",
|
|
280
|
+
description: "Search for emails from specific sender"
|
|
281
|
+
},
|
|
282
|
+
subject: {
|
|
283
|
+
type: "string",
|
|
284
|
+
description: "Search for emails with specific subject"
|
|
285
|
+
},
|
|
286
|
+
after: {
|
|
287
|
+
type: "string",
|
|
288
|
+
description: "Search for emails after date (format: YYYY-MM-DD)"
|
|
289
|
+
},
|
|
290
|
+
before: {
|
|
291
|
+
type: "string",
|
|
292
|
+
description: "Search for emails before date (format: YYYY-MM-DD)"
|
|
293
|
+
},
|
|
294
|
+
hasAttachment: {
|
|
295
|
+
type: "boolean",
|
|
296
|
+
description: "Filter emails that have attachments"
|
|
297
|
+
},
|
|
298
|
+
folder: {
|
|
299
|
+
type: "string",
|
|
300
|
+
description: "Search within specific folder (default: inbox)"
|
|
301
|
+
},
|
|
302
|
+
isUnread: {
|
|
303
|
+
type: "boolean",
|
|
304
|
+
description: "Filter for unread emails only"
|
|
305
|
+
},
|
|
306
|
+
importance: {
|
|
307
|
+
type: "string",
|
|
308
|
+
enum: ["low", "normal", "high"],
|
|
309
|
+
description: "Filter by email importance level"
|
|
310
|
+
},
|
|
311
|
+
maxResults: {
|
|
312
|
+
type: "number",
|
|
313
|
+
description: "Maximum number of results to return (default: 50, max: 200)",
|
|
314
|
+
minimum: 1,
|
|
315
|
+
maximum: 200,
|
|
316
|
+
default: 50
|
|
317
|
+
}
|
|
318
|
+
},
|
|
319
|
+
additionalProperties: false
|
|
320
|
+
}
|
|
321
|
+
},
|
|
264
322
|
{
|
|
265
323
|
name: "list_emails",
|
|
266
324
|
description: "List emails in inbox, sent, or custom folder. Returns basic email information including subjects, senders, and snippets with support for folder navigation.",
|
|
@@ -831,6 +889,28 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
831
889
|
}
|
|
832
890
|
]
|
|
833
891
|
};
|
|
892
|
+
case "search_emails_to_me":
|
|
893
|
+
if (ms365Config.multiUser) {
|
|
894
|
+
const userId = args?.userId;
|
|
895
|
+
if (!userId) {
|
|
896
|
+
throw new Error("User ID is required in multi-user mode");
|
|
897
|
+
}
|
|
898
|
+
const graphClient = await multiUserMS365Auth.getGraphClientForUser(userId);
|
|
899
|
+
ms365Ops.setGraphClient(graphClient);
|
|
900
|
+
}
|
|
901
|
+
else {
|
|
902
|
+
const graphClient = await enhancedMS365Auth.getGraphClient();
|
|
903
|
+
ms365Ops.setGraphClient(graphClient);
|
|
904
|
+
}
|
|
905
|
+
const searchToMeResults = await ms365Ops.searchEmailsToMe(args);
|
|
906
|
+
return {
|
|
907
|
+
content: [
|
|
908
|
+
{
|
|
909
|
+
type: "text",
|
|
910
|
+
text: `🔍 Emails Addressed to You (TO & CC) - ${searchToMeResults.messages.length} found\n\n${searchToMeResults.messages.map((email, index) => `${index + 1}. 📧 ${email.subject}\n 👤 From: ${email.from.name} <${email.from.address}>\n 📅 ${new Date(email.receivedDateTime).toLocaleDateString()}\n 🆔 ID: ${email.id}\n`).join('\n')}`
|
|
911
|
+
}
|
|
912
|
+
]
|
|
913
|
+
};
|
|
834
914
|
case "list_emails":
|
|
835
915
|
if (ms365Config.multiUser) {
|
|
836
916
|
const userId = args?.userId;
|
|
@@ -389,16 +389,14 @@ export class MS365Operations {
|
|
|
389
389
|
return false;
|
|
390
390
|
}
|
|
391
391
|
if (criteria.to) {
|
|
392
|
-
const toMatch = message.toRecipients.some(recipient => recipient.address.toLowerCase()
|
|
393
|
-
recipient.name.toLowerCase().includes(criteria.to.toLowerCase()));
|
|
392
|
+
const toMatch = message.toRecipients.some(recipient => recipient.address.toLowerCase() === criteria.to.toLowerCase());
|
|
394
393
|
if (!toMatch)
|
|
395
394
|
return false;
|
|
396
395
|
}
|
|
397
396
|
if (criteria.cc) {
|
|
398
397
|
// Handle case where ccRecipients might be undefined
|
|
399
398
|
const ccMatch = message.ccRecipients && message.ccRecipients.length > 0 &&
|
|
400
|
-
message.ccRecipients.some(recipient => recipient.address.toLowerCase()
|
|
401
|
-
recipient.name.toLowerCase().includes(criteria.cc.toLowerCase()));
|
|
399
|
+
message.ccRecipients.some(recipient => recipient.address.toLowerCase() === criteria.cc.toLowerCase());
|
|
402
400
|
if (!ccMatch)
|
|
403
401
|
return false;
|
|
404
402
|
}
|
|
@@ -640,5 +638,61 @@ export class MS365Operations {
|
|
|
640
638
|
throw error;
|
|
641
639
|
}
|
|
642
640
|
}
|
|
641
|
+
/**
|
|
642
|
+
* Get current user's email address
|
|
643
|
+
*/
|
|
644
|
+
async getCurrentUserEmail() {
|
|
645
|
+
try {
|
|
646
|
+
const graphClient = await this.getGraphClient();
|
|
647
|
+
const user = await graphClient
|
|
648
|
+
.api('/me')
|
|
649
|
+
.select('mail,userPrincipalName')
|
|
650
|
+
.get();
|
|
651
|
+
return user.mail || user.userPrincipalName || '';
|
|
652
|
+
}
|
|
653
|
+
catch (error) {
|
|
654
|
+
logger.error('Error getting current user email:', error);
|
|
655
|
+
throw error;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
/**
|
|
659
|
+
* Search for emails addressed to the current user (both TO and CC recipients)
|
|
660
|
+
*/
|
|
661
|
+
async searchEmailsToMe(additionalCriteria = {}) {
|
|
662
|
+
try {
|
|
663
|
+
const userEmail = await this.getCurrentUserEmail();
|
|
664
|
+
// First search for emails where user is in TO field
|
|
665
|
+
const toCriteria = {
|
|
666
|
+
...additionalCriteria,
|
|
667
|
+
to: userEmail
|
|
668
|
+
};
|
|
669
|
+
// Then search for emails where user is in CC field
|
|
670
|
+
const ccCriteria = {
|
|
671
|
+
...additionalCriteria,
|
|
672
|
+
cc: userEmail
|
|
673
|
+
};
|
|
674
|
+
// Execute both searches in parallel
|
|
675
|
+
const [toResults, ccResults] = await Promise.all([
|
|
676
|
+
this.searchEmails(toCriteria),
|
|
677
|
+
this.searchEmails(ccCriteria)
|
|
678
|
+
]);
|
|
679
|
+
// Combine results and remove duplicates based on email ID
|
|
680
|
+
const allMessages = [...toResults.messages, ...ccResults.messages];
|
|
681
|
+
const uniqueMessages = allMessages.filter((message, index, array) => array.findIndex(m => m.id === message.id) === index);
|
|
682
|
+
// Sort by received date (newest first)
|
|
683
|
+
uniqueMessages.sort((a, b) => new Date(b.receivedDateTime).getTime() - new Date(a.receivedDateTime).getTime());
|
|
684
|
+
// Apply maxResults limit if specified
|
|
685
|
+
const maxResults = additionalCriteria.maxResults || 50;
|
|
686
|
+
const limitedMessages = uniqueMessages.slice(0, maxResults);
|
|
687
|
+
return {
|
|
688
|
+
messages: limitedMessages,
|
|
689
|
+
hasMore: uniqueMessages.length > maxResults || toResults.hasMore || ccResults.hasMore
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
catch (error) {
|
|
693
|
+
logger.error('Error searching emails addressed to me:', error);
|
|
694
|
+
throw error;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
643
697
|
}
|
|
644
698
|
export const ms365Operations = new MS365Operations();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ms365-mcp-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Microsoft 365 MCP Server for managing Microsoft 365 email through natural language interactions with full OAuth2 authentication support",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|