@aidalinfo/m365-mcp 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +201 -20
- package/dist/audit.js +10 -6
- package/dist/auth/token-provider.js +67 -2
- package/dist/config.js +59 -2
- package/dist/confirm.js +1 -1
- package/dist/context.js +43 -1
- package/dist/errors.js +1 -1
- package/dist/external/activity.js +253 -0
- package/dist/external/client.js +140 -0
- package/dist/external/exchange.js +104 -0
- package/dist/external/sharepoint.js +79 -0
- package/dist/graph-client.js +93 -2
- package/dist/index.js +1 -1
- package/dist/permissions.js +178 -1
- package/dist/register.js +15 -1
- package/dist/reports.js +138 -0
- package/dist/review/collect.js +238 -0
- package/dist/review/model.js +152 -0
- package/dist/tools/access-review.js +98 -0
- package/dist/tools/applications.js +101 -0
- package/dist/tools/capabilities.js +44 -6
- package/dist/tools/common.js +76 -0
- package/dist/tools/devices.js +40 -0
- package/dist/tools/phase2.js +235 -0
- package/dist/tools/reports.js +151 -0
- package/dist/tools/security.js +275 -0
- package/dist/tools/sites.js +231 -0
- package/dist/tools/teams-write.js +2 -1
- package/dist/tools/teams.js +39 -1
- package/dist/tools/write-flow.js +11 -1
- package/package.json +6 -3
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { GUID_RE } from "../config.js";
|
|
3
|
+
import { M365Error } from "../errors.js";
|
|
4
|
+
import { collectAll, cursorParam, daysSince, errorResult, formatParam, jsonBlock, limitParam, listPage, odataString, or, premiumError, renderList, resolveUser, searchText, textResult, userParam, } from "./common.js";
|
|
5
|
+
export const principalType = (p) => String(p?.["@odata.type"] ?? "").replace("#microsoft.graph.", "") || "unknown";
|
|
6
|
+
/** Role definitions (id → name), the whole catalogue: ~100 built-in roles. */
|
|
7
|
+
export async function roleNames(ctx) {
|
|
8
|
+
const { items } = await collectAll(ctx, "/roleManagement/directory/roleDefinitions", { $select: "id,displayName,isBuiltIn,templateId" }, { top: false, max: 1000 });
|
|
9
|
+
return new Map(items.map((r) => [r.id, r]));
|
|
10
|
+
}
|
|
11
|
+
/** Every active role assignment with its principal expanded. */
|
|
12
|
+
export async function roleAssignments(ctx) {
|
|
13
|
+
const { items } = await collectAll(ctx, "/roleManagement/directory/roleAssignments", { $expand: "principal" }, { top: false, max: 2000 });
|
|
14
|
+
return items;
|
|
15
|
+
}
|
|
16
|
+
const METHOD_NAMES = {
|
|
17
|
+
passwordAuthenticationMethod: "password",
|
|
18
|
+
microsoftAuthenticatorAuthenticationMethod: "Microsoft Authenticator",
|
|
19
|
+
phoneAuthenticationMethod: "phone (SMS/voice)",
|
|
20
|
+
fido2AuthenticationMethod: "FIDO2 security key",
|
|
21
|
+
windowsHelloForBusinessAuthenticationMethod: "Windows Hello for Business",
|
|
22
|
+
softwareOathAuthenticationMethod: "software OATH token",
|
|
23
|
+
emailAuthenticationMethod: "e-mail (SSPR only)",
|
|
24
|
+
temporaryAccessPassAuthenticationMethod: "Temporary Access Pass",
|
|
25
|
+
platformCredentialAuthenticationMethod: "platform credential (macOS)",
|
|
26
|
+
x509CertificateAuthenticationMethod: "certificate",
|
|
27
|
+
externalAuthenticationMethod: "external MFA",
|
|
28
|
+
};
|
|
29
|
+
/** Strong second factors (password and e-mail are not). */
|
|
30
|
+
export const isMfaMethod = (type) => !["passwordAuthenticationMethod", "emailAuthenticationMethod"].includes(type);
|
|
31
|
+
/** Method types of one user — only the type, a device label and dates: never a phone number, e-mail or key. */
|
|
32
|
+
export async function userMethods(ctx, userId) {
|
|
33
|
+
const res = await ctx.graph.get(`/users/${userId}/authentication/methods`);
|
|
34
|
+
return (res.data?.value ?? []).map((m) => {
|
|
35
|
+
const type = String(m["@odata.type"] ?? "").replace("#microsoft.graph.", "");
|
|
36
|
+
return { type, label: METHOD_NAMES[type] ?? type, detail: m.displayName ?? m.phoneType ?? undefined, createdDateTime: m.createdDateTime };
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
const AUDIT_CATEGORIES = [
|
|
40
|
+
"UserManagement",
|
|
41
|
+
"GroupManagement",
|
|
42
|
+
"RoleManagement",
|
|
43
|
+
"ApplicationManagement",
|
|
44
|
+
"DirectoryManagement",
|
|
45
|
+
"Policy",
|
|
46
|
+
"Device",
|
|
47
|
+
"Authentication",
|
|
48
|
+
"Other",
|
|
49
|
+
];
|
|
50
|
+
/** Audit entry without property values (old/new values may hold personal data): property names only. */
|
|
51
|
+
const safeAudit = (a) => ({
|
|
52
|
+
id: a.id,
|
|
53
|
+
activityDateTime: a.activityDateTime,
|
|
54
|
+
activity: a.activityDisplayName,
|
|
55
|
+
category: a.category,
|
|
56
|
+
result: a.result,
|
|
57
|
+
resultReason: a.resultReason || undefined,
|
|
58
|
+
service: a.loggedByService,
|
|
59
|
+
initiatedBy: a.initiatedBy?.user?.userPrincipalName ?? a.initiatedBy?.app?.displayName ?? a.initiatedBy?.user?.id ?? a.initiatedBy?.app?.appId,
|
|
60
|
+
targets: (a.targetResources ?? []).slice(0, 10).map((t) => ({
|
|
61
|
+
id: t.id,
|
|
62
|
+
type: t.type,
|
|
63
|
+
name: t.userPrincipalName ?? t.displayName,
|
|
64
|
+
modifiedProperties: (t.modifiedProperties ?? []).map((p) => p.displayName).filter(Boolean).slice(0, 20),
|
|
65
|
+
})),
|
|
66
|
+
});
|
|
67
|
+
export function registerSecurityTools(server, ctx) {
|
|
68
|
+
server.tool("m365_directory_roles", "Who is administrator of what: active Entra role assignments (Global, Exchange, SharePoint, User administrator…) with the principal (user, group, service principal) and scope. view=eligible lists PIM-eligible assignments (Entra ID P2).", {
|
|
69
|
+
view: z.enum(["active", "eligible"]).default("active"),
|
|
70
|
+
role: searchText("Case-insensitive substring of the role name, e.g. 'Global' or 'Exchange'").optional(),
|
|
71
|
+
user: userParam.optional().describe("Only the roles of this user (id, UPN or exact display name)"),
|
|
72
|
+
limit: limitParam,
|
|
73
|
+
cursor: cursorParam,
|
|
74
|
+
format: formatParam,
|
|
75
|
+
}, async ({ view, role, user, limit, cursor, format }) => {
|
|
76
|
+
try {
|
|
77
|
+
const names = await roleNames(ctx);
|
|
78
|
+
let roleIds;
|
|
79
|
+
if (role) {
|
|
80
|
+
roleIds = [...names.values()].filter((r) => r.displayName?.toLowerCase().includes(role.toLowerCase())).map((r) => r.id);
|
|
81
|
+
if (!roleIds.length)
|
|
82
|
+
throw new M365Error("not_found", `not_found: no role matches "${role}"`);
|
|
83
|
+
if (roleIds.length > 15)
|
|
84
|
+
throw new M365Error("invalid_request", `invalid_request: "${role}" matches ${roleIds.length} roles — be more specific`);
|
|
85
|
+
}
|
|
86
|
+
const principalId = user ? (await resolveUser(ctx, user, "id")).id : undefined;
|
|
87
|
+
const filters = [];
|
|
88
|
+
if (roleIds)
|
|
89
|
+
filters.push(`(${roleIds.map((id) => `roleDefinitionId eq ${odataString(id)}`).join(" or ")})`);
|
|
90
|
+
if (principalId)
|
|
91
|
+
filters.push(`principalId eq ${odataString(principalId)}`);
|
|
92
|
+
const path = view === "active" ? "/roleManagement/directory/roleAssignments" : "/roleManagement/directory/roleEligibilityScheduleInstances";
|
|
93
|
+
let page;
|
|
94
|
+
try {
|
|
95
|
+
page = await listPage(ctx, `m365_directory_roles:${view}:${role ?? ""}:${principalId ?? ""}`, { path, query: { $expand: "principal", $filter: filters.join(" and ") || undefined }, supportsTop: false }, limit, cursor);
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
throw view === "eligible" ? await premiumError(ctx, err, "Entra ID P2", "PIM eligible role assignments") : err;
|
|
99
|
+
}
|
|
100
|
+
return textResult(renderList(`${view === "active" ? "Active" : "Eligible (PIM)"} directory role assignments`, page, format, (a) => {
|
|
101
|
+
const r = names.get(a.roleDefinitionId);
|
|
102
|
+
const p = a.principal;
|
|
103
|
+
const who = p ? `${or(p.displayName)}${p.userPrincipalName ? ` <${p.userPrincipalName}>` : ""} (${principalType(p)}${p.userType === "Guest" ? ", GUEST" : ""}${p.accountEnabled === false ? ", DISABLED" : ""})` : a.principalId;
|
|
104
|
+
return `**${or(r?.displayName, a.roleDefinitionId)}** — ${who} — scope ${a.directoryScopeId === "/" || !a.directoryScopeId ? "tenant" : a.directoryScopeId}`;
|
|
105
|
+
}));
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
return errorResult(err);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
server.tool("m365_user_auth_methods", "MFA: with `user`, the authentication methods registered by that user (types only — never a phone number, e-mail or key). Without `user`, the tenant view of MFA registration per user (needs Entra ID P1).", {
|
|
112
|
+
user: userParam.optional(),
|
|
113
|
+
mfaRegistered: z.boolean().optional().describe("Tenant view: only users with (true) / without (false) MFA registered"),
|
|
114
|
+
adminsOnly: z.boolean().default(false).describe("Tenant view: only users holding an admin role"),
|
|
115
|
+
userType: z.enum(["member", "guest"]).optional().describe("Tenant view"),
|
|
116
|
+
limit: limitParam,
|
|
117
|
+
cursor: cursorParam,
|
|
118
|
+
format: formatParam,
|
|
119
|
+
}, async ({ user, mfaRegistered, adminsOnly, userType, limit, cursor, format }) => {
|
|
120
|
+
try {
|
|
121
|
+
if (user) {
|
|
122
|
+
const u = await resolveUser(ctx, user, "id,displayName,userPrincipalName");
|
|
123
|
+
const methods = await userMethods(ctx, u.id);
|
|
124
|
+
const mfa = methods.filter((m) => isMfaMethod(m.type));
|
|
125
|
+
const lines = methods.map((m) => `- ${m.label}${m.detail ? ` — ${m.detail}` : ""}${m.createdDateTime ? ` — registered ${m.createdDateTime}` : ""}`);
|
|
126
|
+
return textResult(`# Authentication methods of ${or(u.displayName)} <${or(u.userPrincipalName)}>\n\nMFA: ${mfa.length ? `yes (${mfa.map((m) => m.label).join(", ")})` : "⚠ NO strong method registered"}\n\n${lines.join("\n") || "none"}${format === "json" ? `\n\n${jsonBlock(methods)}` : ""}`);
|
|
127
|
+
}
|
|
128
|
+
const filters = [];
|
|
129
|
+
if (mfaRegistered !== undefined)
|
|
130
|
+
filters.push(`isMfaRegistered eq ${mfaRegistered}`);
|
|
131
|
+
if (adminsOnly)
|
|
132
|
+
filters.push("isAdmin eq true");
|
|
133
|
+
if (userType)
|
|
134
|
+
filters.push(`userType eq ${odataString(userType)}`);
|
|
135
|
+
try {
|
|
136
|
+
const page = await listPage(ctx, `m365_user_auth_methods:${filters.join(" and ")}`, {
|
|
137
|
+
path: "/reports/authenticationMethods/userRegistrationDetails",
|
|
138
|
+
query: {
|
|
139
|
+
$select: "id,userPrincipalName,userDisplayName,userType,isAdmin,isMfaRegistered,isMfaCapable,isPasswordlessCapable,isSsprRegistered,methodsRegistered,defaultMfaMethod,lastUpdatedDateTime",
|
|
140
|
+
$filter: filters.join(" and ") || undefined,
|
|
141
|
+
},
|
|
142
|
+
}, limit, cursor);
|
|
143
|
+
return textResult(renderList("MFA registration", page, format, (r) => `${or(r.userDisplayName)} <${or(r.userPrincipalName)}>${r.isAdmin ? " — ADMIN" : ""}${r.userType === "guest" ? " — guest" : ""} — MFA ${r.isMfaRegistered ? "registered" : "⚠ NOT registered"} — methods: ${(r.methodsRegistered ?? []).join(", ") || "none"}${r.defaultMfaMethod && r.defaultMfaMethod !== "none" ? ` — default ${r.defaultMfaMethod}` : ""}`));
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
throw await premiumError(ctx, err, "Entra ID P1", "the tenant MFA registration report (pass `user` to read one user's methods without P1)");
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
catch (err) {
|
|
150
|
+
return errorResult(err);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
server.tool("m365_user_activity", "Last sign-in of each account (interactive and non-interactive) to find dormant accounts to disable. Needs Entra ID P1 (signInActivity) — otherwise unsupported_by_tenant.", {
|
|
154
|
+
inactiveDays: z.number().int().min(1).max(3650).optional().describe("Only accounts whose last sign-in is older than N days (accounts that never signed in are listed only without this filter)"),
|
|
155
|
+
accountEnabled: z.boolean().optional().describe("Applied to the returned page (signInActivity filters cannot be combined server-side)"),
|
|
156
|
+
userType: z.enum(["Member", "Guest"]).optional().describe("Applied to the returned page"),
|
|
157
|
+
limit: limitParam,
|
|
158
|
+
cursor: cursorParam,
|
|
159
|
+
format: formatParam,
|
|
160
|
+
}, async ({ inactiveDays, accountEnabled, userType, limit, cursor, format }) => {
|
|
161
|
+
try {
|
|
162
|
+
const before = inactiveDays ? new Date(Date.now() - inactiveDays * 86_400_000).toISOString() : undefined;
|
|
163
|
+
let page;
|
|
164
|
+
try {
|
|
165
|
+
page = await listPage(ctx, `m365_user_activity:${inactiveDays ?? 0}:${accountEnabled ?? ""}:${userType ?? ""}`, {
|
|
166
|
+
path: "/users",
|
|
167
|
+
query: {
|
|
168
|
+
$select: "id,displayName,userPrincipalName,accountEnabled,userType,createdDateTime,signInActivity",
|
|
169
|
+
$filter: before ? `signInActivity/lastSignInDateTime le ${before}` : undefined,
|
|
170
|
+
},
|
|
171
|
+
}, limit, cursor);
|
|
172
|
+
}
|
|
173
|
+
catch (err) {
|
|
174
|
+
throw await premiumError(ctx, err, "Entra ID P1", "signInActivity");
|
|
175
|
+
}
|
|
176
|
+
const shown = page.items.filter((u) => (accountEnabled === undefined || u.accountEnabled === accountEnabled) && (!userType || u.userType === userType));
|
|
177
|
+
const last = (u) => {
|
|
178
|
+
const a = u.signInActivity ?? {};
|
|
179
|
+
return [a.lastSignInDateTime, a.lastNonInteractiveSignInDateTime].filter(Boolean).sort().pop();
|
|
180
|
+
};
|
|
181
|
+
const local = shown.length !== page.items.length ? `\n\n_${page.items.length - shown.length} account(s) of this page hidden by accountEnabled/userType._` : "";
|
|
182
|
+
return textResult(renderList(`Account activity${inactiveDays ? ` (inactive ≥ ${inactiveDays} days)` : ""}`, { ...page, items: shown }, format, (u) => {
|
|
183
|
+
const l = last(u);
|
|
184
|
+
const d = daysSince(l);
|
|
185
|
+
return `${or(u.displayName)} <${or(u.userPrincipalName)}> — ${u.accountEnabled ? "enabled" : "DISABLED"}${u.userType === "Guest" ? " — guest" : ""} — last sign-in ${l ? `${l} (${d} days)` : "NEVER"} — created ${or(u.createdDateTime)}`;
|
|
186
|
+
}) + local);
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
return errorResult(err);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
server.tool("m365_directory_audit", "Who changed what in the directory: Entra audit log (users, groups, roles, licences, applications, policies). Retention: 7 days without Entra ID P1, 30 days with. Property values are never returned, only their names.", {
|
|
193
|
+
sinceHours: z.number().int().min(1).max(720).default(24).describe("How far back, in hours (default 24, max 720 = 30 days)"),
|
|
194
|
+
category: z.enum(AUDIT_CATEGORIES).optional(),
|
|
195
|
+
activity: searchText("Exact activity name, e.g. 'Add member to group', 'Update user', 'Add member to role'").optional(),
|
|
196
|
+
initiatedBy: z.string().max(256).optional().describe("UPN of the user who made the change (exact)"),
|
|
197
|
+
target: z.string().regex(GUID_RE).optional().describe("Object id of the changed user/group/application"),
|
|
198
|
+
result: z.enum(["success", "failure"]).optional(),
|
|
199
|
+
limit: limitParam,
|
|
200
|
+
cursor: cursorParam,
|
|
201
|
+
format: formatParam,
|
|
202
|
+
}, async ({ sinceHours, category, activity, initiatedBy, target, result, limit, cursor, format }) => {
|
|
203
|
+
try {
|
|
204
|
+
const filters = [`activityDateTime ge ${new Date(Date.now() - sinceHours * 3600_000).toISOString()}`];
|
|
205
|
+
if (category)
|
|
206
|
+
filters.push(`category eq ${odataString(category)}`);
|
|
207
|
+
if (activity)
|
|
208
|
+
filters.push(`activityDisplayName eq ${odataString(activity)}`);
|
|
209
|
+
if (initiatedBy)
|
|
210
|
+
filters.push(`initiatedBy/user/userPrincipalName eq ${odataString(initiatedBy.toLowerCase())}`);
|
|
211
|
+
if (target)
|
|
212
|
+
filters.push(`targetResources/any(t:t/id eq ${odataString(target.toLowerCase())})`);
|
|
213
|
+
if (result)
|
|
214
|
+
filters.push(`result eq ${odataString(result)}`);
|
|
215
|
+
const page = await listPage(ctx, "m365_directory_audit", { path: "/auditLogs/directoryAudits", query: { $filter: filters.join(" and "), $orderby: "activityDateTime desc" } }, limit, cursor);
|
|
216
|
+
const safe = { ...page, items: page.items.map(safeAudit) };
|
|
217
|
+
return textResult(renderList(`Directory audit (last ${sinceHours} h)`, safe, format, (a) => `${or(a.activityDateTime)} — ${or(a.activity)} [${or(a.category)}] — ${a.result === "success" ? "success" : `${String(a.result).toUpperCase()}${a.resultReason ? ` (${a.resultReason})` : ""}`} — by ${or(a.initiatedBy)} — on ${a.targets.map((t) => `${or(t.name, t.id)} (${or(t.type)})${t.modifiedProperties.length ? ` [${t.modifiedProperties.join(", ")}]` : ""}`).join("; ") || "—"}`));
|
|
218
|
+
}
|
|
219
|
+
catch (err) {
|
|
220
|
+
return errorResult(err);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
server.tool("m365_conditional_access", "Conditional Access policies (state, targeted users/apps, required controls) and whether security defaults are enabled. Conditional Access needs Entra ID P1; without it the tenant relies on security defaults.", { view: z.enum(["all", "policies", "security_defaults"]).default("all"), format: formatParam }, async ({ view, format }) => {
|
|
224
|
+
try {
|
|
225
|
+
const out = ["# Conditional Access and security defaults", ""];
|
|
226
|
+
const data = {};
|
|
227
|
+
if (view !== "policies") {
|
|
228
|
+
const sd = (await ctx.graph.get("/policies/identitySecurityDefaultsEnforcementPolicy", { query: { $select: "id,isEnabled" } })).data;
|
|
229
|
+
data.securityDefaults = { isEnabled: sd?.isEnabled };
|
|
230
|
+
out.push(`Security defaults: **${sd?.isEnabled ? "ENABLED" : "disabled"}**`);
|
|
231
|
+
}
|
|
232
|
+
if (view !== "security_defaults") {
|
|
233
|
+
try {
|
|
234
|
+
const { items, truncated } = await collectAll(ctx, "/identity/conditionalAccess/policies", { $select: "id,displayName,state,createdDateTime,modifiedDateTime,conditions,grantControls,sessionControls" }, { top: false, max: 500 });
|
|
235
|
+
const policies = items.map((p) => {
|
|
236
|
+
const c = p.conditions ?? {};
|
|
237
|
+
return {
|
|
238
|
+
id: p.id,
|
|
239
|
+
displayName: p.displayName,
|
|
240
|
+
state: p.state,
|
|
241
|
+
modifiedDateTime: p.modifiedDateTime ?? p.createdDateTime,
|
|
242
|
+
users: {
|
|
243
|
+
include: [...(c.users?.includeUsers ?? []), ...(c.users?.includeGroups ?? []).map((g) => `group:${g}`), ...(c.users?.includeRoles ?? []).map((r) => `role:${r}`)],
|
|
244
|
+
exclude: [...(c.users?.excludeUsers ?? []), ...(c.users?.excludeGroups ?? []).map((g) => `group:${g}`), ...(c.users?.excludeRoles ?? []).map((r) => `role:${r}`)],
|
|
245
|
+
},
|
|
246
|
+
applications: { include: c.applications?.includeApplications ?? [], exclude: c.applications?.excludeApplications ?? [] },
|
|
247
|
+
clientAppTypes: c.clientAppTypes,
|
|
248
|
+
locations: c.locations,
|
|
249
|
+
platforms: c.platforms,
|
|
250
|
+
signInRiskLevels: c.signInRiskLevels,
|
|
251
|
+
grant: p.grantControls ? { operator: p.grantControls.operator, controls: p.grantControls.builtInControls, authenticationStrength: p.grantControls.authenticationStrength?.displayName } : undefined,
|
|
252
|
+
session: p.sessionControls ? Object.keys(p.sessionControls).filter((k) => p.sessionControls[k]) : undefined,
|
|
253
|
+
};
|
|
254
|
+
});
|
|
255
|
+
data.policies = policies;
|
|
256
|
+
out.push(`Conditional Access policies: ${policies.length}${truncated ? " (truncated)" : ""} — ${policies.filter((p) => p.state === "enabled").length} enabled, ${policies.filter((p) => p.state === "enabledForReportingButNotEnforced").length} report-only, ${policies.filter((p) => p.state === "disabled").length} disabled`);
|
|
257
|
+
if (format === "summary") {
|
|
258
|
+
out.push("", ...policies.map((p) => `- **${or(p.displayName)}** — ${or(p.state)} — users ${p.users.include.slice(0, 5).join(", ") || "none"}${p.users.exclude.length ? ` (excluding ${p.users.exclude.length})` : ""} — apps ${p.applications.include.slice(0, 3).join(", ") || "none"} — grant ${p.grant ? `${(p.grant.controls ?? []).join(` ${p.grant.operator ?? "OR"} `)}${p.grant.authenticationStrength ? ` + ${p.grant.authenticationStrength}` : ""}` : "—"}`));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
catch (err) {
|
|
262
|
+
const e = await premiumError(ctx, err, "Entra ID P1", "Conditional Access");
|
|
263
|
+
if (view === "policies" || !(e instanceof M365Error) || e.code !== "unsupported_by_tenant")
|
|
264
|
+
throw e;
|
|
265
|
+
data.policies = { error: "unsupported_by_tenant" };
|
|
266
|
+
out.push("Conditional Access policies: **unsupported_by_tenant** — no Entra ID P1; protection relies on security defaults (above) or per-user MFA.");
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return textResult(`${out.join("\n")}${format === "json" ? `\n\n${jsonBlock(data)}` : ""}`);
|
|
270
|
+
}
|
|
271
|
+
catch (err) {
|
|
272
|
+
return errorResult(err);
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { M365Error } from "../errors.js";
|
|
3
|
+
import { cursorParam, errorResult, formatParam, jsonBlock, limitParam, listPage, or, renderList, resolveGroup, searchText, sizeOf, sizeText, textResult, } from "./common.js";
|
|
4
|
+
const SITE_FIELDS = "id,displayName,name,webUrl,description,createdDateTime,lastModifiedDateTime,isPersonalSite,siteCollection";
|
|
5
|
+
const DRIVE_FIELDS = "id,name,driveType,webUrl,createdDateTime,lastModifiedDateTime,quota,owner";
|
|
6
|
+
const SITE_ID_RE = /^[\w.-]+\.sharepoint\.com,[0-9a-f-]{36},[0-9a-f-]{36}$/i;
|
|
7
|
+
export const siteParam = z
|
|
8
|
+
.string()
|
|
9
|
+
.min(1)
|
|
10
|
+
.max(400)
|
|
11
|
+
.describe("Site id (contoso.sharepoint.com,<guid>,<guid>), site URL (https://contoso.sharepoint.com/sites/Finance), or a Microsoft 365 group (id or exact name) for its team site");
|
|
12
|
+
const personal = (s) => s.isPersonalSite === true || /-my\.sharepoint\.com\/personal\//i.test(s.webUrl ?? "");
|
|
13
|
+
/** Site id, https://<tenant>.sharepoint.com/<path>, or a group → its root site. */
|
|
14
|
+
export async function resolveSite(ctx, input) {
|
|
15
|
+
if (SITE_ID_RE.test(input))
|
|
16
|
+
return (await ctx.graph.get(`/sites/${input}`, { query: { $select: SITE_FIELDS } })).data;
|
|
17
|
+
if (/^https:\/\//i.test(input)) {
|
|
18
|
+
let u;
|
|
19
|
+
try {
|
|
20
|
+
u = new URL(input);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
throw new M365Error("invalid_request", "invalid_request: malformed site URL");
|
|
24
|
+
}
|
|
25
|
+
if (!/^[a-z0-9-]+(-my)?\.sharepoint\.com$/i.test(u.hostname))
|
|
26
|
+
throw new M365Error("invalid_request", "invalid_request: the site URL must be on <tenant>.sharepoint.com");
|
|
27
|
+
const segments = decodeURIComponent(u.pathname).split("/").filter(Boolean);
|
|
28
|
+
if (segments.some((s) => s === "." || s === ".."))
|
|
29
|
+
throw new M365Error("invalid_request", "invalid_request: unsafe site URL");
|
|
30
|
+
const rel = segments.slice(0, 2).map(encodeURIComponent).join("/"); // /sites/<name> or /teams/<name>; the rest are library/folder paths
|
|
31
|
+
const path = rel ? `/sites/${u.hostname}:/${rel}:` : `/sites/${u.hostname}`;
|
|
32
|
+
return (await ctx.graph.get(path, { query: { $select: SITE_FIELDS } })).data;
|
|
33
|
+
}
|
|
34
|
+
const g = await resolveGroup(ctx, input, "id,displayName");
|
|
35
|
+
return (await ctx.graph.get(`/groups/${g.id}/sites/root`, { query: { $select: SITE_FIELDS } })).data;
|
|
36
|
+
}
|
|
37
|
+
const driveJson = (d) => ({
|
|
38
|
+
id: d.id,
|
|
39
|
+
name: d.name,
|
|
40
|
+
driveType: d.driveType,
|
|
41
|
+
webUrl: d.webUrl,
|
|
42
|
+
used: sizeOf(d.quota?.used),
|
|
43
|
+
total: sizeOf(d.quota?.total),
|
|
44
|
+
deleted: sizeOf(d.quota?.deleted),
|
|
45
|
+
quotaState: d.quota?.state,
|
|
46
|
+
ownerGroup: d.owner?.group?.id ? { id: d.owner.group.id, displayName: d.owner.group.displayName } : undefined,
|
|
47
|
+
});
|
|
48
|
+
const who = (i) => {
|
|
49
|
+
const u = i?.user ?? i?.siteUser;
|
|
50
|
+
if (u)
|
|
51
|
+
return `${or(u.displayName)}${u.email ? ` <${u.email}>` : ""}`;
|
|
52
|
+
return i?.group?.displayName ?? i?.siteGroup?.displayName ?? "—";
|
|
53
|
+
};
|
|
54
|
+
/** Guests and external people: #EXT# login, or an e-mail outside the tenant's verified domains. */
|
|
55
|
+
const isExternal = (i, domains) => {
|
|
56
|
+
const u = i?.user ?? i?.siteUser;
|
|
57
|
+
const login = (i?.siteUser?.loginName ?? "").toLowerCase();
|
|
58
|
+
const email = (u?.email ?? "").toLowerCase();
|
|
59
|
+
if (login.includes("#ext#") || /urn:spo:guest/.test(login))
|
|
60
|
+
return true;
|
|
61
|
+
return Boolean(email && domains.length && !domains.some((d) => email.endsWith(`@${d}`)));
|
|
62
|
+
};
|
|
63
|
+
export function registerSiteTools(server, ctx) {
|
|
64
|
+
server.tool("m365_sites", "SharePoint sites of the tenant (including sites without Teams), paginated. Personal OneDrive sites are excluded unless asked.", {
|
|
65
|
+
search: searchText("Keyword matched by SharePoint search against site name / URL").optional(),
|
|
66
|
+
includePersonal: z.boolean().default(false).describe("Also OneDrive (personal) sites"),
|
|
67
|
+
limit: limitParam,
|
|
68
|
+
cursor: cursorParam,
|
|
69
|
+
format: formatParam,
|
|
70
|
+
}, async ({ search, includePersonal, limit, cursor, format }) => {
|
|
71
|
+
try {
|
|
72
|
+
const tool = `m365_sites:${includePersonal}:${search ?? ""}`;
|
|
73
|
+
let page;
|
|
74
|
+
if (search) {
|
|
75
|
+
page = await listPage(ctx, tool, { path: "/sites", query: { search, $select: SITE_FIELDS } }, limit, cursor);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
try {
|
|
79
|
+
// app-only listing of every site; isPersonalSite is filterable here
|
|
80
|
+
page = await listPage(ctx, tool, { path: "/sites/getAllSites", query: { $select: SITE_FIELDS, $filter: includePersonal ? undefined : "isPersonalSite eq false" } }, limit, cursor);
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
if (cursor || !(err instanceof M365Error) || !["invalid_request", "not_found"].includes(err.code))
|
|
84
|
+
throw err;
|
|
85
|
+
// fallback documented for tenants where getAllSites is not served: search=* lists every site
|
|
86
|
+
page = await listPage(ctx, tool, { path: "/sites", query: { search: "*", $select: SITE_FIELDS } }, limit);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (!includePersonal)
|
|
90
|
+
page = { ...page, items: page.items.filter((s) => !personal(s)) };
|
|
91
|
+
return textResult(renderList("SharePoint sites", page, format, (s) => `${or(s.displayName ?? s.name)} — ${or(s.webUrl)} (${s.id})${personal(s) ? " — personal" : ""} — modified ${or(s.lastModifiedDateTime)}`));
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
return errorResult(err);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
server.tool("m365_site_info", "One SharePoint site: its document libraries with storage used / quota (bytes and GB), and the Microsoft 365 group (team) it belongs to, if any.", { site: siteParam }, async ({ site }) => {
|
|
98
|
+
try {
|
|
99
|
+
const s = await resolveSite(ctx, site);
|
|
100
|
+
const drives = (await ctx.graph.get(`/sites/${s.id}/drives`, { query: { $select: DRIVE_FIELDS } })).data?.value ?? [];
|
|
101
|
+
const group = drives.map((d) => d.owner?.group).find((g) => g?.id);
|
|
102
|
+
const total = drives.reduce((n, d) => n + (d.quota?.used ?? 0), 0);
|
|
103
|
+
const lines = drives.map((d) => `- ${or(d.name)} (${d.id}) — ${or(d.driveType)} — ${sizeText(d.quota?.used)} used${d.quota?.total ? ` of ${sizeText(d.quota.total)}` : ""}${d.quota?.state && d.quota.state !== "normal" ? ` — quota ${d.quota.state}` : ""}`);
|
|
104
|
+
return textResult([
|
|
105
|
+
`# ${or(s.displayName ?? s.name)} (${s.id})`,
|
|
106
|
+
"",
|
|
107
|
+
`URL: ${or(s.webUrl)}`,
|
|
108
|
+
`Linked Microsoft 365 group: ${group?.id ? `${or(group.displayName)} (${group.id}) — see m365_group_info / m365_team_members` : "none found (communication site, classic site, or group not exposed on the libraries)"}`,
|
|
109
|
+
`Storage of the libraries: ${sizeText(total)}`,
|
|
110
|
+
"",
|
|
111
|
+
`## Document libraries (${drives.length})`,
|
|
112
|
+
lines.join("\n") || "none",
|
|
113
|
+
"",
|
|
114
|
+
jsonBlock({ site: s, drives: drives.map(driveJson) }),
|
|
115
|
+
].join("\n"));
|
|
116
|
+
}
|
|
117
|
+
catch (err) {
|
|
118
|
+
return errorResult(err);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
server.tool("m365_sharing_links", "Sharing links and direct grants on the files of ONE folder (bounded walk: depth and item count capped). Flags anonymous links, links without expiry and external people. Link URLs are never returned.", {
|
|
122
|
+
site: siteParam,
|
|
123
|
+
library: searchText("Document library name (default: the site's default library)").optional(),
|
|
124
|
+
folder: z
|
|
125
|
+
.string()
|
|
126
|
+
.min(1)
|
|
127
|
+
.max(400)
|
|
128
|
+
.regex(/^[^\u0000-\u001f\u007f:*?"<>|]+$/, "invalid characters")
|
|
129
|
+
.describe("Folder path inside the library, e.g. 'Clients/2026' — '/' for the library root (required: the walk is always scoped)"),
|
|
130
|
+
depth: z.number().int().min(0).max(3).default(1).describe("Sub-folder levels to walk (0 = the folder's direct items only, max 3)"),
|
|
131
|
+
maxItems: z.number().int().min(1).max(200).default(100).describe("Maximum items inspected (max 200)"),
|
|
132
|
+
includeInherited: z.boolean().default(false).describe("Also permissions inherited from the parent (default: only those set on the item)"),
|
|
133
|
+
format: formatParam,
|
|
134
|
+
}, async ({ site, library, folder, depth, maxItems, includeInherited, format }) => {
|
|
135
|
+
try {
|
|
136
|
+
const s = await resolveSite(ctx, site);
|
|
137
|
+
let drive;
|
|
138
|
+
if (library) {
|
|
139
|
+
const drives = (await ctx.graph.get(`/sites/${s.id}/drives`, { query: { $select: "id,name" } })).data?.value ?? [];
|
|
140
|
+
const found = drives.filter((d) => d.name?.toLowerCase() === library.toLowerCase());
|
|
141
|
+
if (!found.length)
|
|
142
|
+
throw new M365Error("not_found", `not_found: no library "${library}" — libraries: ${drives.map((d) => d.name).join(", ") || "none"}`);
|
|
143
|
+
drive = found[0];
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
drive = (await ctx.graph.get(`/sites/${s.id}/drive`, { query: { $select: "id,name" } })).data;
|
|
147
|
+
}
|
|
148
|
+
const segments = folder.split("/").filter(Boolean);
|
|
149
|
+
if (segments.some((x) => x === "." || x === ".."))
|
|
150
|
+
throw new M365Error("invalid_request", "invalid_request: '.' and '..' are not allowed in the folder path");
|
|
151
|
+
const rootPath = segments.length ? `/drives/${drive.id}/root:/${segments.map(encodeURIComponent).join("/")}:` : `/drives/${drive.id}/root`;
|
|
152
|
+
const root = (await ctx.graph.get(rootPath, { query: { $select: "id,name,folder,file" } })).data;
|
|
153
|
+
if (!root.folder)
|
|
154
|
+
throw new M365Error("invalid_request", `invalid_request: "${folder}" is a file, not a folder`);
|
|
155
|
+
const domains = await verifiedDomains(ctx);
|
|
156
|
+
const findings = [];
|
|
157
|
+
let inspected = 0;
|
|
158
|
+
let truncated = false;
|
|
159
|
+
const queue = [{ item: root, path: `/${segments.join("/")}`, level: 0 }];
|
|
160
|
+
while (queue.length) {
|
|
161
|
+
const { item, path, level } = queue.shift();
|
|
162
|
+
if (inspected >= maxItems) {
|
|
163
|
+
truncated = true;
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
inspected++;
|
|
167
|
+
const perms = (await ctx.graph.get(`/drives/${drive.id}/items/${item.id}/permissions`)).data?.value ?? [];
|
|
168
|
+
for (const p of perms) {
|
|
169
|
+
if (!includeInherited && p.inheritedFrom)
|
|
170
|
+
continue;
|
|
171
|
+
const people = [p.grantedToV2, ...(p.grantedToIdentitiesV2 ?? [])].filter(Boolean);
|
|
172
|
+
const external = people.filter((i) => isExternal(i, domains)).map(who);
|
|
173
|
+
if (!p.link && !external.length && !includeInherited)
|
|
174
|
+
continue; // owners/members of the site: not a sharing finding
|
|
175
|
+
const flags = [
|
|
176
|
+
p.link?.scope === "anonymous" ? "ANONYMOUS" : "",
|
|
177
|
+
p.link && !p.expirationDateTime ? "no expiry" : "",
|
|
178
|
+
external.length ? "external people" : "",
|
|
179
|
+
p.link?.type === "edit" || p.roles?.includes("write") ? "edit" : "",
|
|
180
|
+
].filter(Boolean);
|
|
181
|
+
findings.push({
|
|
182
|
+
path,
|
|
183
|
+
kind: item.folder ? "folder" : "file",
|
|
184
|
+
link: p.link ? { type: p.link.type, scope: p.link.scope, preventsDownload: p.link.preventsDownload } : undefined,
|
|
185
|
+
roles: p.roles,
|
|
186
|
+
expirationDateTime: p.expirationDateTime,
|
|
187
|
+
hasPassword: p.hasPassword,
|
|
188
|
+
grantedTo: people.map(who).slice(0, 20),
|
|
189
|
+
external,
|
|
190
|
+
inherited: Boolean(p.inheritedFrom),
|
|
191
|
+
flags,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
if (item.folder && level < depth) {
|
|
195
|
+
if (inspected + queue.length >= maxItems) {
|
|
196
|
+
truncated = true;
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
const children = (await ctx.graph.get(`/drives/${drive.id}/items/${item.id}/children`, {
|
|
200
|
+
query: { $select: "id,name,folder,file", $top: Math.min(200, maxItems) },
|
|
201
|
+
})).data;
|
|
202
|
+
if (children?.["@odata.nextLink"])
|
|
203
|
+
truncated = true;
|
|
204
|
+
for (const c of children?.value ?? [])
|
|
205
|
+
queue.push({ item: c, path: `${path === "/" ? "" : path}/${c.name}`, level: level + 1 });
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const head = `# Sharing on ${or(s.displayName)} › ${or(drive.name)} › /${segments.join("/")}\n\n${inspected} item(s) inspected (depth ${depth})${truncated ? " — ⚠ TRUNCATED: raise maxItems or target a sub-folder" : ""} — ${findings.length} finding(s)\n`;
|
|
209
|
+
if (!findings.length)
|
|
210
|
+
return textResult(`${head}\nNo sharing link nor external grant on the inspected items (the requests succeeded).`);
|
|
211
|
+
const body = format === "json"
|
|
212
|
+
? jsonBlock(findings)
|
|
213
|
+
: findings
|
|
214
|
+
.map((f) => `- ${f.path} (${f.kind}) — ${f.link ? `${f.link.scope} ${f.link.type} link` : `direct grant (${(f.roles ?? []).join(",")})`}${f.expirationDateTime ? `, expires ${f.expirationDateTime}` : ""}${f.grantedTo.length ? ` — to ${f.grantedTo.join(", ")}` : ""}${f.flags.length ? ` — ⚠ ${f.flags.join(", ")}` : ""}`)
|
|
215
|
+
.join("\n");
|
|
216
|
+
return textResult(`${head}\n${body}`);
|
|
217
|
+
}
|
|
218
|
+
catch (err) {
|
|
219
|
+
return errorResult(err);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
async function verifiedDomains(ctx) {
|
|
224
|
+
try {
|
|
225
|
+
const org = (await ctx.graph.get("/organization", { query: { $select: "verifiedDomains" } })).data?.value?.[0];
|
|
226
|
+
return (org?.verifiedDomains ?? []).map((d) => d.name.toLowerCase());
|
|
227
|
+
}
|
|
228
|
+
catch {
|
|
229
|
+
return [];
|
|
230
|
+
}
|
|
231
|
+
}
|
|
@@ -9,7 +9,8 @@ async function getTeam(ctx, team, select = "id,displayName,isArchived") {
|
|
|
9
9
|
}
|
|
10
10
|
async function findMembership(ctx, teamId, userId) {
|
|
11
11
|
const res = await ctx.graph.get(`/teams/${teamId}/members`, {
|
|
12
|
-
|
|
12
|
+
// no $select: userId/email are aadUserConversationMember-only and Graph rejects them in $select (400)
|
|
13
|
+
query: { $filter: `(microsoft.graph.aadUserConversationMember/userId eq ${odataString(userId)})` },
|
|
13
14
|
});
|
|
14
15
|
return (res.data?.value ?? []).find((m) => m.userId === userId);
|
|
15
16
|
}
|
package/dist/tools/teams.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { M365Error } from "../errors.js";
|
|
2
3
|
import { cursorParam, errorResult, formatParam, jsonBlock, limitParam, listPage, odataString, or, renderList, resolveTeamId, searchText, teamParam, textResult, } from "./common.js";
|
|
3
4
|
export const TEAM_FIELDS = "id,displayName,description,visibility,isArchived,classification,specialization,createdDateTime,webUrl,memberSettings,guestSettings,messagingSettings,funSettings";
|
|
4
5
|
export const CHANNEL_FIELDS = "id,displayName,description,membershipType,createdDateTime";
|
|
@@ -59,7 +60,9 @@ export function registerTeamTools(server, ctx) {
|
|
|
59
60
|
const { id } = await resolveTeamId(ctx, team);
|
|
60
61
|
const page = await listPage(ctx, `m365_team_members:${id}`, {
|
|
61
62
|
path: `/teams/${id}/members`,
|
|
62
|
-
|
|
63
|
+
// no $select: userId and email exist only on the derived aadUserConversationMember type, and
|
|
64
|
+
// Graph rejects them in $select on conversationMember (400) — they come back anyway for Entra members
|
|
65
|
+
query: { $filter: role ? `roles/any(r:r eq ${odataString(role)})` : undefined },
|
|
63
66
|
supportsTop: false,
|
|
64
67
|
}, limit, cursor);
|
|
65
68
|
return textResult(renderList(`Members of team ${id}`, page, format, (m) => `${or(m.displayName)} <${or(m.email)}> — ${memberRole(m)} — userId ${or(m.userId)} — membershipId ${m.id}`));
|
|
@@ -68,4 +71,39 @@ export function registerTeamTools(server, ctx) {
|
|
|
68
71
|
return errorResult(err);
|
|
69
72
|
}
|
|
70
73
|
});
|
|
74
|
+
server.tool("m365_channel_members", "Members of a channel with their role (owner, member, guest). Needed for private and shared channels, whose members differ from the team's; shared channels also list people from other tenants (tenantId).", {
|
|
75
|
+
team: teamParam,
|
|
76
|
+
channel: z.string().min(1).max(256).describe("Channel id (19:…@thread.tacv2, from m365_team_channels) or exact channel displayName"),
|
|
77
|
+
role: z.enum(["owner", "guest"]).optional().describe("Only owners, or only guests"),
|
|
78
|
+
limit: limitParam,
|
|
79
|
+
cursor: cursorParam,
|
|
80
|
+
format: formatParam,
|
|
81
|
+
}, async ({ team, channel, role, limit, cursor, format }) => {
|
|
82
|
+
try {
|
|
83
|
+
const { id } = await resolveTeamId(ctx, team);
|
|
84
|
+
const ch = await resolveChannel(ctx, id, channel);
|
|
85
|
+
const page = await listPage(ctx, `m365_channel_members:${id}:${ch.id}`, {
|
|
86
|
+
path: `/teams/${id}/channels/${encodeURIComponent(ch.id)}/members`,
|
|
87
|
+
query: { $filter: role ? `roles/any(r:r eq ${odataString(role)})` : undefined },
|
|
88
|
+
supportsTop: false,
|
|
89
|
+
}, limit, cursor);
|
|
90
|
+
return textResult(renderList(`Members of channel ${or(ch.displayName, ch.id)} (${or(ch.membershipType)}) — team ${id}`, page, format, (m) => `${or(m.displayName)} <${or(m.email)}> — ${memberRole(m)} — userId ${or(m.userId)}${m.tenantId ? ` — tenant ${m.tenantId}` : ""}`));
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
return errorResult(err);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/** A channel of a team by id, or by exact displayName (refused when ambiguous). */
|
|
98
|
+
export async function resolveChannel(ctx, teamId, input) {
|
|
99
|
+
if (/^19:[\w.@-]+$/.test(input)) {
|
|
100
|
+
return (await ctx.graph.get(`/teams/${teamId}/channels/${encodeURIComponent(input)}`, { query: { $select: CHANNEL_FIELDS } })).data;
|
|
101
|
+
}
|
|
102
|
+
const res = await ctx.graph.get(`/teams/${teamId}/channels`, { query: { $select: CHANNEL_FIELDS, $filter: `displayName eq ${odataString(input)}` } });
|
|
103
|
+
const found = res.data?.value ?? [];
|
|
104
|
+
if (found.length === 0)
|
|
105
|
+
throw new M365Error("not_found", `not_found: no channel named "${input}" in team ${teamId}`);
|
|
106
|
+
if (found.length > 1)
|
|
107
|
+
throw new M365Error("ambiguous_target", `ambiguous_target: several channels are named "${input}" — pass the channel id: ${found.map((c) => c.id).join(", ")}`);
|
|
108
|
+
return found[0];
|
|
71
109
|
}
|
package/dist/tools/write-flow.js
CHANGED
|
@@ -30,7 +30,17 @@ export async function runWrite(spec) {
|
|
|
30
30
|
throw new M365Error("refused", `refused: writes are disabled by the kill switch (${ctx.config.killSwitchFile} exists)`);
|
|
31
31
|
}
|
|
32
32
|
plan = await spec.plan();
|
|
33
|
-
const
|
|
33
|
+
const identityHandle = ctx.identities[identity];
|
|
34
|
+
if (!identityHandle)
|
|
35
|
+
throw new M365Error("refused", `refused: ${identity} identity is not loaded`);
|
|
36
|
+
const binding = {
|
|
37
|
+
tool,
|
|
38
|
+
identity: { role: identityHandle.role, clientId: identityHandle.clientId },
|
|
39
|
+
approvalId: approvalId ?? null,
|
|
40
|
+
targetId: plan.targetId,
|
|
41
|
+
state: plan.before,
|
|
42
|
+
plan: plan.change,
|
|
43
|
+
};
|
|
34
44
|
const head = `Target: ${plan.targetType} ${plan.targetLabel} (${plan.targetId})\nOperation: ${plan.operation}`;
|
|
35
45
|
if (plan.refuse) {
|
|
36
46
|
ctx.audit.log({ tool, targetType: plan.targetType, targetId: plan.targetId, operation: plan.operation, result: "refused", errorCode: "refused", approvalId, identity });
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aidalinfo/m365-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Microsoft 365 MCP server over Microsoft Graph — Entra ID users, groups and applications, licences, Teams. Read-only by default; full mode uses separate scoped identities with two-step confirmed, audited writes",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Microsoft 365 MCP server over Microsoft Graph — Entra ID users, groups and applications, licences, Teams, SharePoint, usage reports, service health, roles, MFA, audit, access review. Read-only by default; full mode uses separate scoped identities with two-step confirmed, audited writes",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"bin": {
|
|
@@ -33,7 +33,10 @@
|
|
|
33
33
|
"entra-id",
|
|
34
34
|
"teams",
|
|
35
35
|
"licenses",
|
|
36
|
-
"typescript"
|
|
36
|
+
"typescript",
|
|
37
|
+
"sharepoint",
|
|
38
|
+
"access-review",
|
|
39
|
+
"service-health"
|
|
37
40
|
],
|
|
38
41
|
"scripts": {
|
|
39
42
|
"build": "tsc",
|