@softeria/ms-365-mcp-server 0.176.1 → 0.177.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/README.md +41 -0
- package/SECURITY.md +9 -0
- package/dist/app-mode.js +137 -0
- package/dist/auth.js +66 -12
- package/dist/cli.js +10 -1
- package/dist/endpoints.json +250 -41
- package/dist/graph-client.js +8 -2
- package/dist/graph-tools.js +32 -24
- package/dist/index.js +18 -3
- package/dist/mcp-instructions.js +4 -0
- package/dist/server.js +3 -1
- package/package.json +1 -1
- package/src/endpoints.json +250 -41
package/dist/graph-client.js
CHANGED
|
@@ -259,7 +259,7 @@ class GraphClient {
|
|
|
259
259
|
const errorText = await response.text();
|
|
260
260
|
if (errorText.includes("scope") || errorText.includes("permission")) {
|
|
261
261
|
throw new Error(
|
|
262
|
-
`Microsoft Graph API scope error: ${response.status} ${response.statusText} - ${errorText}.
|
|
262
|
+
`Microsoft Graph API scope error: ${response.status} ${response.statusText} - ${errorText}. ${this.scopeErrorHint()}`
|
|
263
263
|
);
|
|
264
264
|
}
|
|
265
265
|
throw new Error(
|
|
@@ -327,13 +327,19 @@ class GraphClient {
|
|
|
327
327
|
}
|
|
328
328
|
}
|
|
329
329
|
}
|
|
330
|
+
scopeErrorHint() {
|
|
331
|
+
if (this.authManager.isAppMode?.()) {
|
|
332
|
+
return "Grant one of these as an application permission to your app registration (with admin consent), or for mail and calendars through Exchange RBAC for Applications.";
|
|
333
|
+
}
|
|
334
|
+
return "This tool requires organization mode. Please restart with --org-mode flag.";
|
|
335
|
+
}
|
|
330
336
|
async createGraphApiError(response) {
|
|
331
337
|
const errorText = await response.text();
|
|
332
338
|
const graphErrorCode = extractGraphErrorCode(errorText);
|
|
333
339
|
const isPermissionOrScopeError = errorText.includes("scope") || errorText.includes("permission");
|
|
334
340
|
if (response.status === 403 && isPermissionOrScopeError) {
|
|
335
341
|
return new GraphApiError(
|
|
336
|
-
`Microsoft Graph API scope error: ${response.status} ${response.statusText} - ${errorText}.
|
|
342
|
+
`Microsoft Graph API scope error: ${response.status} ${response.statusText} - ${errorText}. ${this.scopeErrorHint()}`,
|
|
337
343
|
response.status,
|
|
338
344
|
graphErrorCode
|
|
339
345
|
);
|
package/dist/graph-tools.js
CHANGED
|
@@ -10,7 +10,9 @@ import { deriveTargetResource } from "./audit-target-resource.js";
|
|
|
10
10
|
import {
|
|
11
11
|
getEndpointScopeGroups,
|
|
12
12
|
getMissingAllowedScopesForGroups,
|
|
13
|
-
|
|
13
|
+
isEndpointInScopeMode,
|
|
14
|
+
parseAllowedScopes,
|
|
15
|
+
scopeModeFor
|
|
14
16
|
} from "./auth.js";
|
|
15
17
|
import { api as betaApi } from "./generated/client-beta.js";
|
|
16
18
|
import { api } from "./generated/client.js";
|
|
@@ -521,6 +523,13 @@ async function executeUtilityTool(utility, ctx, params) {
|
|
|
521
523
|
throw error;
|
|
522
524
|
}
|
|
523
525
|
}
|
|
526
|
+
function isUtilityToolAvailable(utility, options) {
|
|
527
|
+
if (options.readOnly && !utility.readOnlyHint) return false;
|
|
528
|
+
if (options.httpMode && utility.stdioOnly) return false;
|
|
529
|
+
if (options.scopeMode === "app" && utility.meOnly) return false;
|
|
530
|
+
if (utility.enabled && !utility.enabled()) return false;
|
|
531
|
+
return true;
|
|
532
|
+
}
|
|
524
533
|
function formatDisabledToolsForLog(disabledTools) {
|
|
525
534
|
const shown = disabledTools.slice(0, 20).map((tool) => `${tool.toolName} (missing: ${tool.missingScopes.join(", ")})`);
|
|
526
535
|
const suffix = disabledTools.length > shown.length ? `, ... +${disabledTools.length - shown.length} more` : "";
|
|
@@ -539,7 +548,7 @@ function collectDeniedToolPolicies(options) {
|
|
|
539
548
|
const allowedScopes = parseAllowedScopes(options.allowedScopesValue);
|
|
540
549
|
for (const tool of allEndpoints) {
|
|
541
550
|
const endpointConfig = endpointsData.find((e) => e.toolName === tool.alias);
|
|
542
|
-
if (!
|
|
551
|
+
if (!isEndpointInScopeMode(endpointConfig, options.scopeMode)) {
|
|
543
552
|
continue;
|
|
544
553
|
}
|
|
545
554
|
const method = tool.method.toUpperCase();
|
|
@@ -554,7 +563,7 @@ function collectDeniedToolPolicies(options) {
|
|
|
554
563
|
continue;
|
|
555
564
|
}
|
|
556
565
|
const missingScopes = allowedScopes !== void 0 && !endpointConfig ? ["endpoint scope metadata"] : getMissingAllowedScopesForGroups(
|
|
557
|
-
getEndpointScopeGroups(endpointConfig, options.
|
|
566
|
+
getEndpointScopeGroups(endpointConfig, options.scopeMode),
|
|
558
567
|
allowedScopes
|
|
559
568
|
);
|
|
560
569
|
if (missingScopes.length > 0) {
|
|
@@ -565,9 +574,7 @@ function collectDeniedToolPolicies(options) {
|
|
|
565
574
|
}
|
|
566
575
|
}
|
|
567
576
|
for (const utility of UTILITY_TOOLS) {
|
|
568
|
-
if (
|
|
569
|
-
if (options.httpMode && utility.stdioOnly) continue;
|
|
570
|
-
if (utility.enabled && !utility.enabled()) continue;
|
|
577
|
+
if (!isUtilityToolAvailable(utility, options)) continue;
|
|
571
578
|
if (options.enabledToolsRegex && !options.enabledToolsRegex.test(utility.name)) {
|
|
572
579
|
deniedTools.set(utility.name, {
|
|
573
580
|
toolName: utility.name,
|
|
@@ -624,7 +631,7 @@ const UPLOAD_CONTENT_ID_ERROR = 'contentId may hold letters, digits, ".", "_", "
|
|
|
624
631
|
const contentIdSchema = z.string().optional().describe(
|
|
625
632
|
'Attach inline under this Content-ID instead of as a regular attachment, so the HTML body can show the file with <img src="cid:<contentId>">, e.g. a picture in an email signature. Letters, digits, ".", "_", "@", "-".'
|
|
626
633
|
);
|
|
627
|
-
const UPLOAD_TARGET_ERROR = "target must be the attachments collection of a draft message or an event: /me/messages/{message-id}/attachments or /me/events/{event-id}/attachments.";
|
|
634
|
+
const UPLOAD_TARGET_ERROR = "target must be the attachments collection of a draft message or an event: /me/messages/{message-id}/attachments or /me/events/{event-id}/attachments (or /users/{user-id}/... for another mailbox).";
|
|
628
635
|
function uploadError(message) {
|
|
629
636
|
return { content: [{ type: "text", text: JSON.stringify({ error: message }) }], isError: true };
|
|
630
637
|
}
|
|
@@ -786,7 +793,7 @@ const UTILITY_TOOLS = [
|
|
|
786
793
|
buildSchema: (ctx) => {
|
|
787
794
|
const schema = {
|
|
788
795
|
target: z.string().describe(
|
|
789
|
-
"Attachments collection of a draft message or an event, e.g. /me/messages/{message-id}/attachments
|
|
796
|
+
"Attachments collection of a draft message or an event, e.g. /me/messages/{message-id}/attachments, /me/events/{event-id}/attachments, or /users/{user-id}/messages/{message-id}/attachments for another mailbox."
|
|
790
797
|
),
|
|
791
798
|
name: z.string().describe("Attachment file name as the recipient will see it, e.g. report.pdf"),
|
|
792
799
|
contentType: z.string().optional().describe(
|
|
@@ -834,7 +841,7 @@ const UTILITY_TOOLS = [
|
|
|
834
841
|
buildSchema: (ctx) => {
|
|
835
842
|
const schema = {
|
|
836
843
|
target: z.string().describe(
|
|
837
|
-
"Attachments collection of a draft message or an event, e.g. /me/messages/{message-id}/attachments
|
|
844
|
+
"Attachments collection of a draft message or an event, e.g. /me/messages/{message-id}/attachments, /me/events/{event-id}/attachments, or /users/{user-id}/messages/{message-id}/attachments for another mailbox."
|
|
838
845
|
),
|
|
839
846
|
filePath: z.string().describe(
|
|
840
847
|
"Absolute path of the file on the server's filesystem, e.g. /Users/me/documents/invitation.pdf. Must be inside a directory the server allows uploads from."
|
|
@@ -969,6 +976,7 @@ const UTILITY_TOOLS = [
|
|
|
969
976
|
},
|
|
970
977
|
{
|
|
971
978
|
name: "read-mail-text",
|
|
979
|
+
meOnly: true,
|
|
972
980
|
method: "GET",
|
|
973
981
|
path: "tool:read-mail-text",
|
|
974
982
|
searchKeywords: "triage inbox skim many emails at once without quoted history signature footer tracking links",
|
|
@@ -2405,6 +2413,7 @@ function registerGraphTools(server, graphClient, options = {}) {
|
|
|
2405
2413
|
readOnly = false,
|
|
2406
2414
|
enabledTools: enabledToolsPattern,
|
|
2407
2415
|
orgMode = false,
|
|
2416
|
+
appMode = false,
|
|
2408
2417
|
authManager,
|
|
2409
2418
|
multiAccount = false,
|
|
2410
2419
|
accountNames = [],
|
|
@@ -2427,17 +2436,18 @@ function registerGraphTools(server, graphClient, options = {}) {
|
|
|
2427
2436
|
let failedCount = 0;
|
|
2428
2437
|
const allowedScopes = parseAllowedScopes(allowedScopesValue);
|
|
2429
2438
|
const disabledByAllowedScopes = [];
|
|
2439
|
+
const scopeMode = scopeModeFor({ orgMode, appMode });
|
|
2430
2440
|
const deniedTools = collectDeniedToolPolicies({
|
|
2431
2441
|
readOnly,
|
|
2432
|
-
|
|
2442
|
+
scopeMode,
|
|
2433
2443
|
enabledToolsRegex,
|
|
2434
2444
|
allowedScopesValue,
|
|
2435
2445
|
httpMode
|
|
2436
2446
|
});
|
|
2437
2447
|
for (const tool of allEndpoints) {
|
|
2438
2448
|
const endpointConfig = endpointsData.find((e) => e.toolName === tool.alias);
|
|
2439
|
-
if (!
|
|
2440
|
-
logger.info(`Skipping
|
|
2449
|
+
if (!isEndpointInScopeMode(endpointConfig, scopeMode)) {
|
|
2450
|
+
logger.info(`Skipping tool ${tool.alias} - not available in ${scopeMode} mode`);
|
|
2441
2451
|
skippedCount++;
|
|
2442
2452
|
continue;
|
|
2443
2453
|
}
|
|
@@ -2455,7 +2465,7 @@ function registerGraphTools(server, graphClient, options = {}) {
|
|
|
2455
2465
|
continue;
|
|
2456
2466
|
}
|
|
2457
2467
|
const missingScopes = allowedScopes !== void 0 && !endpointConfig ? ["endpoint scope metadata"] : getMissingAllowedScopesForGroups(
|
|
2458
|
-
getEndpointScopeGroups(endpointConfig,
|
|
2468
|
+
getEndpointScopeGroups(endpointConfig, scopeMode),
|
|
2459
2469
|
allowedScopes
|
|
2460
2470
|
);
|
|
2461
2471
|
if (missingScopes.length > 0) {
|
|
@@ -2487,9 +2497,7 @@ function registerGraphTools(server, graphClient, options = {}) {
|
|
|
2487
2497
|
userFields
|
|
2488
2498
|
};
|
|
2489
2499
|
for (const utility of UTILITY_TOOLS) {
|
|
2490
|
-
if (readOnly
|
|
2491
|
-
if (httpMode && utility.stdioOnly) continue;
|
|
2492
|
-
if (utility.enabled && !utility.enabled()) continue;
|
|
2500
|
+
if (!isUtilityToolAvailable(utility, { readOnly, httpMode, scopeMode })) continue;
|
|
2493
2501
|
if (enabledToolsRegex && !enabledToolsRegex.test(utility.name)) continue;
|
|
2494
2502
|
try {
|
|
2495
2503
|
registerUtilityToolWithMcp(server, utility, utilityCtx);
|
|
@@ -2505,12 +2513,12 @@ function registerGraphTools(server, graphClient, options = {}) {
|
|
|
2505
2513
|
installDeniedToolAuditHandler(server, deniedTools);
|
|
2506
2514
|
return registeredCount;
|
|
2507
2515
|
}
|
|
2508
|
-
function buildToolsRegistry(readOnly,
|
|
2516
|
+
function buildToolsRegistry(readOnly, mode, enabledToolsRegex, allowedScopesValue, disabledByAllowedScopes = []) {
|
|
2509
2517
|
const toolsMap = /* @__PURE__ */ new Map();
|
|
2510
2518
|
const allowedScopes = parseAllowedScopes(allowedScopesValue);
|
|
2511
2519
|
for (const tool of allEndpoints) {
|
|
2512
2520
|
const endpointConfig = endpointsData.find((e) => e.toolName === tool.alias);
|
|
2513
|
-
if (!
|
|
2521
|
+
if (!isEndpointInScopeMode(endpointConfig, mode)) {
|
|
2514
2522
|
continue;
|
|
2515
2523
|
}
|
|
2516
2524
|
const method = tool.method.toUpperCase();
|
|
@@ -2523,7 +2531,7 @@ function buildToolsRegistry(readOnly, orgMode, enabledToolsRegex, allowedScopesV
|
|
|
2523
2531
|
continue;
|
|
2524
2532
|
}
|
|
2525
2533
|
const missingScopes = allowedScopes !== void 0 && !endpointConfig ? ["endpoint scope metadata"] : getMissingAllowedScopesForGroups(
|
|
2526
|
-
getEndpointScopeGroups(endpointConfig,
|
|
2534
|
+
getEndpointScopeGroups(endpointConfig, mode),
|
|
2527
2535
|
allowedScopes
|
|
2528
2536
|
);
|
|
2529
2537
|
if (missingScopes.length > 0) {
|
|
@@ -2619,6 +2627,7 @@ function registerDiscoveryTools(server, graphClient, options = {}) {
|
|
|
2619
2627
|
readOnly = false,
|
|
2620
2628
|
enabledTools,
|
|
2621
2629
|
orgMode = false,
|
|
2630
|
+
appMode = false,
|
|
2622
2631
|
authManager,
|
|
2623
2632
|
multiAccount = false,
|
|
2624
2633
|
accountNames = [],
|
|
@@ -2641,16 +2650,17 @@ function registerDiscoveryTools(server, graphClient, options = {}) {
|
|
|
2641
2650
|
}
|
|
2642
2651
|
}
|
|
2643
2652
|
const disabledByAllowedScopes = [];
|
|
2653
|
+
const scopeMode = scopeModeFor({ orgMode, appMode });
|
|
2644
2654
|
const deniedTools = collectDeniedToolPolicies({
|
|
2645
2655
|
readOnly,
|
|
2646
|
-
|
|
2656
|
+
scopeMode,
|
|
2647
2657
|
enabledToolsRegex,
|
|
2648
2658
|
allowedScopesValue,
|
|
2649
2659
|
httpMode
|
|
2650
2660
|
});
|
|
2651
2661
|
const toolsRegistry = buildToolsRegistry(
|
|
2652
2662
|
readOnly,
|
|
2653
|
-
|
|
2663
|
+
scopeMode,
|
|
2654
2664
|
enabledToolsRegex,
|
|
2655
2665
|
allowedScopesValue,
|
|
2656
2666
|
disabledByAllowedScopes
|
|
@@ -2661,9 +2671,7 @@ function registerDiscoveryTools(server, graphClient, options = {}) {
|
|
|
2661
2671
|
);
|
|
2662
2672
|
}
|
|
2663
2673
|
const utilityTools = UTILITY_TOOLS.filter((u) => {
|
|
2664
|
-
if (readOnly
|
|
2665
|
-
if (httpMode && u.stdioOnly) return false;
|
|
2666
|
-
if (u.enabled && !u.enabled()) return false;
|
|
2674
|
+
if (!isUtilityToolAvailable(u, { readOnly, httpMode, scopeMode })) return false;
|
|
2667
2675
|
if (enabledToolsRegex && !enabledToolsRegex.test(u.name)) return false;
|
|
2668
2676
|
return true;
|
|
2669
2677
|
});
|
package/dist/index.js
CHANGED
|
@@ -12,6 +12,8 @@ import {
|
|
|
12
12
|
import { createTokenCacheStorage } from "./token-cache-storage.js";
|
|
13
13
|
import { dumpError, getActiveResources } from "./crash-logging.js";
|
|
14
14
|
import { version } from "./version.js";
|
|
15
|
+
import { APP_MODE_WARNING, assertAppModeOptions } from "./app-mode.js";
|
|
16
|
+
import { buildToolsRegistry } from "./graph-tools.js";
|
|
15
17
|
process.on("unhandledRejection", (reason) => {
|
|
16
18
|
const dump = {
|
|
17
19
|
kind: "unhandledRejection",
|
|
@@ -35,6 +37,9 @@ async function main() {
|
|
|
35
37
|
try {
|
|
36
38
|
loadEnvFile();
|
|
37
39
|
const args = parseArgs();
|
|
40
|
+
if (args.appMode) {
|
|
41
|
+
assertAppModeOptions(args);
|
|
42
|
+
}
|
|
38
43
|
const includeWorkScopes = args.orgMode || false;
|
|
39
44
|
if (includeWorkScopes) {
|
|
40
45
|
logger.info("Organization mode enabled - including work account scopes");
|
|
@@ -43,7 +48,7 @@ async function main() {
|
|
|
43
48
|
const effectiveScopes = resolveAuthScopes(args);
|
|
44
49
|
if (args.listPermissions) {
|
|
45
50
|
const diagnostics = buildAllowedScopeDiagnostics(args);
|
|
46
|
-
const mode = includeWorkScopes ? "org" : "personal";
|
|
51
|
+
const mode = args.appMode ? "app" : includeWorkScopes ? "org" : "personal";
|
|
47
52
|
const filter = args.enabledTools ? args.enabledTools : void 0;
|
|
48
53
|
if (diagnostics.disabledTools.length > 0) {
|
|
49
54
|
console.error(
|
|
@@ -64,7 +69,17 @@ async function main() {
|
|
|
64
69
|
);
|
|
65
70
|
process.exit(0);
|
|
66
71
|
}
|
|
67
|
-
|
|
72
|
+
if (args.appMode) {
|
|
73
|
+
logger.warn(APP_MODE_WARNING);
|
|
74
|
+
console.error(APP_MODE_WARNING);
|
|
75
|
+
const filter = args.enabledTools ? new RegExp(args.enabledTools, "i") : void 0;
|
|
76
|
+
if (buildToolsRegistry(Boolean(args.readOnly), "app", filter, args.allowedScopes).size === 0) {
|
|
77
|
+
const empty = "Warning: no Microsoft Graph tools are left in app mode with these filters. App mode only has the /users/{user-id}, directory, files, sites and Teams tools (see --preset work).";
|
|
78
|
+
logger.warn(empty);
|
|
79
|
+
console.error(empty);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const useLocalAuthStorage = !args.appMode && shouldUseLocalAuthStorage(args);
|
|
68
83
|
const storage = await createTokenCacheStorage({
|
|
69
84
|
allowCommandStorage: useLocalAuthStorage,
|
|
70
85
|
logProvider: useLocalAuthStorage
|
|
@@ -75,7 +90,7 @@ async function main() {
|
|
|
75
90
|
expectedUsername: args.expectedUsername,
|
|
76
91
|
expectedHomeAccountId: args.expectedHomeAccountId
|
|
77
92
|
},
|
|
78
|
-
{ storage }
|
|
93
|
+
{ storage, appMode: args.appMode }
|
|
79
94
|
);
|
|
80
95
|
if (useLocalAuthStorage) {
|
|
81
96
|
await authManager.loadTokenCache();
|
package/dist/mcp-instructions.js
CHANGED
|
@@ -8,6 +8,10 @@ function buildGeneralMcpInstructions(opts) {
|
|
|
8
8
|
"Teams chat and channel messages: prefer HTML contentType in the body; plain text is often mangled by Graph.",
|
|
9
9
|
"Files / binary content: for large drive/SharePoint file content, prefer get-download-url to resolve a pre-authenticated URL for out-of-band download. Use download-bytes for authenticated byte reads such as mail attachments, profile photos, Teams hosted content, and meeting recordings. In stdio mode (or HTTP with --http-local-file-tools), download-bytes-to-file writes those same authenticated bytes straight to a local absolute path instead of returning base64. For large mail attachments and meeting recordings that is one out-of-band option; get-download-url is the other, on a server running with --enable-attachment-urls. These tools take relative Microsoft Graph paths, not absolute URLs. For uploads, upload-file-content takes a base64 string body (Graph allows 250MB, but the whole string passes through the agent context and a truncated one is written without error); use create-upload-session for anything but small files."
|
|
10
10
|
];
|
|
11
|
+
if (opts.appMode)
|
|
12
|
+
parts.push(
|
|
13
|
+
"App mode: there is no signed-in user, so /me paths do not work. Name the user in /users/{user-id} paths with a UPN or object id."
|
|
14
|
+
);
|
|
11
15
|
if (opts.readOnly) parts.push("This server is read-only; write operations are disabled.");
|
|
12
16
|
if (opts.multiAccount)
|
|
13
17
|
parts.push("Multiple accounts: pass the account parameter when required (see list-accounts).");
|
package/dist/server.js
CHANGED
|
@@ -192,12 +192,13 @@ class MicrosoftGraphServer {
|
|
|
192
192
|
discovery: Boolean(this.options.discovery),
|
|
193
193
|
eagerTools: this.options.eagerTools,
|
|
194
194
|
orgMode: Boolean(this.options.orgMode),
|
|
195
|
+
appMode: Boolean(this.options.appMode),
|
|
195
196
|
readOnly: Boolean(this.options.readOnly),
|
|
196
197
|
multiAccount: this.multiAccount
|
|
197
198
|
})
|
|
198
199
|
}
|
|
199
200
|
);
|
|
200
|
-
const shouldRegisterAuthTools = !this.options.http || this.options.enableAuthTools;
|
|
201
|
+
const shouldRegisterAuthTools = !this.options.appMode && (!this.options.http || this.options.enableAuthTools);
|
|
201
202
|
if (shouldRegisterAuthTools) {
|
|
202
203
|
registerAuthTools(server, this.authManager);
|
|
203
204
|
}
|
|
@@ -207,6 +208,7 @@ class MicrosoftGraphServer {
|
|
|
207
208
|
onUnavailableEagerTool: this.reportUnavailableEagerTool,
|
|
208
209
|
enabledTools: this.options.enabledTools,
|
|
209
210
|
orgMode: this.options.orgMode,
|
|
211
|
+
appMode: this.options.appMode,
|
|
210
212
|
authManager: this.authManager,
|
|
211
213
|
multiAccount: this.multiAccount,
|
|
212
214
|
accountNames: this.accountNames,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@softeria/ms-365-mcp-server",
|
|
3
3
|
"mcpName": "io.github.Softeria/ms-365-mcp-server",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.177.0",
|
|
5
5
|
"description": " A Model Context Protocol (MCP) server for interacting with Microsoft 365 and Office services through the Graph API",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/index.js",
|