@softeria/ms-365-mcp-server 0.182.1 → 0.182.3
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/.gitattributes +1 -0
- package/PRESETS.md +6 -6
- package/README.md +1 -1
- package/dist/__tests__/log-safe.test.js +153 -0
- package/dist/app-mode.js +1 -0
- package/dist/attachment-route.js +11 -4
- package/dist/audit-log.js +2 -0
- package/dist/auth.js +4 -1
- package/dist/crash-logging.js +27 -13
- package/dist/endpoints.json +1 -1
- package/dist/generated/client.js +1 -1
- package/dist/graph-client.js +6 -5
- package/dist/graph-tools.js +25 -14
- package/dist/lib/bounded-file-transport.js +99 -0
- package/dist/lib/log-limits.js +12 -0
- package/dist/lib/log-safe.js +405 -0
- package/dist/lib/microsoft-auth.js +99 -1
- package/dist/logger.js +11 -4
- package/dist/server.js +38 -5
- package/package.json +1 -1
- package/src/endpoints.json +1 -1
package/.gitattributes
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* text=auto eol=lf
|
package/PRESETS.md
CHANGED
|
@@ -304,10 +304,10 @@ Tools (370):
|
|
|
304
304
|
- `list-sharepoint-site-list-items`
|
|
305
305
|
- `list-sharepoint-site-list-items-delta`
|
|
306
306
|
- `list-sharepoint-site-lists`
|
|
307
|
+
- `list-sharepoint-site-onenote-child-section-groups`
|
|
307
308
|
- `list-sharepoint-site-onenote-notebook-section-groups`
|
|
308
309
|
- `list-sharepoint-site-onenote-notebook-sections`
|
|
309
310
|
- `list-sharepoint-site-onenote-notebooks`
|
|
310
|
-
- `list-sharepoint-site-onenote-section-group-section-groups`
|
|
311
311
|
- `list-sharepoint-site-onenote-section-group-sections`
|
|
312
312
|
- `list-sharepoint-site-onenote-section-pages`
|
|
313
313
|
- `list-specific-calendar-events`
|
|
@@ -632,10 +632,10 @@ Tools (180):
|
|
|
632
632
|
- `list-sharepoint-site-list-items`
|
|
633
633
|
- `list-sharepoint-site-list-items-delta`
|
|
634
634
|
- `list-sharepoint-site-lists`
|
|
635
|
+
- `list-sharepoint-site-onenote-child-section-groups`
|
|
635
636
|
- `list-sharepoint-site-onenote-notebook-section-groups`
|
|
636
637
|
- `list-sharepoint-site-onenote-notebook-sections`
|
|
637
638
|
- `list-sharepoint-site-onenote-notebooks`
|
|
638
|
-
- `list-sharepoint-site-onenote-section-group-section-groups`
|
|
639
639
|
- `list-sharepoint-site-onenote-section-group-sections`
|
|
640
640
|
- `list-sharepoint-site-onenote-section-pages`
|
|
641
641
|
- `list-specific-calendar-events`
|
|
@@ -1149,10 +1149,10 @@ Tools (29):
|
|
|
1149
1149
|
- `list-onenote-pages`
|
|
1150
1150
|
- `list-onenote-section-groups`
|
|
1151
1151
|
- `list-onenote-section-pages`
|
|
1152
|
+
- `list-sharepoint-site-onenote-child-section-groups`
|
|
1152
1153
|
- `list-sharepoint-site-onenote-notebook-section-groups`
|
|
1153
1154
|
- `list-sharepoint-site-onenote-notebook-sections`
|
|
1154
1155
|
- `list-sharepoint-site-onenote-notebooks`
|
|
1155
|
-
- `list-sharepoint-site-onenote-section-group-section-groups`
|
|
1156
1156
|
- `list-sharepoint-site-onenote-section-group-sections`
|
|
1157
1157
|
- `list-sharepoint-site-onenote-section-pages`
|
|
1158
1158
|
- `update-onenote-page-content`
|
|
@@ -1183,10 +1183,10 @@ Tools (17):
|
|
|
1183
1183
|
- `list-onenote-pages`
|
|
1184
1184
|
- `list-onenote-section-groups`
|
|
1185
1185
|
- `list-onenote-section-pages`
|
|
1186
|
+
- `list-sharepoint-site-onenote-child-section-groups`
|
|
1186
1187
|
- `list-sharepoint-site-onenote-notebook-section-groups`
|
|
1187
1188
|
- `list-sharepoint-site-onenote-notebook-sections`
|
|
1188
1189
|
- `list-sharepoint-site-onenote-notebooks`
|
|
1189
|
-
- `list-sharepoint-site-onenote-section-group-section-groups`
|
|
1190
1190
|
- `list-sharepoint-site-onenote-section-group-sections`
|
|
1191
1191
|
- `list-sharepoint-site-onenote-section-pages`
|
|
1192
1192
|
|
|
@@ -2230,10 +2230,10 @@ Tools (190):
|
|
|
2230
2230
|
- `list-sharepoint-site-list-items`
|
|
2231
2231
|
- `list-sharepoint-site-list-items-delta`
|
|
2232
2232
|
- `list-sharepoint-site-lists`
|
|
2233
|
+
- `list-sharepoint-site-onenote-child-section-groups`
|
|
2233
2234
|
- `list-sharepoint-site-onenote-notebook-section-groups`
|
|
2234
2235
|
- `list-sharepoint-site-onenote-notebook-sections`
|
|
2235
2236
|
- `list-sharepoint-site-onenote-notebooks`
|
|
2236
|
-
- `list-sharepoint-site-onenote-section-group-section-groups`
|
|
2237
2237
|
- `list-sharepoint-site-onenote-section-group-sections`
|
|
2238
2238
|
- `list-sharepoint-site-onenote-section-pages`
|
|
2239
2239
|
- `list-team-channels`
|
|
@@ -2447,10 +2447,10 @@ Tools (110):
|
|
|
2447
2447
|
- `list-sharepoint-site-list-items`
|
|
2448
2448
|
- `list-sharepoint-site-list-items-delta`
|
|
2449
2449
|
- `list-sharepoint-site-lists`
|
|
2450
|
+
- `list-sharepoint-site-onenote-child-section-groups`
|
|
2450
2451
|
- `list-sharepoint-site-onenote-notebook-section-groups`
|
|
2451
2452
|
- `list-sharepoint-site-onenote-notebook-sections`
|
|
2452
2453
|
- `list-sharepoint-site-onenote-notebooks`
|
|
2453
|
-
- `list-sharepoint-site-onenote-section-group-section-groups`
|
|
2454
2454
|
- `list-sharepoint-site-onenote-section-group-sections`
|
|
2455
2455
|
- `list-sharepoint-site-onenote-section-pages`
|
|
2456
2456
|
- `list-team-channels`
|
package/README.md
CHANGED
|
@@ -883,7 +883,7 @@ Environment variables:
|
|
|
883
883
|
- `MS365_MCP_GRAPH_BASE_URL=<url>`: Send Graph API requests to this base URL instead of the cloud's `graph.microsoft.com` (e.g. `http://127.0.0.1:10255/tenant-a/graph` for an egress proxy that originates TLS itself). Absolute http(s) URL without query or fragment; a path prefix is kept, so requests go to `<url>/v1.0/...`. The login authority and the On-Behalf-Of token resource are unchanged. Two things bypass it: `get-download-url` returns Graph's pre-authenticated SharePoint URL, and the `302` from `/content` points straight at SharePoint, so whoever follows either connects to SharePoint directly; if you control egress, allow those SharePoint hosts or disable those tools. Not read from `.env`
|
|
884
884
|
- `LOG_LEVEL`: Set logging level (default: 'info')
|
|
885
885
|
- `SILENT=true|1`: Disable console output
|
|
886
|
-
- `MS365_MCP_REDACT_PII=false|0`: Disable scrubbing of JWTs, Bearer headers, OAuth token fields, and email addresses from log messages (default: enabled). The server handles live Graph bearer tokens, so redaction is on unless you opt out for fully verbose local debugging.
|
|
886
|
+
- `MS365_MCP_REDACT_PII=false|0`: Disable scrubbing of JWTs, Bearer headers, OAuth token fields, and email addresses from log messages, and log tool parameters, request bodies, URLs, error messages and crash dumps in full instead of by shape only (default: enabled). The server handles live Graph bearer tokens, so redaction is on unless you opt out for fully verbose local debugging.
|
|
887
887
|
- `MS365_MCP_CLIENT_ID`: Custom Azure app client ID (defaults to built-in app)
|
|
888
888
|
- `MS365_MCP_TENANT_ID`: Custom tenant ID (defaults to 'common' for multi-tenant). **Personal Microsoft accounts should set this to `consumers`** - as of June 2026, refresh tokens issued via the default 'common' authority are rejected at the first refresh, so sessions die roughly an hour after login
|
|
889
889
|
- `MS365_MCP_OAUTH_TOKEN`: Pre-existing OAuth token for Microsoft Graph API (BYOT method)
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, it, expect } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
describeShape,
|
|
4
|
+
describeText,
|
|
5
|
+
describeUrl,
|
|
6
|
+
describeError,
|
|
7
|
+
describeStack,
|
|
8
|
+
serializedSize,
|
|
9
|
+
summarizeError
|
|
10
|
+
} from "../lib/log-safe.js";
|
|
11
|
+
import { dumpError } from "../crash-logging.js";
|
|
12
|
+
import { GraphApiError } from "../graph-client.js";
|
|
13
|
+
const SECRET = "SENTINEL-the quarterly numbers are bad, do not forward";
|
|
14
|
+
describe("log-safe", () => {
|
|
15
|
+
it("describes parameters by shape, never by value", () => {
|
|
16
|
+
const out = describeShape({
|
|
17
|
+
top: 10,
|
|
18
|
+
filter: `subject eq '${SECRET}'`,
|
|
19
|
+
search: `"${SECRET}"`,
|
|
20
|
+
body: { subject: SECRET, body: { contentType: "html", content: SECRET } },
|
|
21
|
+
messageIds: [SECRET, SECRET],
|
|
22
|
+
confirm: true,
|
|
23
|
+
skiptoken: null
|
|
24
|
+
});
|
|
25
|
+
expect(out).not.toContain(SECRET);
|
|
26
|
+
expect(out).toContain("top: 10");
|
|
27
|
+
expect(out).toContain(`filter: string(${SECRET.length + 13})`);
|
|
28
|
+
expect(out).toContain("body: object(2 keys)");
|
|
29
|
+
expect(out).toContain("messageIds: array(2)");
|
|
30
|
+
expect(out).toContain("confirm: true");
|
|
31
|
+
expect(out).toContain("skiptoken: null");
|
|
32
|
+
});
|
|
33
|
+
it("counts keys that are not on the known list instead of naming them", () => {
|
|
34
|
+
const out = describeShape({ [SECRET]: "x", top: 1, [`${SECRET}-2`]: 2 });
|
|
35
|
+
expect(out).toBe("{top: 1, +2 other}");
|
|
36
|
+
});
|
|
37
|
+
it("describes a string or array at the top level without its content", () => {
|
|
38
|
+
expect(describeShape(SECRET)).toBe(`string(${SECRET.length})`);
|
|
39
|
+
expect(describeShape([SECRET])).toBe("array(1)");
|
|
40
|
+
});
|
|
41
|
+
it("masks every path segment that is not a fixed Graph word", () => {
|
|
42
|
+
expect(describeUrl(`/me/drive/root:/${SECRET}.txt:/content`)).toBe(
|
|
43
|
+
"/me/drive/root:/{\u2026}/content"
|
|
44
|
+
);
|
|
45
|
+
expect(describeUrl("/me/messages/AAMkAGVj-abc=/attachments/ATT1/$value")).toBe(
|
|
46
|
+
"/me/messages/{\u2026}/attachments/{\u2026}/$value"
|
|
47
|
+
);
|
|
48
|
+
expect(describeUrl(`/users/${SECRET}@contoso.com/mailFolders/inbox/messages`)).toBe(
|
|
49
|
+
"/users/{\u2026}/mailFolders/inbox/messages"
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
it("drops the query string and lists only $-prefixed OData names", () => {
|
|
53
|
+
const url = `https://graph.microsoft.com/v1.0/me/messages?$search=%22${encodeURIComponent(SECRET)}%22&$top=5&${encodeURIComponent(SECRET)}=x`;
|
|
54
|
+
const out = describeUrl(url);
|
|
55
|
+
expect(out).not.toContain(SECRET);
|
|
56
|
+
expect(out).not.toContain(encodeURIComponent(SECRET));
|
|
57
|
+
expect(out).toBe(
|
|
58
|
+
"https://graph.microsoft.com/v1.0/me/messages [query: $search, $top, +1 other]"
|
|
59
|
+
);
|
|
60
|
+
expect(describeUrl("/me/messages")).toBe("/me/messages");
|
|
61
|
+
});
|
|
62
|
+
it("never throws on malformed input", () => {
|
|
63
|
+
expect(describeUrl("/me/messages?%malformed=x&%E0%A4%A=y")).toBe(
|
|
64
|
+
"/me/messages [query: +2 other]"
|
|
65
|
+
);
|
|
66
|
+
expect(describeUrl("")).toBe("");
|
|
67
|
+
expect(describeUrl(`http://${SECRET}/me`)).toBe("{origin}/me");
|
|
68
|
+
expect(describeUrl(void 0)).toBe("undefined");
|
|
69
|
+
});
|
|
70
|
+
it("describes a Graph error by status and code, never by message", () => {
|
|
71
|
+
const err = new GraphApiError(`Invalid filter clause: ${SECRET}`, 400, "BadRequest");
|
|
72
|
+
expect(describeError(err)).toBe("GraphApiError status=400 code=BadRequest");
|
|
73
|
+
});
|
|
74
|
+
it("shows only known error names, HTTP statuses and short codes", () => {
|
|
75
|
+
const named = new Error(`connect failed while sending ${SECRET}`);
|
|
76
|
+
named.name = SECRET;
|
|
77
|
+
expect(describeError(Object.assign(named, { code: SECRET, status: 999 }))).toBe(
|
|
78
|
+
`Error code=unlisted(${SECRET.length})`
|
|
79
|
+
);
|
|
80
|
+
expect(describeError(Object.assign(new Error("x"), { code: 7000215 }))).toBe(
|
|
81
|
+
"Error code=7000215"
|
|
82
|
+
);
|
|
83
|
+
expect(describeError(Object.assign(new Error("x"), { code: "ECONNRESET", status: 502 }))).toBe(
|
|
84
|
+
"Error status=502 code=ECONNRESET"
|
|
85
|
+
);
|
|
86
|
+
expect(describeError(SECRET)).toBe("non-error(string)");
|
|
87
|
+
});
|
|
88
|
+
it("keeps stack frames but not the message line", () => {
|
|
89
|
+
const frames = describeStack(new Error(`boom ${SECRET}`));
|
|
90
|
+
expect(frames.length).toBeGreaterThan(0);
|
|
91
|
+
for (const f of frames) {
|
|
92
|
+
expect(f.startsWith("at ")).toBe(true);
|
|
93
|
+
expect(f).not.toContain(SECRET);
|
|
94
|
+
}
|
|
95
|
+
expect(describeStack("x")).toEqual([]);
|
|
96
|
+
});
|
|
97
|
+
it("reports a serialized size without the content", () => {
|
|
98
|
+
expect(serializedSize({ a: "bc" })).toBe(Buffer.byteLength('{"a":"bc"}'));
|
|
99
|
+
const cyclic = {};
|
|
100
|
+
cyclic.self = cyclic;
|
|
101
|
+
expect(serializedSize(cyclic)).toBe(-1);
|
|
102
|
+
});
|
|
103
|
+
it("describes free text by length", () => {
|
|
104
|
+
expect(describeText(SECRET)).toBe(`(${SECRET.length} chars)`);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
describe("log-safe with MS365_MCP_REDACT_PII=false", () => {
|
|
108
|
+
const prev = process.env.MS365_MCP_REDACT_PII;
|
|
109
|
+
beforeEach(() => {
|
|
110
|
+
process.env.MS365_MCP_REDACT_PII = "false";
|
|
111
|
+
});
|
|
112
|
+
afterEach(() => {
|
|
113
|
+
if (prev === void 0) delete process.env.MS365_MCP_REDACT_PII;
|
|
114
|
+
else process.env.MS365_MCP_REDACT_PII = prev;
|
|
115
|
+
});
|
|
116
|
+
it("logs values, URLs and free text in full", () => {
|
|
117
|
+
const params = { filter: `subject eq '${SECRET}'`, [SECRET]: 1 };
|
|
118
|
+
expect(describeShape(params)).toBe(JSON.stringify(params));
|
|
119
|
+
const cyclic = {};
|
|
120
|
+
cyclic.self = cyclic;
|
|
121
|
+
expect(describeShape(cyclic)).toBe("[unserializable: TypeError]");
|
|
122
|
+
const url = `/me/drive/root:/${SECRET}.txt:/content?$search=${SECRET}`;
|
|
123
|
+
expect(describeUrl(url)).toBe(url);
|
|
124
|
+
expect(describeText(SECRET)).toBe(SECRET);
|
|
125
|
+
});
|
|
126
|
+
it("logs the real error name, code and message", () => {
|
|
127
|
+
const err = new GraphApiError(
|
|
128
|
+
`Insufficient privileges: ${SECRET}`,
|
|
129
|
+
403,
|
|
130
|
+
"Authorization_RequestDenied"
|
|
131
|
+
);
|
|
132
|
+
expect(describeError(err)).toBe(
|
|
133
|
+
`GraphApiError status=403 code=Authorization_RequestDenied: Insufficient privileges: ${SECRET}`
|
|
134
|
+
);
|
|
135
|
+
expect(describeError(SECRET)).toBe(JSON.stringify(SECRET));
|
|
136
|
+
});
|
|
137
|
+
it("keeps the self-test summary short, since /health returns it", () => {
|
|
138
|
+
const err = Object.assign(new Error(`connect ${SECRET}`), { code: "ECONNREFUSED" });
|
|
139
|
+
expect(summarizeError(err)).toBe("Error code=ECONNREFUSED");
|
|
140
|
+
});
|
|
141
|
+
it("dumps a crash with message, properties and cause", () => {
|
|
142
|
+
const crash = Object.assign(new Error(`boom ${SECRET}`), {
|
|
143
|
+
response: { body: SECRET },
|
|
144
|
+
cause: new Error(`inner ${SECRET}`)
|
|
145
|
+
});
|
|
146
|
+
expect(dumpError(crash)).toMatchObject({
|
|
147
|
+
name: "Error",
|
|
148
|
+
message: `boom ${SECRET}`,
|
|
149
|
+
properties: { response: { body: SECRET } },
|
|
150
|
+
cause: { message: `inner ${SECRET}` }
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
});
|
package/dist/app-mode.js
CHANGED
package/dist/attachment-route.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Readable } from "node:stream";
|
|
2
2
|
import { pipeline } from "node:stream/promises";
|
|
3
3
|
import logger from "./logger.js";
|
|
4
|
+
import { describeError, describeUrl } from "./lib/log-safe.js";
|
|
4
5
|
import {
|
|
5
6
|
isPlainGraphPath,
|
|
6
7
|
TICKET_PARAM
|
|
@@ -105,7 +106,7 @@ function createAttachmentHandler(deps) {
|
|
|
105
106
|
stream = await graphClient.downloadStream(ticket.target, { accessToken });
|
|
106
107
|
} catch (error) {
|
|
107
108
|
logger.error(
|
|
108
|
-
`Attachment redemption failed for ${ticket.target}: ${error
|
|
109
|
+
`Attachment redemption failed for ${describeUrl(ticket.target)}: ${describeError(error)}`
|
|
109
110
|
);
|
|
110
111
|
res.status(502).type("text/plain").send("Upstream fetch failed");
|
|
111
112
|
return;
|
|
@@ -128,7 +129,9 @@ function createAttachmentHandler(deps) {
|
|
|
128
129
|
try {
|
|
129
130
|
await pipeline(Readable.fromWeb(stream.body), res);
|
|
130
131
|
} catch (error) {
|
|
131
|
-
logger.error(
|
|
132
|
+
logger.error(
|
|
133
|
+
`Attachment stream aborted for ${describeUrl(ticket.target)}: ${describeError(error)}`
|
|
134
|
+
);
|
|
132
135
|
res.destroy();
|
|
133
136
|
}
|
|
134
137
|
};
|
|
@@ -179,7 +182,9 @@ function createAttachmentUploadHandler(deps) {
|
|
|
179
182
|
accessToken = ticket.kind === "request-token" ? ticket.accessToken : await deps.authManager.getTokenForAccount(ticket.accountName);
|
|
180
183
|
if (!accessToken) throw new Error("No access token for this ticket");
|
|
181
184
|
} catch (error) {
|
|
182
|
-
logger.error(
|
|
185
|
+
logger.error(
|
|
186
|
+
`Attachment upload failed for ${describeUrl(ticket.target)}: ${describeError(error)}`
|
|
187
|
+
);
|
|
183
188
|
res.status(502).type("text/plain").send("Upstream upload failed");
|
|
184
189
|
return;
|
|
185
190
|
}
|
|
@@ -233,7 +238,9 @@ function createAttachmentUploadHandler(deps) {
|
|
|
233
238
|
...ticket.contentId ? { contentId: ticket.contentId } : {}
|
|
234
239
|
});
|
|
235
240
|
} catch (error) {
|
|
236
|
-
logger.error(
|
|
241
|
+
logger.error(
|
|
242
|
+
`Attachment upload failed for ${describeUrl(ticket.target)}: ${describeError(error)}`
|
|
243
|
+
);
|
|
237
244
|
if (!res.headersSent) res.status(502).type("text/plain").send("Upstream upload failed");
|
|
238
245
|
}
|
|
239
246
|
};
|
package/dist/audit-log.js
CHANGED
|
@@ -35,6 +35,8 @@ const auditLogger = winston.createLogger({
|
|
|
35
35
|
stderrLevels: ["info"],
|
|
36
36
|
silent: process.env.SILENT === "true" || process.env.SILENT === "1" || process.env.VITEST === "true"
|
|
37
37
|
}),
|
|
38
|
+
// Not bounded like the diagnostic logs: this is the audit trail, so when old
|
|
39
|
+
// records go is up to the operator.
|
|
38
40
|
new winston.transports.File({
|
|
39
41
|
filename: auditLogPath,
|
|
40
42
|
options: { flags: "a", mode: FILE_MODE }
|
package/dist/auth.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AuthError, PublicClientApplication } from "@azure/msal-node";
|
|
2
2
|
import logger from "./logger.js";
|
|
3
|
+
import { describeText } from "./lib/log-safe.js";
|
|
3
4
|
import { readFileSync } from "fs";
|
|
4
5
|
import { fileURLToPath } from "url";
|
|
5
6
|
import path from "path";
|
|
@@ -974,7 +975,9 @@ class AuthManager {
|
|
|
974
975
|
};
|
|
975
976
|
} else {
|
|
976
977
|
const errorText = await response.text();
|
|
977
|
-
logger.error(
|
|
978
|
+
logger.error(
|
|
979
|
+
`Graph API user data fetch failed: ${response.status} ${describeText(errorText)}`
|
|
980
|
+
);
|
|
978
981
|
return {
|
|
979
982
|
success: false,
|
|
980
983
|
message: `Login successful but Graph API access failed: ${response.status}`
|
package/dist/crash-logging.js
CHANGED
|
@@ -1,28 +1,42 @@
|
|
|
1
|
+
import { redactionEnabled } from "./lib/log-redactor.js";
|
|
2
|
+
import { describeError, describeStack } from "./lib/log-safe.js";
|
|
1
3
|
function dumpError(reason, depth = 0) {
|
|
2
4
|
if (depth > 5) {
|
|
3
5
|
return { truncated: true };
|
|
4
6
|
}
|
|
7
|
+
if (!redactionEnabled()) return fullDump(reason, depth);
|
|
5
8
|
if (reason instanceof Error) {
|
|
6
9
|
const dump = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
message: reason.message,
|
|
10
|
-
stack: reason.stack
|
|
10
|
+
summary: describeError(reason),
|
|
11
|
+
stack: describeStack(reason)
|
|
11
12
|
};
|
|
12
|
-
const properties = {};
|
|
13
|
-
for (const key of Object.getOwnPropertyNames(reason)) {
|
|
14
|
-
if (key === "name" || key === "message" || key === "stack" || key === "cause") continue;
|
|
15
|
-
properties[key] = reason[key];
|
|
16
|
-
}
|
|
17
|
-
if (Object.keys(properties).length > 0) {
|
|
18
|
-
dump.properties = properties;
|
|
19
|
-
}
|
|
20
13
|
if ("cause" in reason && reason.cause !== void 0) {
|
|
21
14
|
dump.cause = dumpError(reason.cause, depth + 1);
|
|
22
15
|
}
|
|
23
16
|
return dump;
|
|
24
17
|
}
|
|
25
|
-
return { type: typeof reason
|
|
18
|
+
return { type: typeof reason };
|
|
19
|
+
}
|
|
20
|
+
function fullDump(reason, depth) {
|
|
21
|
+
if (!(reason instanceof Error)) return { type: typeof reason, value: reason };
|
|
22
|
+
const dump = {
|
|
23
|
+
name: reason.name,
|
|
24
|
+
constructor: reason.constructor?.name,
|
|
25
|
+
message: reason.message,
|
|
26
|
+
stack: reason.stack
|
|
27
|
+
};
|
|
28
|
+
const properties = {};
|
|
29
|
+
for (const key of Object.getOwnPropertyNames(reason)) {
|
|
30
|
+
if (key === "name" || key === "message" || key === "stack" || key === "cause") continue;
|
|
31
|
+
properties[key] = reason[key];
|
|
32
|
+
}
|
|
33
|
+
if (Object.keys(properties).length > 0) {
|
|
34
|
+
dump.properties = properties;
|
|
35
|
+
}
|
|
36
|
+
if ("cause" in reason && reason.cause !== void 0) {
|
|
37
|
+
dump.cause = dumpError(reason.cause, depth + 1);
|
|
38
|
+
}
|
|
39
|
+
return dump;
|
|
26
40
|
}
|
|
27
41
|
function getActiveResources() {
|
|
28
42
|
const fn = process.getActiveResourcesInfo;
|
package/dist/endpoints.json
CHANGED
|
@@ -1334,7 +1334,7 @@
|
|
|
1334
1334
|
{
|
|
1335
1335
|
"pathPattern": "/sites/{site-id}/onenote/sectionGroups/{sectionGroup-id}/sectionGroups",
|
|
1336
1336
|
"method": "get",
|
|
1337
|
-
"toolName": "list-sharepoint-site-onenote-
|
|
1337
|
+
"toolName": "list-sharepoint-site-onenote-child-section-groups",
|
|
1338
1338
|
"presets": ["onenote", "work"],
|
|
1339
1339
|
"workScopes": ["Notes.Read.All"]
|
|
1340
1340
|
},
|
package/dist/generated/client.js
CHANGED
|
@@ -14343,7 +14343,7 @@ The same item might appear more than once in a delta feed, for various reasons.
|
|
|
14343
14343
|
{
|
|
14344
14344
|
method: "get",
|
|
14345
14345
|
path: "/sites/:siteId/onenote/sectionGroups/:sectionGroupId/sectionGroups",
|
|
14346
|
-
alias: "list-sharepoint-site-onenote-
|
|
14346
|
+
alias: "list-sharepoint-site-onenote-child-section-groups",
|
|
14347
14347
|
description: `The section groups in the section. Read-only. Nullable.`,
|
|
14348
14348
|
requestFormat: "json",
|
|
14349
14349
|
parameters: [
|
package/dist/graph-client.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import logger from "./logger.js";
|
|
2
|
+
import { describeError, describeShape, describeUrl } from "./lib/log-safe.js";
|
|
2
3
|
import { encode as toonEncode } from "@toon-format/toon";
|
|
3
4
|
import { getGraphBaseUrl } from "./cloud-config.js";
|
|
4
5
|
import { getRequestTokens } from "./request-context.js";
|
|
@@ -246,7 +247,7 @@ class GraphClient {
|
|
|
246
247
|
}
|
|
247
248
|
return { data: result, metadata };
|
|
248
249
|
} catch (error) {
|
|
249
|
-
logger.error(
|
|
250
|
+
logger.error(`Microsoft Graph API request failed: ${describeError(error)}`);
|
|
250
251
|
throw error;
|
|
251
252
|
}
|
|
252
253
|
}
|
|
@@ -340,7 +341,7 @@ class GraphClient {
|
|
|
340
341
|
httpStatus: response.status
|
|
341
342
|
};
|
|
342
343
|
} catch (error) {
|
|
343
|
-
logger.error(
|
|
344
|
+
logger.error(`Microsoft Graph file download failed: ${describeError(error)}`);
|
|
344
345
|
throw error;
|
|
345
346
|
} finally {
|
|
346
347
|
await fileHandle.close().catch(() => void 0);
|
|
@@ -404,7 +405,7 @@ class GraphClient {
|
|
|
404
405
|
async performRequest(endpoint, accessToken, options) {
|
|
405
406
|
const apiVersion = options.apiVersion || "v1.0";
|
|
406
407
|
const url = `${getGraphBaseUrl(this.secrets.cloudType)}/${apiVersion}${endpoint}`;
|
|
407
|
-
logger.info(`[GRAPH CLIENT]
|
|
408
|
+
logger.info(`[GRAPH CLIENT] Request ${options.method || "GET"} ${describeUrl(url)}`);
|
|
408
409
|
const method = options.method || "GET";
|
|
409
410
|
const signedBody = applyMessageSignoffToRequest(method, endpoint, options.body);
|
|
410
411
|
const body = applyBatchContentType(method, endpoint, signedBody);
|
|
@@ -448,7 +449,7 @@ class GraphClient {
|
|
|
448
449
|
try {
|
|
449
450
|
const { accessToken: _redacted, ...safeOptions } = options;
|
|
450
451
|
logger.info(
|
|
451
|
-
`Calling ${endpoint} with options: ${
|
|
452
|
+
`Calling ${describeUrl(endpoint)} [${options.method || "GET"}] with options: ${describeShape(safeOptions)}${_redacted ? " [accessToken=REDACTED]" : ""}`
|
|
452
453
|
);
|
|
453
454
|
const { data, metadata } = await this.makeRequestWithMetadata(endpoint, options);
|
|
454
455
|
const outputFormat = options.forceJsonOutput ? "json" : this.outputFormat;
|
|
@@ -458,7 +459,7 @@ class GraphClient {
|
|
|
458
459
|
metadata
|
|
459
460
|
);
|
|
460
461
|
} catch (error) {
|
|
461
|
-
logger.error(`Error in Graph API request: ${error}`);
|
|
462
|
+
logger.error(`Error in Graph API request: ${describeError(error)}`);
|
|
462
463
|
const metadata = error instanceof GraphApiError ? definedMetadata({
|
|
463
464
|
http_status: error.httpStatus,
|
|
464
465
|
error_code: error.graphErrorCode
|
package/dist/graph-tools.js
CHANGED
|
@@ -92,6 +92,13 @@ import {
|
|
|
92
92
|
userFieldEnforcement
|
|
93
93
|
} from "./lib/user-field-policy.js";
|
|
94
94
|
import logger from "./logger.js";
|
|
95
|
+
import {
|
|
96
|
+
describeError,
|
|
97
|
+
describeShape,
|
|
98
|
+
describeText,
|
|
99
|
+
describeUrl,
|
|
100
|
+
serializedSize
|
|
101
|
+
} from "./lib/log-safe.js";
|
|
95
102
|
import { getRequestTokens } from "./request-context.js";
|
|
96
103
|
import { TOOL_CATEGORIES } from "./tool-categories.js";
|
|
97
104
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -309,7 +316,9 @@ function normalizeSearchQueryParam(queryParams, path2, toolAlias) {
|
|
|
309
316
|
if (inner === "") return noSearchableText();
|
|
310
317
|
const normalized = `"${inner}"`;
|
|
311
318
|
if (normalized !== raw) {
|
|
312
|
-
logger.info(
|
|
319
|
+
logger.info(
|
|
320
|
+
`Auto-corrected parameter '$search': normalized KQL quoting ${describeText(normalized)}`
|
|
321
|
+
);
|
|
313
322
|
queryParams["$search"] = normalized;
|
|
314
323
|
}
|
|
315
324
|
}
|
|
@@ -1904,11 +1913,7 @@ function hasOwn(obj, key) {
|
|
|
1904
1913
|
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
1905
1914
|
}
|
|
1906
1915
|
function describeParamsForLog(params) {
|
|
1907
|
-
|
|
1908
|
-
return JSON.stringify(params);
|
|
1909
|
-
} catch (error) {
|
|
1910
|
-
return `[unserializable: ${error instanceof Error ? error.name : "unknown error"}]`;
|
|
1911
|
-
}
|
|
1916
|
+
return describeShape(params);
|
|
1912
1917
|
}
|
|
1913
1918
|
function escapeIfStringLiteral(template, names, value) {
|
|
1914
1919
|
const quoted = names.some((n) => template.includes(`'{${n}}'`) || template.includes(`':${n}'`));
|
|
@@ -2111,7 +2116,7 @@ async function executeGraphTool(tool, config, graphClient, params, authManager,
|
|
|
2111
2116
|
}
|
|
2112
2117
|
} else if (paramName === "body") {
|
|
2113
2118
|
body = paramValue;
|
|
2114
|
-
logger.info(`Set body param: ${
|
|
2119
|
+
logger.info(`Set body param: ${describeShape(body)} (${serializedSize(body)} bytes)`);
|
|
2115
2120
|
} else if (path2.includes(`:${paramName}`) || path2.includes(`{${paramName}}`) || path2.includes(`:${camelCaseParamName}`) || path2.includes(`{${camelCaseParamName}}`)) {
|
|
2116
2121
|
const encodedValue = encodeURIComponent(
|
|
2117
2122
|
escapeIfStringLiteral(tool.path, [paramName, camelCaseParamName], paramValue)
|
|
@@ -2127,7 +2132,9 @@ async function executeGraphTool(tool, config, graphClient, params, authManager,
|
|
|
2127
2132
|
}
|
|
2128
2133
|
} else if (isOdataParam) {
|
|
2129
2134
|
queryParams[fixedParamName] = `${paramValue}`;
|
|
2130
|
-
logger.info(
|
|
2135
|
+
logger.info(
|
|
2136
|
+
`OData param fallback: forwarded ${fixedParamName} ${describeText(String(paramValue))}`
|
|
2137
|
+
);
|
|
2131
2138
|
} else if (bodyShape && (hasOwn(bodyShape, paramName) || hasOwn(bodyShape, camelCaseParamName)) && !READ_ONLY_BODY_FIELDS.has(hasOwn(bodyShape, paramName) ? paramName : camelCaseParamName)) {
|
|
2132
2139
|
const fieldName = hasOwn(bodyShape, paramName) ? paramName : camelCaseParamName;
|
|
2133
2140
|
strayBodyFields[fieldName] = paramValue;
|
|
@@ -2135,7 +2142,9 @@ async function executeGraphTool(tool, config, graphClient, params, authManager,
|
|
|
2135
2142
|
`Body field fallback: merging top-level param '${fieldName}' into request body`
|
|
2136
2143
|
);
|
|
2137
2144
|
} else {
|
|
2138
|
-
logger.warn(
|
|
2145
|
+
logger.warn(
|
|
2146
|
+
`Dropping unrecognized parameter ${describeText(paramName)} for tool ${tool.alias}`
|
|
2147
|
+
);
|
|
2139
2148
|
}
|
|
2140
2149
|
}
|
|
2141
2150
|
if (!isUnalteredGraphPath(path2)) {
|
|
@@ -2333,7 +2342,7 @@ async function executeGraphTool(tool, config, graphClient, params, authManager,
|
|
|
2333
2342
|
});
|
|
2334
2343
|
const { accessToken: _redacted, ...safeOptions } = options;
|
|
2335
2344
|
logger.info(
|
|
2336
|
-
`Making graph request to ${path2} with options: ${
|
|
2345
|
+
`Making graph request to ${describeUrl(path2)} [${options.method || "GET"}] with options: ${describeShape(safeOptions)}${_redacted ? " [accessToken=REDACTED]" : ""}`
|
|
2337
2346
|
);
|
|
2338
2347
|
const fetchAllPages = params.fetchAllPages === true;
|
|
2339
2348
|
const paginationEnabled = paginationAllowed();
|
|
@@ -2389,7 +2398,7 @@ async function executeGraphTool(tool, config, graphClient, params, authManager,
|
|
|
2389
2398
|
const maxItems = positiveIntFromEnv("MS365_MCP_MAX_ITEMS", DEFAULT_MAX_ITEMS);
|
|
2390
2399
|
let deltaLink = combinedResponse["@odata.deltaLink"];
|
|
2391
2400
|
while (nextLink && pageCount < maxPages && allItems.length < maxItems) {
|
|
2392
|
-
logger.info(`Fetching page ${pageCount + 1} from: ${nextLink}`);
|
|
2401
|
+
logger.info(`Fetching page ${pageCount + 1} from: ${describeUrl(nextLink)}`);
|
|
2393
2402
|
const url = new URL(nextLink);
|
|
2394
2403
|
const nextPath = url.pathname.replace(/^\/(v1\.0|beta)/, "") + url.search;
|
|
2395
2404
|
const nextOptions = { ...options };
|
|
@@ -2450,7 +2459,7 @@ async function executeGraphTool(tool, config, graphClient, params, authManager,
|
|
|
2450
2459
|
}
|
|
2451
2460
|
}
|
|
2452
2461
|
} catch (e) {
|
|
2453
|
-
logger.error(`Error during pagination: ${e}`);
|
|
2462
|
+
logger.error(`Error during pagination: ${describeError(e)}`);
|
|
2454
2463
|
}
|
|
2455
2464
|
if (combinedResponse !== void 0) {
|
|
2456
2465
|
const merged = applyMemberFilter(
|
|
@@ -2495,7 +2504,9 @@ async function executeGraphTool(tool, config, graphClient, params, authManager,
|
|
|
2495
2504
|
logger.info(`Response contains ${jsonResponse.value.length} items`);
|
|
2496
2505
|
}
|
|
2497
2506
|
if (jsonResponse["@odata.nextLink"]) {
|
|
2498
|
-
logger.info(
|
|
2507
|
+
logger.info(
|
|
2508
|
+
`Response has pagination nextLink: ${describeUrl(jsonResponse["@odata.nextLink"])}`
|
|
2509
|
+
);
|
|
2499
2510
|
}
|
|
2500
2511
|
} catch {
|
|
2501
2512
|
}
|
|
@@ -2522,7 +2533,7 @@ async function executeGraphTool(tool, config, graphClient, params, authManager,
|
|
|
2522
2533
|
};
|
|
2523
2534
|
} catch (error) {
|
|
2524
2535
|
const err = error;
|
|
2525
|
-
logger.error(`Error in tool ${tool.alias}: ${error
|
|
2536
|
+
logger.error(`Error in tool ${tool.alias}: ${describeError(error)}`);
|
|
2526
2537
|
auditLog({
|
|
2527
2538
|
event: "tool.call",
|
|
2528
2539
|
request_id: requestId,
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import winston from "winston";
|
|
4
|
+
const Transport = winston.Transport;
|
|
5
|
+
const MIN_BYTES = 1024;
|
|
6
|
+
class BoundedFileTransport extends Transport {
|
|
7
|
+
constructor(opts) {
|
|
8
|
+
super(opts);
|
|
9
|
+
this.stopped = false;
|
|
10
|
+
this.filename = opts.filename;
|
|
11
|
+
this.maxBytes = Math.max(MIN_BYTES, opts.maxBytes);
|
|
12
|
+
this.maxFiles = Math.max(1, opts.maxFiles);
|
|
13
|
+
this.mode = opts.mode ?? 384;
|
|
14
|
+
fs.mkdirSync(path.dirname(this.filename), { recursive: true, mode: 448 });
|
|
15
|
+
this.size = this.currentSize();
|
|
16
|
+
}
|
|
17
|
+
currentSize() {
|
|
18
|
+
try {
|
|
19
|
+
return fs.statSync(this.filename).size;
|
|
20
|
+
} catch {
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
rotated(n) {
|
|
25
|
+
return `${this.filename}.${n}`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* `<name>.<maxFiles-1>` is removed, every older file shifts up, the live file
|
|
29
|
+
* becomes `.1`. Returns false when the live file could neither be moved aside
|
|
30
|
+
* nor cut to zero.
|
|
31
|
+
*/
|
|
32
|
+
rotate() {
|
|
33
|
+
try {
|
|
34
|
+
fs.rmSync(this.rotated(this.maxFiles - 1), { force: true });
|
|
35
|
+
for (let n = this.maxFiles - 2; n >= 1; n--) {
|
|
36
|
+
if (fs.existsSync(this.rotated(n))) fs.renameSync(this.rotated(n), this.rotated(n + 1));
|
|
37
|
+
}
|
|
38
|
+
} catch {
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
if (this.maxFiles > 1 && fs.existsSync(this.filename)) {
|
|
42
|
+
fs.renameSync(this.filename, this.rotated(1));
|
|
43
|
+
} else {
|
|
44
|
+
fs.rmSync(this.filename, { force: true });
|
|
45
|
+
}
|
|
46
|
+
} catch {
|
|
47
|
+
try {
|
|
48
|
+
fs.truncateSync(this.filename, 0);
|
|
49
|
+
} catch {
|
|
50
|
+
this.size = this.currentSize();
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
this.size = this.currentSize();
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
/** A single record never exceeds the file bound; the excess is replaced by a note. */
|
|
58
|
+
fit(line) {
|
|
59
|
+
const bytes = Buffer.byteLength(line);
|
|
60
|
+
if (bytes <= this.maxBytes) return line;
|
|
61
|
+
const note = ` \u2026[${bytes - this.maxBytes} bytes dropped]
|
|
62
|
+
`;
|
|
63
|
+
const room = Math.max(0, this.maxBytes - Buffer.byteLength(note));
|
|
64
|
+
const head = Buffer.from(line).subarray(0, room).toString("utf8").replace(/�+$/, "");
|
|
65
|
+
return `${head}${note}`;
|
|
66
|
+
}
|
|
67
|
+
log(info, callback) {
|
|
68
|
+
setImmediate(() => this.emit("logged", info));
|
|
69
|
+
if (this.stopped) {
|
|
70
|
+
callback();
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const line = this.fit(`${String(info[/* @__PURE__ */ Symbol.for("message")] ?? "")}
|
|
74
|
+
`);
|
|
75
|
+
const bytes = Buffer.byteLength(line);
|
|
76
|
+
if (this.size + bytes > this.maxBytes && !this.rotate()) {
|
|
77
|
+
this.stopped = true;
|
|
78
|
+
console.error(
|
|
79
|
+
`[ms365-mcp] log file ${path.basename(this.filename)} cannot be bounded; writing stopped`
|
|
80
|
+
);
|
|
81
|
+
callback();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (this.size + bytes > this.maxBytes) {
|
|
85
|
+
this.stopped = true;
|
|
86
|
+
callback();
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
fs.appendFileSync(this.filename, line, { mode: this.mode, flag: "a" });
|
|
91
|
+
this.size += bytes;
|
|
92
|
+
} catch {
|
|
93
|
+
}
|
|
94
|
+
callback();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
export {
|
|
98
|
+
BoundedFileTransport
|
|
99
|
+
};
|