@softeria/ms-365-mcp-server 0.190.4 → 0.190.5
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/dist/cli.js +1 -1
- package/dist/lib/client-metadata.js +14 -3
- package/dist/server.js +4 -1
- package/docs/deployment.md +3 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -82,7 +82,7 @@ program.name("ms-365-mcp-server").description("Microsoft 365 MCP Server").versio
|
|
|
82
82
|
"Use browser-based interactive OAuth flow instead of device code for stdio mode. Opens system browser with localhost callback for seamless sign-in."
|
|
83
83
|
).option(
|
|
84
84
|
"--public-url <url>",
|
|
85
|
-
"Public base URL (e.g. https://mcp.example.com) used
|
|
85
|
+
"Public base URL (e.g. https://mcp.example.com) used for every advertised OAuth endpoint when running behind a reverse proxy, path included."
|
|
86
86
|
).option(
|
|
87
87
|
"--obo",
|
|
88
88
|
"Enable On-Behalf-Of token exchange in HTTP mode. Exchanges the incoming bearer token for a Graph API token using the OBO flow. Requires MS365_MCP_CLIENT_SECRET."
|
|
@@ -9,6 +9,7 @@ const CIMD_MIN_TTL_MS = 6e4;
|
|
|
9
9
|
const CIMD_MAX_TTL_MS = 24 * 60 * 6e4;
|
|
10
10
|
const CIMD_MAX_CACHE_ENTRIES = 500;
|
|
11
11
|
const CIMD_MAX_IN_FLIGHT = 20;
|
|
12
|
+
const CIMD_RETRY_AFTER_SECONDS = 30;
|
|
12
13
|
class ClientMetadataError extends Error {
|
|
13
14
|
constructor(message, transient = false) {
|
|
14
15
|
super(message);
|
|
@@ -274,7 +275,10 @@ class ClientMetadataResolver {
|
|
|
274
275
|
if (!pending) {
|
|
275
276
|
if (this.inFlight.size >= CIMD_MAX_IN_FLIGHT) {
|
|
276
277
|
if (stale) return stale;
|
|
277
|
-
throw new ClientMetadataError(
|
|
278
|
+
throw new ClientMetadataError(
|
|
279
|
+
"too many client metadata lookups in progress, try again",
|
|
280
|
+
true
|
|
281
|
+
);
|
|
278
282
|
}
|
|
279
283
|
pending = this.load(url, clientId).finally(() => this.inFlight.delete(clientId));
|
|
280
284
|
this.inFlight.set(clientId, pending);
|
|
@@ -338,8 +342,14 @@ async function checkAuthorizeClient(params) {
|
|
|
338
342
|
try {
|
|
339
343
|
metadata = await resolver.resolve(clientId);
|
|
340
344
|
} catch (err) {
|
|
341
|
-
|
|
342
|
-
|
|
345
|
+
if (!(err instanceof ClientMetadataError)) {
|
|
346
|
+
return { ok: false, error: "invalid_client", description: "client metadata error" };
|
|
347
|
+
}
|
|
348
|
+
return {
|
|
349
|
+
ok: false,
|
|
350
|
+
error: err.transient ? "temporarily_unavailable" : "invalid_client",
|
|
351
|
+
description: err.message
|
|
352
|
+
};
|
|
343
353
|
}
|
|
344
354
|
if (!redirectUriMatches(redirectUri, metadata.redirect_uris)) {
|
|
345
355
|
return {
|
|
@@ -358,6 +368,7 @@ export {
|
|
|
358
368
|
CIMD_MAX_STALE_MS,
|
|
359
369
|
CIMD_MAX_TTL_MS,
|
|
360
370
|
CIMD_MIN_TTL_MS,
|
|
371
|
+
CIMD_RETRY_AFTER_SECONDS,
|
|
361
372
|
CIMD_TIMEOUT_MS,
|
|
362
373
|
ClientMetadataError,
|
|
363
374
|
ClientMetadataResolver,
|
package/dist/server.js
CHANGED
|
@@ -40,6 +40,7 @@ import {
|
|
|
40
40
|
import { isAllowedRedirectUri, parseAllowlist } from "./lib/redirect-uri-validation.js";
|
|
41
41
|
import {
|
|
42
42
|
checkAuthorizeClient,
|
|
43
|
+
CIMD_RETRY_AFTER_SECONDS,
|
|
43
44
|
clientIdHost,
|
|
44
45
|
ClientMetadataResolver,
|
|
45
46
|
DCR_DISABLED_HINT
|
|
@@ -546,7 +547,9 @@ class MicrosoftGraphServer {
|
|
|
546
547
|
error: clientCheck.error,
|
|
547
548
|
reason: clientCheck.description
|
|
548
549
|
});
|
|
549
|
-
|
|
550
|
+
const unavailable = clientCheck.error === "temporarily_unavailable";
|
|
551
|
+
if (unavailable) res.set("Retry-After", String(CIMD_RETRY_AFTER_SECONDS));
|
|
552
|
+
res.status(unavailable ? 503 : 400).json({
|
|
550
553
|
error: clientCheck.error,
|
|
551
554
|
error_description: clientCheck.description
|
|
552
555
|
});
|
package/docs/deployment.md
CHANGED
|
@@ -186,7 +186,7 @@ The list should mirror the redirect URIs registered on your Azure AD app registr
|
|
|
186
186
|
|
|
187
187
|
## Reverse Proxy / Custom Domain
|
|
188
188
|
|
|
189
|
-
When running behind a reverse proxy, set `MS365_MCP_PUBLIC_URL` so that the OAuth
|
|
189
|
+
When running behind a reverse proxy, set `MS365_MCP_PUBLIC_URL` so that the OAuth URLs the server advertises are resolvable from outside the server's network:
|
|
190
190
|
|
|
191
191
|
```bash
|
|
192
192
|
# Via environment variable
|
|
@@ -196,7 +196,7 @@ MS365_MCP_PUBLIC_URL=https://mcp.example.com
|
|
|
196
196
|
--public-url https://mcp.example.com
|
|
197
197
|
```
|
|
198
198
|
|
|
199
|
-
|
|
199
|
+
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
200
|
|
|
201
201
|
## Client Configuration
|
|
202
202
|
|
|
@@ -233,7 +233,7 @@ The client automatically discovers OAuth endpoints and opens a browser for authe
|
|
|
233
233
|
- **Read-only mode**: use `--read-only` to disable all write operations (send, delete, update, create)
|
|
234
234
|
- **Tool filtering**: use `--enabled-tools <regex>`, `--enabled-tools-file <path>` (one regex per line), or `--preset <names>` to restrict available tools
|
|
235
235
|
- **CORS**: configure `MS365_MCP_CORS_ORIGIN` to restrict allowed origins (defaults to `http://localhost:3000`); set explicitly when clients run on a different origin
|
|
236
|
-
- **Client registration**: clients identify themselves with Client ID Metadata Documents (CIMD): the `client_id` is an https URL, the server fetches the document there and only redirects to a `redirect_uri` it lists. This follows the MCP spec; it is not a security boundary, since a `client_id` that is not an https URL skips it and the server always sends its own client ID to Entra, whose reply URLs are what really limit where codes go. The fetch only goes to public addresses, follows no redirects and is capped at 5 KiB and 5 s; documents are cached per their `Cache-Control` (5 minutes by default), and an expired one is still used for up to 24 hours while a refetch fails for a passing reason (unreachable host, timeout, 5xx, 429) or every lookup slot is busy; a final answer (a 404, an invalid document) drops it at once. The fetch connects directly and does not use `HTTPS_PROXY`, so it needs direct outbound HTTPS to
|
|
236
|
+
- **Client registration**: clients identify themselves with Client ID Metadata Documents (CIMD): the `client_id` is an https URL, the server fetches the document there and only redirects to a `redirect_uri` it lists. This follows the MCP spec; it is not a security boundary, since a `client_id` that is not an https URL skips it and the server always sends its own client ID to Entra, whose reply URLs are what really limit where codes go. The fetch only goes to public addresses, follows no redirects and is capped at 5 KiB and 5 s; documents are cached per their `Cache-Control` (5 minutes by default), and an expired one is still used for up to 24 hours while a refetch fails for a passing reason (unreachable host, timeout, 5xx, 429) or every lookup slot is busy; a final answer (a 404, an invalid document) drops it at once. With no usable copy, `/authorize` answers a passing failure with 503 `temporarily_unavailable` and `Retry-After`, and a final one with 400 `invalid_client`. The fetch resolves the client's host over DNS itself, so `/etc/hosts` entries do not apply. It connects directly and does not use `HTTPS_PROXY`, so it needs direct outbound HTTPS to that host (`claude.ai` for Claude). Without that, turn CIMD off with `--no-client-metadata-documents` (or `MS365_MCP_DISABLE_CIMD=true`) and turn DCR on: Claude then falls back to DCR. Dynamic Client Registration is off by default, since the MCP spec deprecated it; `/register` then answers with how to turn it on. Turn it on with `--enable-dynamic-registration` or `MS365_MCP_ENABLE_DCR=true` for DCR-only clients such as Open WebUI; `MS365_MCP_DISABLE_DCR=true` (or `--no-dynamic-registration`) keeps it off regardless. Other `client_id` values (a static one, or one issued by DCR earlier) are accepted at `/authorize` as before
|
|
237
237
|
- **Structured audit log**: enabled by default. Every tool invocation that reaches Microsoft Graph emits one JSON line on stderr (captured by the container platform's log collector) and to `~/.ms-365-mcp-server/logs/audit.log` (mode `0o600`, or under `MS365_MCP_LOG_DIR` when set) with `{ event, request_id, user_principal_name, tool, http_method, http_status?, status, duration_ms, recipient_count?, recipient_domains?, recipient_domains_truncated?, graph_batch_subrequest_count?, graph_batch_http_status_counts?, graph_batch_error_code_counts?, result_count?, result_has_more?, response_bytes?, target_resource?, error_type?, error_code? }`. A few refusals short-circuit before that and emit nothing: a confirm-gate rejection, an `account` param that contradicts the bearer identity, and a failure to resolve an account token. Policy-blocked tool attempts emit `event: "tool.denied"` with `status: "denied"`, `reason` (`allowed_scopes` or `tool_allowlist`), and `missing_scopes` when applicable. When an audited generated Microsoft Graph tool targets a derivable resource through an ID-like path parameter such as `{message-id}` or `{driveItem-id}`, `target_resource` is `{ type, id }`, where `id` is the Graph path up to that resource ID. Later path parameters such as `{path}`, query values, returned content, and Graph response bodies are NEVER recorded, and error messages are reduced to `error_type` / `error_code` so upstream library errors do not leak token fragments or query-string PII. Response _metadata_ is recorded — `result_count`, `result_has_more` and `response_bytes` describe how much came back so that a bulk read is distinguishable from an ordinary one; none of them reveals any of its content. Two things derived from tool parameters **are** recorded, both deliberately. First, `target_resource.id` substitutes ID-like path parameters into the resource path, so a tool on `/users/{user-id}/...` records whatever identifier the caller passed, which may be a full email address. Second, a request whose body carries `toRecipients` / `ccRecipients` / `bccRecipients` / `attendees` / `recipients`, at any casing and several levels down, including inside a `graph-batch` sub-request, records `recipient_count`, the number of entries in those arrays, and `recipient_domains`, the **domain part only** of their addresses and only where it parses as a plain hostname, never the local part and never a subject or message body. An entry that names someone without an address (a `driveRecipient` given as `alias` or `objectId`) counts but contributes no domain. It keys on body shape rather than on the endpoint, so it covers sends, forwards, invites and file shares but equally draft creation and edits, event updates and `findMeetingTimes`, and it reads high rather than low: an attached message's own recipients are counted too. `recipient_domains` holds at most 50 **distinct domains**, alphabetically, and sets `recipient_domains_truncated: true` when there were more; `recipient_count` is unaffected by the cap. All three are absent when the body carries no recipient array at all. A request that fails after reaching Graph still records recipients, since a timeout is not proof of non-delivery. Gaps remain, so absence proves nothing: a draft composed outside this server and sent by id, the original thread's recipients on a reply (Graph resolves those server-side), and a body nesting recipients deeper than the walker descends. This describes the structured audit log only; the operational logger is separate and does log tool parameters. Forms the "who accessed what, when" trail required for GDPR / HIPAA / PIPEDA / SOC 2 audit. Opt-out: `MS365_MCP_AUDIT_LOG=false`
|
|
238
238
|
- **Graph resilience**: every call to Microsoft Graph is wrapped with a fetch timeout (default 100 s via `MS365_MCP_GRAPH_TIMEOUT_MS`), retry-with-backoff on 429 / 503 / 504 / network errors (default 3 retries, full-jitter exponential backoff, honours `Retry-After`; 503 / 504 / network errors only retried for idempotent methods, 429 retried on all methods), and a process-wide circuit breaker that opens after 5 consecutive failures and cools down for 30 s (`MS365_MCP_GRAPH_CIRCUIT_THRESHOLD` / `MS365_MCP_GRAPH_CIRCUIT_COOLDOWN_MS`). Disable the breaker for trusted automation: `MS365_MCP_GRAPH_CIRCUIT_DISABLED=true`
|
|
239
239
|
- **Confirm gate on destructive tools**: opt-in, **off by default**. Enable with `MS365_MCP_REQUIRE_CONFIRM=true`. When on, destructive tools (POST except `readOnly`, PATCH, PUT, DELETE — `delete-mail-message`, `send-mail`, `update-event`, etc.) return `{ "error": "confirmation_required" }` until the caller re-invokes them with `"confirm": true`. Mitigates accidental writes when an LLM misroutes a request or follows an injected instruction. Shipped opt-in so it is a non-breaking, additive layer that can coexist with client-side elicitation prompts (MCP Elicitation API) where the client supports them.
|
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.190.
|
|
4
|
+
"version": "0.190.5",
|
|
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",
|