@softeria/ms-365-mcp-server 0.190.3 → 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/README.md +2 -0
- package/dist/__tests__/graph-tools.test.js +27 -1
- package/dist/cli.js +1 -1
- package/dist/graph-tools.js +7 -2
- package/dist/lib/client-metadata.js +14 -3
- package/dist/mcp-instructions.js +1 -1
- package/dist/server.js +4 -1
- package/docs/deployment.md +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -895,6 +895,8 @@ When running as an MCP server, the following options can be used:
|
|
|
895
895
|
|
|
896
896
|
The account tools (`login`, `logout`, `verify-login`, `list-accounts`, `select-account`, `remove-account`) follow the same filters: `--enabled-tools` applies to them, every `--preset` includes them, and `--read-only` or `MS365_MCP_OAUTH_TOKEN` keeps only `verify-login` and `list-accounts`.
|
|
897
897
|
|
|
898
|
+
`--read-only` keeps `download-bytes-to-file` (stdio, or HTTP with `--http-local-file-tools`), since it only reads from Microsoft 365. It tells clients that it writes files (`readOnlyHint: false`), so they can ask before running it.
|
|
899
|
+
|
|
898
900
|
Environment variables:
|
|
899
901
|
|
|
900
902
|
- `READ_ONLY=true|1`: Alternative to --read-only flag
|
|
@@ -3508,7 +3508,7 @@ describe("graph-tools", () => {
|
|
|
3508
3508
|
});
|
|
3509
3509
|
});
|
|
3510
3510
|
describe("utility tools in read-only mode", () => {
|
|
3511
|
-
it("
|
|
3511
|
+
it("keeps read-only utility tools and skips write ones", async () => {
|
|
3512
3512
|
mockEndpoints.length = 0;
|
|
3513
3513
|
mockEndpointsJson = [];
|
|
3514
3514
|
const server = createMockServer();
|
|
@@ -3516,6 +3516,32 @@ describe("graph-tools", () => {
|
|
|
3516
3516
|
registerGraphTools(server, {}, { readOnly: true });
|
|
3517
3517
|
expect(server.tools.has("download-bytes")).toBe(true);
|
|
3518
3518
|
expect(server.tools.has("parse-teams-url")).toBe(true);
|
|
3519
|
+
expect(server.tools.has("get-upload-url")).toBe(false);
|
|
3520
|
+
});
|
|
3521
|
+
it("keeps download-bytes-to-file, but tells clients it writes files", async () => {
|
|
3522
|
+
mockEndpoints.length = 0;
|
|
3523
|
+
mockEndpointsJson = [];
|
|
3524
|
+
const server = createMockServer();
|
|
3525
|
+
const { registerGraphTools } = await loadModule();
|
|
3526
|
+
registerGraphTools(server, {}, { readOnly: true });
|
|
3527
|
+
const call = server.tool.mock.calls.find((c) => c[0] === "download-bytes-to-file");
|
|
3528
|
+
expect(call?.[3]).toEqual({
|
|
3529
|
+
title: "download-bytes-to-file",
|
|
3530
|
+
readOnlyHint: false,
|
|
3531
|
+
destructiveHint: false,
|
|
3532
|
+
openWorldHint: true
|
|
3533
|
+
});
|
|
3534
|
+
});
|
|
3535
|
+
});
|
|
3536
|
+
describe("utility tool annotations", () => {
|
|
3537
|
+
it("sends destructiveHint only for download-bytes-to-file", async () => {
|
|
3538
|
+
mockEndpoints.length = 0;
|
|
3539
|
+
mockEndpointsJson = [];
|
|
3540
|
+
const server = createMockServer();
|
|
3541
|
+
const { registerGraphTools } = await loadModule();
|
|
3542
|
+
registerGraphTools(server, {}, {});
|
|
3543
|
+
const withHint = server.tool.mock.calls.filter((c) => "destructiveHint" in c[3]).map((c) => c[0]);
|
|
3544
|
+
expect(withHint).toEqual(["download-bytes-to-file"]);
|
|
3519
3545
|
});
|
|
3520
3546
|
});
|
|
3521
3547
|
describe("destructive operations require confirm: true", () => {
|
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."
|
package/dist/graph-tools.js
CHANGED
|
@@ -635,7 +635,7 @@ async function executeUtilityTool(utility, ctx, params) {
|
|
|
635
635
|
}
|
|
636
636
|
}
|
|
637
637
|
function isUtilityToolAvailable(utility, options) {
|
|
638
|
-
if (options.readOnly && !utility.readOnlyHint) return false;
|
|
638
|
+
if (options.readOnly && !utility.readOnlyHint && !utility.allowedInReadOnly) return false;
|
|
639
639
|
if (options.httpMode && utility.stdioOnly) return false;
|
|
640
640
|
if (options.scopeMode === "app" && utility.meOnly) return false;
|
|
641
641
|
if (utility.enabled && !utility.enabled()) return false;
|
|
@@ -1513,7 +1513,11 @@ const UTILITY_TOOLS = [
|
|
|
1513
1513
|
// sits past the cap. That keeps the hint for the reading LLM while letting
|
|
1514
1514
|
// get-download-url own the high-signal "drive"/"sharepoint" search terms.
|
|
1515
1515
|
description: "Write authenticated Microsoft Graph byte content to a local file on the server, returning { path, contentType, bytesWritten } instead of base64. An out-of-band way to save mail attachments and meeting recordings. With --enable-attachment-urls in HTTP mode, prefer get-download-url to hand their bytes to an external downloader or converter. Also handles profile photos and Teams hosted content. Writes to an absolute outputPath and never overwrites an existing file. stdio mode, or HTTP with --http-local-file-tools. For OneDrive or SharePoint file content, get-download-url is preferred \u2014 it returns a pre-authenticated URL for fully out-of-band download without the server fetching the bytes.",
|
|
1516
|
-
|
|
1516
|
+
// Writes to the local disk, so clients must not see it as read-only. It only
|
|
1517
|
+
// creates new files, and it only reads from Microsoft 365, so --read-only keeps it.
|
|
1518
|
+
readOnlyHint: false,
|
|
1519
|
+
destructiveHint: false,
|
|
1520
|
+
allowedInReadOnly: true,
|
|
1517
1521
|
openWorldHint: true,
|
|
1518
1522
|
stdioOnly: true,
|
|
1519
1523
|
buildSchema: (ctx) => {
|
|
@@ -1935,6 +1939,7 @@ function registerUtilityToolWithMcp(server, utility, ctx) {
|
|
|
1935
1939
|
{
|
|
1936
1940
|
title: utility.name,
|
|
1937
1941
|
readOnlyHint: utility.readOnlyHint ?? true,
|
|
1942
|
+
...utility.destructiveHint !== void 0 ? { destructiveHint: utility.destructiveHint } : {},
|
|
1938
1943
|
openWorldHint: utility.openWorldHint ?? true
|
|
1939
1944
|
},
|
|
1940
1945
|
async (params) => executeUtilityTool(utility, ctx, params)
|
|
@@ -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/mcp-instructions.js
CHANGED
|
@@ -14,7 +14,7 @@ function buildGeneralMcpInstructions(opts) {
|
|
|
14
14
|
parts.push(
|
|
15
15
|
"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."
|
|
16
16
|
);
|
|
17
|
-
if (opts.readOnly) parts.push("This server is read-only;
|
|
17
|
+
if (opts.readOnly) parts.push("This server is read-only; writes to Microsoft 365 are disabled.");
|
|
18
18
|
else
|
|
19
19
|
parts.push(
|
|
20
20
|
"Mail reply, reply-all and forward tools (including their drafts and shared mailboxes): Graph puts comment into an HTML body, so plain-text line breaks are usually lost; use <br> for line breaks or <p> for paragraphs."
|
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",
|