@softeria/ms-365-mcp-server 0.190.5 → 0.191.1
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 +3 -3
- package/dist/__tests__/graph-tools.test.js +25 -11
- package/dist/app-mode.js +1 -0
- package/dist/auth-tools.js +47 -38
- package/dist/auth.js +19 -2
- package/dist/cli.js +1 -1
- package/dist/generated/hack.js +1 -0
- package/dist/graph-client.js +6 -1
- package/dist/graph-tools.js +91 -51
- package/dist/lib/attachment-tickets.js +1 -1
- package/dist/lib/body-schema-budget.js +27 -1
- package/dist/lib/bounded-file-transport.js +6 -1
- package/dist/lib/client-metadata.js +4 -2
- package/dist/lib/graph-resilience.js +4 -3
- package/dist/lib/microsoft-auth.js +4 -0
- package/dist/normalize-tool-schema.js +0 -38
- package/dist/obo-client.js +2 -0
- package/dist/secrets.js +1 -0
- package/dist/server.js +125 -52
- package/dist/token-cache-storage.js +4 -5
- package/docs/deployment.md +8 -0
- package/eslint.config.js +17 -0
- package/package.json +5 -3
- package/tsup.config.ts +3 -2
- package/dist/oauth-provider.js +0 -51
- package/test-calendar-fix.js +0 -62
- package/test-real-calendar.js +0 -96
|
@@ -21,11 +21,12 @@ function loadResilienceConfig() {
|
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
class CircuitOpenError extends Error {
|
|
24
|
+
code = "circuit_open";
|
|
25
|
+
cooldownMs;
|
|
24
26
|
constructor(cooldownMs) {
|
|
25
27
|
super(
|
|
26
28
|
`Graph circuit breaker is open (cooldown ${cooldownMs} ms). Upstream has failed repeatedly; refusing to flood it.`
|
|
27
29
|
);
|
|
28
|
-
this.code = "circuit_open";
|
|
29
30
|
this.name = "CircuitOpenError";
|
|
30
31
|
this.cooldownMs = cooldownMs;
|
|
31
32
|
}
|
|
@@ -36,9 +37,9 @@ class CircuitBreaker {
|
|
|
36
37
|
this.cooldownMs = cooldownMs;
|
|
37
38
|
this.disabled = disabled;
|
|
38
39
|
this.now = now;
|
|
39
|
-
this.failures = 0;
|
|
40
|
-
this.openedAt = null;
|
|
41
40
|
}
|
|
41
|
+
failures = 0;
|
|
42
|
+
openedAt = null;
|
|
42
43
|
/**
|
|
43
44
|
* @returns the time-remaining (in ms) before the circuit can be probed,
|
|
44
45
|
* or `null` if the circuit is closed and the call should proceed.
|
|
@@ -27,6 +27,7 @@ function isJwtExpired(token) {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
const DISCOVERY_METHODS = /* @__PURE__ */ new Set([
|
|
30
|
+
"server/discover",
|
|
30
31
|
"initialize",
|
|
31
32
|
"notifications/initialized",
|
|
32
33
|
"tools/list",
|
|
@@ -79,6 +80,9 @@ const microsoftBearerTokenAuthMiddleware = (opts = {}) => (req, res, next) => {
|
|
|
79
80
|
next();
|
|
80
81
|
};
|
|
81
82
|
class OAuthUpstreamError extends Error {
|
|
83
|
+
status;
|
|
84
|
+
body;
|
|
85
|
+
raw;
|
|
82
86
|
constructor(status, raw, body) {
|
|
83
87
|
const suffix = body.error_description ? ` - ${body.error_description}` : "";
|
|
84
88
|
super(`OAuth upstream error: ${body.error}${suffix}`);
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
2
1
|
import { z } from "zod";
|
|
3
|
-
import logger from "./logger.js";
|
|
4
2
|
function dropZodOnlyChecks(node) {
|
|
5
3
|
if (!node || typeof node !== "object") return;
|
|
6
4
|
if (Array.isArray(node)) {
|
|
@@ -351,43 +349,7 @@ function normalizeToolSchemaRefs(schema) {
|
|
|
351
349
|
const inlined = inlineExcept(leavesOnly);
|
|
352
350
|
return JSON.stringify(inlined).length <= limit ? inlined : hoisted;
|
|
353
351
|
}
|
|
354
|
-
function installToolSchemaRefNormalization(server) {
|
|
355
|
-
const lowLevel = server.server;
|
|
356
|
-
const handlers = lowLevel._requestHandlers;
|
|
357
|
-
const original = handlers?.get("tools/list");
|
|
358
|
-
if (!original) {
|
|
359
|
-
logger.warn("Skipping tool-schema $ref normalization: tools/list handler not found");
|
|
360
|
-
return;
|
|
361
|
-
}
|
|
362
|
-
const registered = server._registeredTools;
|
|
363
|
-
lowLevel.setRequestHandler(ListToolsRequestSchema, async (request, extra) => {
|
|
364
|
-
for (const [name, tool] of Object.entries(registered ?? {})) {
|
|
365
|
-
if (tool.inputSchema instanceof z.core.$ZodObject) useOwnConversion(name, tool.inputSchema);
|
|
366
|
-
}
|
|
367
|
-
const result = await original(request, extra);
|
|
368
|
-
for (const tool of result.tools ?? []) {
|
|
369
|
-
if (tool.inputSchema && typeof tool.inputSchema === "object") {
|
|
370
|
-
tool.inputSchema = normalizeToolSchemaRefs(tool.inputSchema);
|
|
371
|
-
tidyToolJsonSchema(tool.inputSchema);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
return result;
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
function useOwnConversion(name, schema) {
|
|
378
|
-
const internals = schema._zod;
|
|
379
|
-
if (internals.toJSONSchema) return;
|
|
380
|
-
internals.toJSONSchema = () => {
|
|
381
|
-
try {
|
|
382
|
-
return toolInputJsonSchema(schema);
|
|
383
|
-
} catch (error) {
|
|
384
|
-
logger.warn(`Could not convert the input schema of ${name}: ${error}`);
|
|
385
|
-
return void 0;
|
|
386
|
-
}
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
352
|
export {
|
|
390
|
-
installToolSchemaRefNormalization,
|
|
391
353
|
normalizeToolSchemaRefs,
|
|
392
354
|
tidyToolJsonSchema,
|
|
393
355
|
toolInputJsonSchema,
|
package/dist/obo-client.js
CHANGED
|
@@ -2,6 +2,8 @@ import { ConfidentialClientApplication } from "@azure/msal-node";
|
|
|
2
2
|
import logger from "./logger.js";
|
|
3
3
|
import { getCloudEndpoints } from "./cloud-config.js";
|
|
4
4
|
class OboClient {
|
|
5
|
+
cca;
|
|
6
|
+
graphScopes;
|
|
5
7
|
constructor(secrets) {
|
|
6
8
|
if (!secrets.clientSecret) {
|
|
7
9
|
throw new Error(
|
package/dist/secrets.js
CHANGED
package/dist/server.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import {
|
|
2
|
+
hostHeaderValidation,
|
|
3
|
+
NodeStreamableHTTPServerTransport,
|
|
4
|
+
toNodeHandler,
|
|
5
|
+
toWebRequest
|
|
6
|
+
} from "@modelcontextprotocol/node";
|
|
7
|
+
import {
|
|
8
|
+
createMcpHandler,
|
|
9
|
+
isLegacyRequest,
|
|
10
|
+
McpServer
|
|
11
|
+
} from "@modelcontextprotocol/server";
|
|
12
|
+
import { serveStdio } from "@modelcontextprotocol/server/stdio";
|
|
6
13
|
import express from "express";
|
|
7
14
|
import rateLimit from "express-rate-limit";
|
|
8
15
|
import helmet from "helmet";
|
|
@@ -48,8 +55,6 @@ import {
|
|
|
48
55
|
import logger, { enableConsoleLogging } from "./logger.js";
|
|
49
56
|
import { version } from "./version.js";
|
|
50
57
|
import { buildMcpServerInstructions } from "./mcp-instructions.js";
|
|
51
|
-
import { installToolSchemaRefNormalization } from "./normalize-tool-schema.js";
|
|
52
|
-
import { MicrosoftOAuthProvider } from "./oauth-provider.js";
|
|
53
58
|
import OboClient from "./obo-client.js";
|
|
54
59
|
import { isRejectedAssertion, oboAllowlistRefusal, readOboAllowlist } from "./lib/obo-access.js";
|
|
55
60
|
import { requestContext } from "./request-context.js";
|
|
@@ -171,28 +176,39 @@ function statelessPkceSecret(env = process.env) {
|
|
|
171
176
|
return secret;
|
|
172
177
|
}
|
|
173
178
|
class MicrosoftGraphServer {
|
|
179
|
+
authManager;
|
|
180
|
+
options;
|
|
181
|
+
graphClient;
|
|
182
|
+
server;
|
|
183
|
+
secrets;
|
|
184
|
+
oboClient;
|
|
185
|
+
credentialCheck = null;
|
|
186
|
+
version = "0.0.0";
|
|
187
|
+
multiAccount = false;
|
|
188
|
+
accountNames = [];
|
|
189
|
+
/**
|
|
190
|
+
* Every HTTP listener `start()` opened, so `stop()` can close every one.
|
|
191
|
+
*
|
|
192
|
+
* A list rather than a field because `--attachment-port` makes it two, and an
|
|
193
|
+
* untracked listener cannot be closed at all: it holds the event loop open
|
|
194
|
+
* for the life of the process. One that is only *usually* two is worse than
|
|
195
|
+
* either, so nothing here special-cases the count.
|
|
196
|
+
*/
|
|
197
|
+
httpServers = [];
|
|
198
|
+
// The 2026-07-28 leg of /mcp, built once in start() so stop() can close it
|
|
199
|
+
mcpHandler = null;
|
|
200
|
+
stdioHandle = null;
|
|
201
|
+
// Two-leg PKCE: stores client's code_challenge and server's code_verifier, keyed by OAuth state
|
|
202
|
+
pkceStore = /* @__PURE__ */ new Map();
|
|
203
|
+
// Set in start() for HTTP mode; replaces pkceStore when present.
|
|
204
|
+
pkceSecret;
|
|
205
|
+
reportedUnavailableEagerTools = /* @__PURE__ */ new Set();
|
|
206
|
+
reportUnavailableEagerTool = (name) => {
|
|
207
|
+
if (this.reportedUnavailableEagerTools.has(name)) return;
|
|
208
|
+
this.reportedUnavailableEagerTools.add(name);
|
|
209
|
+
logger.info(`Eager tool ${name} is unavailable under the current filters or transport`);
|
|
210
|
+
};
|
|
174
211
|
constructor(authManager, options = {}) {
|
|
175
|
-
this.credentialCheck = null;
|
|
176
|
-
this.version = "0.0.0";
|
|
177
|
-
this.multiAccount = false;
|
|
178
|
-
this.accountNames = [];
|
|
179
|
-
/**
|
|
180
|
-
* Every HTTP listener `start()` opened, so `stop()` can close every one.
|
|
181
|
-
*
|
|
182
|
-
* A list rather than a field because `--attachment-port` makes it two, and an
|
|
183
|
-
* untracked listener cannot be closed at all: it holds the event loop open
|
|
184
|
-
* for the life of the process. One that is only *usually* two is worse than
|
|
185
|
-
* either, so nothing here special-cases the count.
|
|
186
|
-
*/
|
|
187
|
-
this.httpServers = [];
|
|
188
|
-
// Two-leg PKCE: stores client's code_challenge and server's code_verifier, keyed by OAuth state
|
|
189
|
-
this.pkceStore = /* @__PURE__ */ new Map();
|
|
190
|
-
this.reportedUnavailableEagerTools = /* @__PURE__ */ new Set();
|
|
191
|
-
this.reportUnavailableEagerTool = (name) => {
|
|
192
|
-
if (this.reportedUnavailableEagerTools.has(name)) return;
|
|
193
|
-
this.reportedUnavailableEagerTools.add(name);
|
|
194
|
-
logger.info(`Eager tool ${name} is unavailable under the current filters or transport`);
|
|
195
|
-
};
|
|
196
212
|
if (options.eagerTools?.length) validateEagerToolNames(options.eagerTools);
|
|
197
213
|
this.authManager = authManager;
|
|
198
214
|
this.options = options;
|
|
@@ -210,6 +226,7 @@ class MicrosoftGraphServer {
|
|
|
210
226
|
return Boolean(this.options.http) && !this.options.httpLocalFileTools;
|
|
211
227
|
}
|
|
212
228
|
createMcpServer() {
|
|
229
|
+
const mcpApps = Boolean(this.options.enableMcpApps && !this.options.toon);
|
|
213
230
|
const server = new McpServer(
|
|
214
231
|
{
|
|
215
232
|
name: "Microsoft365MCP",
|
|
@@ -225,7 +242,12 @@ class MicrosoftGraphServer {
|
|
|
225
242
|
multiAccount: this.multiAccount,
|
|
226
243
|
attachmentUrlsEnabled: Boolean(this.options.http && this.options.enableAttachmentUrls)
|
|
227
244
|
}),
|
|
228
|
-
maxToolInputElements: MAX_TOOL_INPUT_ELEMENTS
|
|
245
|
+
maxToolInputElements: MAX_TOOL_INPUT_ELEMENTS,
|
|
246
|
+
// The tool set is fixed for the life of a server, so no list ever changes
|
|
247
|
+
capabilities: {
|
|
248
|
+
tools: { listChanged: false },
|
|
249
|
+
...mcpApps && { resources: { listChanged: false } }
|
|
250
|
+
}
|
|
229
251
|
}
|
|
230
252
|
);
|
|
231
253
|
const shouldRegisterAuthTools = !this.options.appMode && (!this.options.http || this.options.enableAuthTools);
|
|
@@ -251,15 +273,13 @@ class MicrosoftGraphServer {
|
|
|
251
273
|
allowedScopes: this.options.allowedScopes,
|
|
252
274
|
httpMode: this.hidesStdioOnlyTools(),
|
|
253
275
|
userFields: this.options.userFields,
|
|
254
|
-
|
|
255
|
-
mcpApps: Boolean(this.options.enableMcpApps && !this.options.toon)
|
|
276
|
+
mcpApps
|
|
256
277
|
};
|
|
257
278
|
if (this.options.discovery) {
|
|
258
279
|
registerDiscoveryTools(server, this.graphClient, registrationOptions);
|
|
259
280
|
} else {
|
|
260
281
|
registerGraphTools(server, this.graphClient, registrationOptions);
|
|
261
282
|
}
|
|
262
|
-
installToolSchemaRefNormalization(server);
|
|
263
283
|
return server;
|
|
264
284
|
}
|
|
265
285
|
/**
|
|
@@ -391,7 +411,10 @@ class MicrosoftGraphServer {
|
|
|
391
411
|
}
|
|
392
412
|
const app = express();
|
|
393
413
|
if (this.isLoopbackOnlyHttp()) {
|
|
394
|
-
|
|
414
|
+
const hostGuard = hostHeaderValidation(LOOPBACK_HOSTNAMES);
|
|
415
|
+
app.use((req, res, next) => {
|
|
416
|
+
if (hostGuard(req, res)) next();
|
|
417
|
+
});
|
|
395
418
|
app.use(loopbackOriginValidation());
|
|
396
419
|
}
|
|
397
420
|
const trustProxyEnv = process.env.MS365_MCP_TRUST_PROXY_HOPS;
|
|
@@ -417,7 +440,7 @@ class MicrosoftGraphServer {
|
|
|
417
440
|
res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
|
|
418
441
|
res.header(
|
|
419
442
|
"Access-Control-Allow-Headers",
|
|
420
|
-
"Origin, X-Requested-With, Content-Type, Accept, Authorization, mcp-protocol-version"
|
|
443
|
+
"Origin, X-Requested-With, Content-Type, Accept, Authorization, mcp-protocol-version, mcp-method, mcp-name"
|
|
421
444
|
);
|
|
422
445
|
if (req.method === "OPTIONS") {
|
|
423
446
|
res.sendStatus(200);
|
|
@@ -444,9 +467,21 @@ class MicrosoftGraphServer {
|
|
|
444
467
|
app.use("/register", authLimiter);
|
|
445
468
|
app.use("/mcp", mcpLimiter);
|
|
446
469
|
}
|
|
447
|
-
const oauthProvider = new MicrosoftOAuthProvider(this.authManager, this.secrets);
|
|
448
470
|
const publicUrlRaw = this.options.publicUrl || process.env.MS365_MCP_PUBLIC_URL || this.options.baseUrl || process.env.MS365_MCP_BASE_URL || null;
|
|
449
471
|
const publicBase = publicUrlRaw ? new URL(publicUrlRaw).href.replace(/\/$/, "") : null;
|
|
472
|
+
if (publicUrlRaw) {
|
|
473
|
+
const parsed = new URL(publicUrlRaw);
|
|
474
|
+
if (!["http:", "https:"].includes(parsed.protocol) || parsed.search || parsed.hash) {
|
|
475
|
+
throw new Error(
|
|
476
|
+
`Public URL ${publicUrlRaw} must be an http(s) URL without a query or fragment`
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
if (parsed.protocol === "http:" && !isLoopbackHost(parsed.hostname)) {
|
|
480
|
+
logger.warn(
|
|
481
|
+
`Public URL ${parsed.origin} is http:// on a non-loopback host. Newer MCP clients refuse an http token endpoint and cannot sign in; serve it over https.`
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
450
485
|
const cimdEnabled = this.options.clientMetadataDocuments !== false;
|
|
451
486
|
app.get("/.well-known/oauth-authorization-server", async (req, res) => {
|
|
452
487
|
const protocol = req.secure ? "https" : "http";
|
|
@@ -752,12 +787,6 @@ class MicrosoftGraphServer {
|
|
|
752
787
|
res.status(status).json(body);
|
|
753
788
|
}
|
|
754
789
|
});
|
|
755
|
-
app.use(
|
|
756
|
-
mcpAuthRouter({
|
|
757
|
-
provider: oauthProvider,
|
|
758
|
-
issuerUrl: new URL(publicBase ?? `http://localhost:${port}`)
|
|
759
|
-
})
|
|
760
|
-
);
|
|
761
790
|
const oboAllowlist = this.oboClient ? readOboAllowlist() : null;
|
|
762
791
|
if (oboAllowlist && (oboAllowlist.tenants.size > 0 || oboAllowlist.users.size > 0)) {
|
|
763
792
|
logger.info(
|
|
@@ -769,6 +798,23 @@ class MicrosoftGraphServer {
|
|
|
769
798
|
allowUnauthenticatedDiscovery: this.options.allowUnauthenticatedDiscovery,
|
|
770
799
|
publicUrl: publicBase
|
|
771
800
|
});
|
|
801
|
+
const onMcpError = (error) => {
|
|
802
|
+
if (error.message.startsWith("Rejected inbound request")) {
|
|
803
|
+
logger.debug(`MCP request refused: ${error.message}`);
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
806
|
+
logger.error("MCP request error", { error: dumpError(error) });
|
|
807
|
+
};
|
|
808
|
+
const mcpHandler = createMcpHandler(() => this.createMcpServer(), {
|
|
809
|
+
legacy: "reject",
|
|
810
|
+
maxRequestBodySize: MAX_REQUEST_BODY_BYTES,
|
|
811
|
+
onerror: onMcpError
|
|
812
|
+
});
|
|
813
|
+
this.mcpHandler = mcpHandler;
|
|
814
|
+
const serveModernMcp = toNodeHandler(mcpHandler, {
|
|
815
|
+
maxRequestBodySize: MAX_REQUEST_BODY_BYTES,
|
|
816
|
+
onerror: onMcpError
|
|
817
|
+
});
|
|
772
818
|
app.get("/mcp", (req, res) => {
|
|
773
819
|
res.status(405).json({
|
|
774
820
|
jsonrpc: "2.0",
|
|
@@ -784,8 +830,20 @@ class MicrosoftGraphServer {
|
|
|
784
830
|
mcpAuth,
|
|
785
831
|
async (req, res) => {
|
|
786
832
|
const handler = async () => {
|
|
833
|
+
const body = req.body;
|
|
834
|
+
if (body !== void 0) {
|
|
835
|
+
const probe = await toWebRequest(req, body, {
|
|
836
|
+
maxRequestBodySize: MAX_REQUEST_BODY_BYTES
|
|
837
|
+
});
|
|
838
|
+
if (!await isLegacyRequest(probe, body, {
|
|
839
|
+
maxRequestBodySize: MAX_REQUEST_BODY_BYTES
|
|
840
|
+
})) {
|
|
841
|
+
await serveModernMcp(req, res, body);
|
|
842
|
+
return;
|
|
843
|
+
}
|
|
844
|
+
}
|
|
787
845
|
const server = this.createMcpServer();
|
|
788
|
-
const transport = new
|
|
846
|
+
const transport = new NodeStreamableHTTPServerTransport({
|
|
789
847
|
sessionIdGenerator: void 0,
|
|
790
848
|
// Stateless mode
|
|
791
849
|
enableJsonResponse: true,
|
|
@@ -793,11 +851,13 @@ class MicrosoftGraphServer {
|
|
|
793
851
|
maxRequestBodySize: MAX_REQUEST_BODY_BYTES
|
|
794
852
|
});
|
|
795
853
|
res.on("close", () => {
|
|
796
|
-
transport.close()
|
|
797
|
-
|
|
854
|
+
void transport.close().catch(() => {
|
|
855
|
+
});
|
|
856
|
+
void server.close().catch(() => {
|
|
857
|
+
});
|
|
798
858
|
});
|
|
799
859
|
await server.connect(transport);
|
|
800
|
-
await transport.handleRequest(req, res,
|
|
860
|
+
await transport.handleRequest(req, res, body);
|
|
801
861
|
};
|
|
802
862
|
try {
|
|
803
863
|
if (req.microsoftAuth) {
|
|
@@ -945,12 +1005,19 @@ class MicrosoftGraphServer {
|
|
|
945
1005
|
}
|
|
946
1006
|
}
|
|
947
1007
|
} else {
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
1008
|
+
this.stdioHandle = serveStdio(
|
|
1009
|
+
() => {
|
|
1010
|
+
const server = this.server ?? this.createMcpServer();
|
|
1011
|
+
this.server = null;
|
|
1012
|
+
return server;
|
|
1013
|
+
},
|
|
1014
|
+
{
|
|
1015
|
+
onerror: (error) => {
|
|
1016
|
+
logger.error("Stdio transport error", { error: dumpError(error) });
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
);
|
|
1020
|
+
logger.info("Serving MCP over stdio");
|
|
954
1021
|
}
|
|
955
1022
|
}
|
|
956
1023
|
/**
|
|
@@ -1020,11 +1087,17 @@ class MicrosoftGraphServer {
|
|
|
1020
1087
|
async stop() {
|
|
1021
1088
|
const servers = this.httpServers.splice(0);
|
|
1022
1089
|
configureAttachmentMinting(null);
|
|
1090
|
+
const stdioHandle = this.stdioHandle;
|
|
1091
|
+
this.stdioHandle = null;
|
|
1092
|
+
await stdioHandle?.close();
|
|
1093
|
+
const mcpHandler = this.mcpHandler;
|
|
1094
|
+
this.mcpHandler = null;
|
|
1095
|
+
await mcpHandler?.close();
|
|
1023
1096
|
await Promise.all(
|
|
1024
1097
|
servers.map(
|
|
1025
1098
|
(server) => new Promise((resolve) => {
|
|
1026
1099
|
server.close(() => resolve());
|
|
1027
|
-
server.
|
|
1100
|
+
server.closeAllConnections();
|
|
1028
1101
|
})
|
|
1029
1102
|
)
|
|
1030
1103
|
);
|
|
@@ -444,10 +444,8 @@ async function assertOverwritable(key, cachePath) {
|
|
|
444
444
|
throw new Error(`Refusing to overwrite the unreadable auth cache at ${cachePath}`);
|
|
445
445
|
}
|
|
446
446
|
class DefaultTokenCacheStorage {
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
this.failClosed = false;
|
|
450
|
-
}
|
|
447
|
+
description = "default (encrypted file)";
|
|
448
|
+
failClosed = false;
|
|
451
449
|
async load(key) {
|
|
452
450
|
assertValidKey(key);
|
|
453
451
|
migrateLegacyPaths();
|
|
@@ -508,9 +506,10 @@ class CommandTokenCacheStorage {
|
|
|
508
506
|
this.commandPath = commandPath;
|
|
509
507
|
this.timeoutMs = timeoutMs;
|
|
510
508
|
this.spawnCommand = spawnCommand;
|
|
511
|
-
this.failClosed = true;
|
|
512
509
|
this.description = `command (${path.basename(commandPath)})`;
|
|
513
510
|
}
|
|
511
|
+
description;
|
|
512
|
+
failClosed = true;
|
|
514
513
|
async load(key) {
|
|
515
514
|
assertValidKey(key);
|
|
516
515
|
const result = await this.invoke("load", key);
|
package/docs/deployment.md
CHANGED
|
@@ -18,6 +18,10 @@ MCP Clients (Claude Desktop, Claude Code, Open WebUI, ...)
|
|
|
18
18
|
Microsoft Graph API
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
+
Requires Node.js 20 or newer.
|
|
22
|
+
|
|
23
|
+
`/mcp` serves both protocol eras on the same URL: MCP 2026-07-28 clients (which open with `server/discover`) and 2025-era clients (which open with `initialize`). Nothing needs configuring for either.
|
|
24
|
+
|
|
21
25
|
## Headless stdio auth-cache storage
|
|
22
26
|
|
|
23
27
|
Production HTTP deployments are stateless: normal Graph requests carry a per-user bearer token, including On-Behalf-Of (`--obo`) deployments, and the server does not store MSAL token state for those requests.
|
|
@@ -198,6 +202,10 @@ MS365_MCP_PUBLIC_URL=https://mcp.example.com
|
|
|
198
202
|
|
|
199
203
|
Every advertised URL (`issuer`, `authorization_endpoint`, `token_endpoint`, `registration_endpoint`, `resource`, `authorization_servers`) uses this URL, path included, so a server hosted under a sub-path works. A client that reaches the server over an internal network (e.g. another container on the same Docker network) must still be able to reach the public URL, since it calls `/token` there.
|
|
200
204
|
|
|
205
|
+
The proxy must pass the `MCP-Protocol-Version`, `Mcp-Method` and `Mcp-Name` request headers through to `/mcp`. MCP 2026-07-28 clients send them on every request, and the server answers `400` when they are missing; 2025-era clients do not need them.
|
|
206
|
+
|
|
207
|
+
Use an `https://` public URL. Newer MCP clients refuse an `http://` token endpoint, so the server logs a warning at startup when the public URL is `http://` on a host other than localhost.
|
|
208
|
+
|
|
201
209
|
## Client Configuration
|
|
202
210
|
|
|
203
211
|
Once deployed, users connect by pointing their MCP client to the server URL:
|
package/eslint.config.js
CHANGED
|
@@ -3,6 +3,15 @@ import globals from 'globals';
|
|
|
3
3
|
import tseslint from '@typescript-eslint/eslint-plugin';
|
|
4
4
|
import tsparser from '@typescript-eslint/parser';
|
|
5
5
|
|
|
6
|
+
const SDK_V1 = {
|
|
7
|
+
group: ['@modelcontextprotocol/sdk', '@modelcontextprotocol/sdk/*'],
|
|
8
|
+
message: 'SDK v1 is gone, use the v2 packages.',
|
|
9
|
+
};
|
|
10
|
+
const CLIENT = {
|
|
11
|
+
group: ['@modelcontextprotocol/client', '@modelcontextprotocol/client/*'],
|
|
12
|
+
message: 'The client package is a devDependency, for tests only.',
|
|
13
|
+
};
|
|
14
|
+
|
|
6
15
|
export default [
|
|
7
16
|
js.configs.recommended,
|
|
8
17
|
{
|
|
@@ -28,6 +37,14 @@ export default [
|
|
|
28
37
|
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
|
|
29
38
|
'@typescript-eslint/no-explicit-any': 'warn',
|
|
30
39
|
'no-console': 'off',
|
|
40
|
+
'no-restricted-imports': ['error', { patterns: [SDK_V1] }],
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
// The client package is a devDependency, for tests only
|
|
45
|
+
files: ['src/**/*.ts'],
|
|
46
|
+
rules: {
|
|
47
|
+
'no-restricted-imports': ['error', { patterns: [SDK_V1, CLIENT] }],
|
|
31
48
|
},
|
|
32
49
|
},
|
|
33
50
|
{
|
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.191.1",
|
|
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",
|
|
@@ -36,7 +36,8 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@azure/msal-node": "^7.1.1",
|
|
39
|
-
"@modelcontextprotocol/
|
|
39
|
+
"@modelcontextprotocol/node": "^2.1.2",
|
|
40
|
+
"@modelcontextprotocol/server": "^2.4.0",
|
|
40
41
|
"@toon-format/toon": "^2.3.1",
|
|
41
42
|
"commander": "^11.1.0",
|
|
42
43
|
"dotenv": "^17.0.1",
|
|
@@ -55,6 +56,7 @@
|
|
|
55
56
|
"keytar": "^7.9.0"
|
|
56
57
|
},
|
|
57
58
|
"devDependencies": {
|
|
59
|
+
"@modelcontextprotocol/client": "^2.4.0",
|
|
58
60
|
"@redocly/cli": "^2.11.1",
|
|
59
61
|
"@semantic-release/exec": "^7.1.0",
|
|
60
62
|
"@semantic-release/git": "^10.0.1",
|
|
@@ -75,7 +77,7 @@
|
|
|
75
77
|
"vitest": "^4.1.8"
|
|
76
78
|
},
|
|
77
79
|
"engines": {
|
|
78
|
-
"node": ">=
|
|
80
|
+
"node": ">=20"
|
|
79
81
|
},
|
|
80
82
|
"repository": {
|
|
81
83
|
"type": "git",
|
package/tsup.config.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { defineConfig } from 'tsup';
|
|
|
3
3
|
export default defineConfig({
|
|
4
4
|
entry: ['src/**/*.ts', 'src/endpoints.json', 'src/apps/*.html', 'src/apps/*.js'],
|
|
5
5
|
format: ['esm'],
|
|
6
|
-
target: '
|
|
6
|
+
target: 'es2022',
|
|
7
7
|
outDir: 'dist',
|
|
8
8
|
clean: true,
|
|
9
9
|
bundle: false,
|
|
@@ -21,7 +21,8 @@ export default defineConfig({
|
|
|
21
21
|
noExternal: [],
|
|
22
22
|
external: [
|
|
23
23
|
'@azure/msal-node',
|
|
24
|
-
'@modelcontextprotocol/
|
|
24
|
+
'@modelcontextprotocol/node',
|
|
25
|
+
'@modelcontextprotocol/server',
|
|
25
26
|
'commander',
|
|
26
27
|
'dotenv',
|
|
27
28
|
'express',
|
package/dist/oauth-provider.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { ProxyOAuthServerProvider } from "@modelcontextprotocol/sdk/server/auth/providers/proxyProvider.js";
|
|
2
|
-
import logger from "./logger.js";
|
|
3
|
-
import { getCloudEndpoints, getGraphBaseUrl } from "./cloud-config.js";
|
|
4
|
-
class MicrosoftOAuthProvider extends ProxyOAuthServerProvider {
|
|
5
|
-
constructor(authManager, secrets) {
|
|
6
|
-
const tenantId = secrets.tenantId || "common";
|
|
7
|
-
const clientId = secrets.clientId;
|
|
8
|
-
const cloudEndpoints = getCloudEndpoints(secrets.cloudType);
|
|
9
|
-
super({
|
|
10
|
-
endpoints: {
|
|
11
|
-
authorizationUrl: `${cloudEndpoints.authority}/${tenantId}/oauth2/v2.0/authorize`,
|
|
12
|
-
tokenUrl: `${cloudEndpoints.authority}/${tenantId}/oauth2/v2.0/token`,
|
|
13
|
-
revocationUrl: `${cloudEndpoints.authority}/${tenantId}/oauth2/v2.0/logout`
|
|
14
|
-
},
|
|
15
|
-
verifyAccessToken: async (token) => {
|
|
16
|
-
try {
|
|
17
|
-
const response = await fetch(`${getGraphBaseUrl(secrets.cloudType)}/v1.0/me`, {
|
|
18
|
-
headers: {
|
|
19
|
-
Authorization: `Bearer ${token}`
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
if (response.ok) {
|
|
23
|
-
const userData = await response.json();
|
|
24
|
-
logger.info(`OAuth token verified for user: ${userData.userPrincipalName}`);
|
|
25
|
-
await authManager.setOAuthToken(token);
|
|
26
|
-
return {
|
|
27
|
-
token,
|
|
28
|
-
clientId,
|
|
29
|
-
scopes: []
|
|
30
|
-
};
|
|
31
|
-
} else {
|
|
32
|
-
throw new Error(`Token verification failed: ${response.status}`);
|
|
33
|
-
}
|
|
34
|
-
} catch (error) {
|
|
35
|
-
logger.error(`OAuth token verification error: ${error}`);
|
|
36
|
-
throw error;
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
getClient: async (client_id) => {
|
|
40
|
-
return {
|
|
41
|
-
client_id,
|
|
42
|
-
redirect_uris: ["http://localhost:3000/callback"]
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
this.authManager = authManager;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
export {
|
|
50
|
-
MicrosoftOAuthProvider
|
|
51
|
-
};
|
package/test-calendar-fix.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// Test script to verify the calendarId parameter fix
|
|
4
|
-
// This simulates what the MCP client would do
|
|
5
|
-
|
|
6
|
-
import { spawn } from 'child_process';
|
|
7
|
-
import { fileURLToPath } from 'url';
|
|
8
|
-
import { dirname, join } from 'path';
|
|
9
|
-
|
|
10
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
-
const __dirname = dirname(__filename);
|
|
12
|
-
|
|
13
|
-
// Start the MCP server
|
|
14
|
-
const server = spawn('node', [join(__dirname, 'dist', 'index.js'), '-v'], {
|
|
15
|
-
stdio: ['pipe', 'pipe', 'inherit'],
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
// Wait a bit for server to start
|
|
19
|
-
setTimeout(() => {
|
|
20
|
-
// Test the create-calendar-event with calendarId
|
|
21
|
-
const testRequest = {
|
|
22
|
-
jsonrpc: '2.0',
|
|
23
|
-
method: 'tools/call',
|
|
24
|
-
params: {
|
|
25
|
-
name: 'create-calendar-event',
|
|
26
|
-
arguments: {
|
|
27
|
-
calendarId: 'EXAMPLE_CALENDAR_ID_HERE',
|
|
28
|
-
body: {
|
|
29
|
-
subject: 'Test Event on Specific Calendar',
|
|
30
|
-
body: {
|
|
31
|
-
contentType: 'text',
|
|
32
|
-
content: 'Testing calendarId parameter fix',
|
|
33
|
-
},
|
|
34
|
-
start: {
|
|
35
|
-
dateTime: '2025-12-01T10:00:00.0000000',
|
|
36
|
-
timeZone: 'America/New_York',
|
|
37
|
-
},
|
|
38
|
-
end: {
|
|
39
|
-
dateTime: '2025-12-01T11:00:00.0000000',
|
|
40
|
-
timeZone: 'America/New_York',
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
id: 1,
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
console.log('Sending test request:', JSON.stringify(testRequest, null, 2));
|
|
49
|
-
|
|
50
|
-
server.stdin.write(JSON.stringify(testRequest) + '\n');
|
|
51
|
-
|
|
52
|
-
// Read response
|
|
53
|
-
server.stdout.on('data', (data) => {
|
|
54
|
-
console.log('Response:', data.toString());
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// Close after a few seconds
|
|
58
|
-
setTimeout(() => {
|
|
59
|
-
server.kill();
|
|
60
|
-
process.exit(0);
|
|
61
|
-
}, 5000);
|
|
62
|
-
}, 2000);
|