@softeria/ms-365-mcp-server 0.179.1 → 0.180.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/PRESETS.md CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  Tool and scope lists assume `--org-mode`; without it, personal accounts get fewer tools and scopes.
6
6
 
7
+ Every preset also includes the account tools (`login`, `logout`, `verify-login`, `list-accounts`, `select-account`, `remove-account`; only `verify-login` and `list-accounts` under `--read-only`). They are not listed or counted below.
8
+
7
9
  ## Summary
8
10
 
9
11
  | Preset | Mode | Tools | Scopes | Org mode | Description |
package/README.md CHANGED
@@ -827,6 +827,8 @@ When running as an MCP server, the following options can be used:
827
827
  --public-url <url> Public base URL for OAuth when behind a reverse proxy (see Open WebUI section and docs/deployment.md)
828
828
  ```
829
829
 
830
+ 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`.
831
+
830
832
  Environment variables:
831
833
 
832
834
  - `READ_ONLY=true|1`: Alternative to --read-only flag
@@ -852,6 +854,7 @@ Environment variables:
852
854
  - `MS365_MCP_MESSAGE_SIGNOFF_PREFIX=<text>`: Signoff prepended to outgoing messages so recipients can tell they were agent-sent, e.g. `🤖`. Default: none. CLI equivalent: `--message-signoff-prefix <text>` (see Message Signoff below)
853
855
  - `MS365_MCP_MESSAGE_SIGNOFF_SUFFIX=<text>`: Signoff appended to outgoing messages. Default: none. CLI equivalent: `--message-signoff-suffix <text>`. `--no-message-signoff` disables both (see Message Signoff below)
854
856
  - `MS365_MCP_RATE_LIMIT_DISABLED=true|1`: Disable per-IP rate limiting in HTTP mode (default: enabled — 30 req/min on `/authorize`, `/token`, `/register`; 120 req/min on `/mcp`)
857
+ - `MS365_MCP_PKCE_SECRET=<32+ random characters>`: For HTTP mode with more than one instance (replicas, serverless, a restart between sign-in steps). The server derives its side of the two-leg PKCE flow from this secret instead of keeping it in process memory, so `/token` works on any instance that has the same secret. Without it, `/token` must reach the instance that served `/authorize`, or sign-in fails with `AADSTS501481`. A shorter secret fails startup
855
858
  - `MS365_MCP_TRUST_PROXY_HOPS=<n>`: Number of trusted reverse-proxy hops in HTTP mode (default `1`). Accurate per-IP rate limiting depends on this matching your deployment — set to the number of proxies in front of the server, `0` to use the raw socket peer IP, or a comma-separated subnet list
856
859
  - `MS365_MCP_ATTACHMENT_PORT=<port>`: Serve the attachment route on its own listener on this port (alternative to --attachment-port; requires `--enable-attachment-urls`)
857
860
  - `MS365_MCP_ATTACHMENT_HOST=<host>`: Interface the `MS365_MCP_ATTACHMENT_PORT` listener binds (alternative to --attachment-host; requires `--attachment-port`). Defaults to the host `--http` bound — which for a wildcard `--http` means both ports answer everywhere and the port split isolates nothing. See "Splitting the attachment listener"
@@ -91,6 +91,8 @@ export async function renderPresetsMarkdown(): Promise<string> {
91
91
  '',
92
92
  'Tool and scope lists assume `--org-mode`; without it, personal accounts get fewer tools and scopes.',
93
93
  '',
94
+ 'Every preset also includes the account tools (`login`, `logout`, `verify-login`, `list-accounts`, `select-account`, `remove-account`; only `verify-login` and `list-accounts` under `--read-only`). They are not listed or counted below.',
95
+ '',
94
96
  '## Summary',
95
97
  '',
96
98
  '| Preset | Mode | Tools | Scopes | Org mode | Description |',
@@ -1,13 +1,34 @@
1
1
  import { z } from "zod";
2
2
  import logger from "./logger.js";
3
3
  import { getRequestTokens } from "./request-context.js";
4
- function registerAuthTools(server, authManager) {
4
+ function readOnlyHintOf(args) {
5
+ const annotations = args.find(
6
+ (arg) => typeof arg === "object" && arg !== null && "readOnlyHint" in arg
7
+ );
8
+ return annotations?.readOnlyHint === true;
9
+ }
10
+ function registerAuthTools(mcpServer, authManager, options = {}) {
11
+ let enabledToolsRegex;
12
+ if (options.enabledTools) {
13
+ try {
14
+ enabledToolsRegex = new RegExp(options.enabledTools, "i");
15
+ } catch {
16
+ }
17
+ }
18
+ const server = {
19
+ tool: ((name, ...args) => {
20
+ if (options.readOnly && !readOnlyHintOf(args)) return void 0;
21
+ if (enabledToolsRegex && !enabledToolsRegex.test(name)) return void 0;
22
+ return mcpServer.tool.call(mcpServer, name, ...args);
23
+ })
24
+ };
5
25
  server.tool(
6
26
  "login",
7
27
  "Authenticate with Microsoft account",
8
28
  {
9
29
  force: z.boolean().default(false).describe("Force a new login even if already logged in")
10
30
  },
31
+ { title: "login", readOnlyHint: false, openWorldHint: false },
11
32
  async ({ force }) => {
12
33
  try {
13
34
  if (!force) {
@@ -70,47 +91,59 @@ function registerAuthTools(server, authManager) {
70
91
  }
71
92
  }
72
93
  );
73
- server.tool("logout", "Log out from Microsoft account", {}, async () => {
74
- try {
75
- await authManager.logout();
76
- return {
77
- content: [
78
- {
79
- type: "text",
80
- text: JSON.stringify({ message: "Logged out successfully" })
81
- }
82
- ]
83
- };
84
- } catch {
94
+ server.tool(
95
+ "logout",
96
+ "Log out from Microsoft account",
97
+ {},
98
+ { title: "logout", readOnlyHint: false, openWorldHint: false },
99
+ async () => {
100
+ try {
101
+ await authManager.logout();
102
+ return {
103
+ content: [
104
+ {
105
+ type: "text",
106
+ text: JSON.stringify({ message: "Logged out successfully" })
107
+ }
108
+ ]
109
+ };
110
+ } catch {
111
+ return {
112
+ content: [
113
+ {
114
+ type: "text",
115
+ text: JSON.stringify({ error: "Logout failed" })
116
+ }
117
+ ]
118
+ };
119
+ }
120
+ }
121
+ );
122
+ server.tool(
123
+ "verify-login",
124
+ "Check current Microsoft authentication status",
125
+ {},
126
+ { title: "verify-login", readOnlyHint: true, openWorldHint: false },
127
+ async () => {
128
+ let testResult;
129
+ try {
130
+ testResult = await authManager.testLogin();
131
+ } catch (error) {
132
+ testResult = {
133
+ success: false,
134
+ message: `Login failed: ${error.message}`
135
+ };
136
+ }
85
137
  return {
86
138
  content: [
87
139
  {
88
140
  type: "text",
89
- text: JSON.stringify({ error: "Logout failed" })
141
+ text: JSON.stringify(testResult)
90
142
  }
91
143
  ]
92
144
  };
93
145
  }
94
- });
95
- server.tool("verify-login", "Check current Microsoft authentication status", {}, async () => {
96
- let testResult;
97
- try {
98
- testResult = await authManager.testLogin();
99
- } catch (error) {
100
- testResult = {
101
- success: false,
102
- message: `Login failed: ${error.message}`
103
- };
104
- }
105
- return {
106
- content: [
107
- {
108
- type: "text",
109
- text: JSON.stringify(testResult)
110
- }
111
- ]
112
- };
113
- });
146
+ );
114
147
  server.tool(
115
148
  "list-accounts",
116
149
  "List all Microsoft accounts configured in this server. Use this to discover available account emails before making tool calls. Reflects accounts added mid-session via --login.",
@@ -164,6 +197,7 @@ function registerAuthTools(server, authManager) {
164
197
  {
165
198
  account: z.string().describe("Email address or account ID of the account to select")
166
199
  },
200
+ { title: "select-account", readOnlyHint: false, openWorldHint: false },
167
201
  async ({ account }) => {
168
202
  try {
169
203
  await authManager.selectAccount(account);
@@ -196,6 +230,7 @@ function registerAuthTools(server, authManager) {
196
230
  {
197
231
  account: z.string().describe("Email address or account ID of the account to remove")
198
232
  },
233
+ { title: "remove-account", readOnlyHint: false, openWorldHint: false },
199
234
  async ({ account }) => {
200
235
  try {
201
236
  const success = await authManager.removeAccount(account);
@@ -752,9 +752,8 @@ const microsoft_graph_customEmojiFromIdentitySet = z.object({
752
752
  }).loose();
753
753
  const microsoft_graph_teamworkCustomEmoji = z.object({
754
754
  id: z.string().describe("The unique identifier for an entity. Read-only.").optional(),
755
- contentBytes: z.string().describe(
756
- "The base64-encoded image content of the emoji. Supported formats include PNG and GIF."
757
- ).nullish(),
755
+ contentBytes: z.string().describe("Write only. Bytes for the hosted content (such as images).").nullish(),
756
+ contentType: z.string().describe("Write only. Content type, such as image/png, image/jpg.").nullish(),
758
757
  createdBy: microsoft_graph_customEmojiFromIdentitySet.optional(),
759
758
  createdDateTime: z.string().regex(
760
759
  /^[0-9]{4,}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]{1,12})?(Z|[+-][0-9][0-9]:[0-9][0-9])$/
@@ -762,7 +761,7 @@ const microsoft_graph_teamworkCustomEmoji = z.object({
762
761
  "The date and time when the emoji was created. The timestamp type represents date and time information using ISO 8601 format and is always in UTC. For example, midnight UTC on Jan 1, 2024, is 2024-01-01T00:00:00Z."
763
762
  ).optional(),
764
763
  displayName: z.string().describe(
765
- "The unique display name of the custom emoji. Key. Must be unique and must not conflict with existing emoji names."
764
+ "The unique display name of the custom emoji. This property is an alternate key and must not conflict with existing emoji names."
766
765
  ).optional()
767
766
  }).loose();
768
767
  const microsoft_graph_teamworkCustomEmojiCollectionResponse = z.object({
@@ -2284,6 +2284,9 @@ const microsoft_graph_calendar = z.object({
2284
2284
  "true if this is the default calendar where new events are created by default, false otherwise."
2285
2285
  ).nullish(),
2286
2286
  isRemovable: z.boolean().describe("Indicates whether this user calendar can be deleted from the user mailbox.").nullish(),
2287
+ isSharedWithMe: z.boolean().describe(
2288
+ "true if someone shared this calendar with the user; false otherwise. This property is always false for a calendar owner. This property is set when sharing is initiated in an Outlook client and can be reset when sharing is canceled through the client or the corresponding calendarPermission resource. Read-only."
2289
+ ).nullish(),
2287
2290
  isTallyingResponses: z.boolean().describe(
2288
2291
  "Indicates whether this user calendar supports tracking of meeting responses. Only meeting invites sent from users' primary calendars support tracking of meeting responses."
2289
2292
  ).nullish(),
@@ -2390,6 +2393,12 @@ const microsoft_graph_labelActionSource = z.enum([
2390
2393
  "none",
2391
2394
  "unknownFutureValue"
2392
2395
  ]);
2396
+ const microsoft_graph_applicationMode = z.enum([
2397
+ "manual",
2398
+ "automatic",
2399
+ "recommended",
2400
+ "unknownFutureValue"
2401
+ ]);
2393
2402
  const microsoft_graph_usageRights = z.enum([
2394
2403
  "unknown",
2395
2404
  "docEdit",
@@ -2424,6 +2433,7 @@ const microsoft_graph_sensitivityLabel = z.lazy(
2424
2433
  () => z.object({
2425
2434
  id: z.string().describe("The unique identifier for an entity. Read-only.").optional(),
2426
2435
  actionSource: microsoft_graph_labelActionSource.optional(),
2436
+ applicationMode: microsoft_graph_applicationMode.optional(),
2427
2437
  autoTooltip: z.string().nullish(),
2428
2438
  description: z.string().nullish(),
2429
2439
  displayName: z.string().nullish(),
@@ -3837,6 +3847,24 @@ const microsoft_graph_attendanceInterval = z.object({
3837
3847
  /^[0-9]{4,}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]{1,12})?(Z|[+-][0-9][0-9]:[0-9][0-9])$/
3838
3848
  ).datetime({ offset: true }).describe("The time the attendee left in UTC.").nullish()
3839
3849
  }).loose();
3850
+ const microsoft_graph_meetingEngagementType = z.enum([
3851
+ "reaction",
3852
+ "hand",
3853
+ "camera",
3854
+ "microphone",
3855
+ "unknownFutureValue"
3856
+ ]);
3857
+ const microsoft_graph_meetingEngagement = z.object({
3858
+ dateTime: z.string().regex(
3859
+ /^[0-9]{4,}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]{1,12})?(Z|[+-][0-9][0-9]:[0-9][0-9])$/
3860
+ ).datetime({ offset: true }).describe(
3861
+ "The date and time when the engagement event occurred. The timestamp type represents date and time information using ISO 8601 format and is always in UTC time. For example, midnight UTC on Jan 1, 2026 is 2026-01-01T00:00:00Z."
3862
+ ).nullish(),
3863
+ engagementSubType: z.string().describe(
3864
+ "The specific engagement action within the engagement type. The possible values are: like, love, applause, laugh, surprised for reaction; raiseHand for hand; cameraOn, cameraOff for camera; and mute, unmute for microphone."
3865
+ ).nullish(),
3866
+ engagementType: microsoft_graph_meetingEngagementType.optional()
3867
+ }).loose();
3840
3868
  const microsoft_graph_virtualEventExternalRegistrationInformation = z.object({
3841
3869
  referrer: z.string().describe(
3842
3870
  "A URL or string that represents the location from which the registrant registered. Optional."
@@ -3849,6 +3877,7 @@ const microsoft_graph_attendanceRecord = z.object({
3849
3877
  id: z.string().describe("The unique identifier for an entity. Read-only.").optional(),
3850
3878
  attendanceIntervals: z.array(microsoft_graph_attendanceInterval).describe("List of time periods between joining and leaving a meeting.").optional(),
3851
3879
  emailAddress: z.string().describe("Email address of the user associated with this attendance record.").nullish(),
3880
+ engagements: z.array(microsoft_graph_meetingEngagement).describe("The list of real-time participant interaction behaviors during a meeting.").optional(),
3852
3881
  externalRegistrationInformation: microsoft_graph_virtualEventExternalRegistrationInformation.optional(),
3853
3882
  identity: microsoft_graph_identity.optional(),
3854
3883
  registrationId: z.string().describe(
@@ -4124,6 +4153,10 @@ const microsoft_graph_wellknownListName = z.enum([
4124
4153
  "flaggedEmails",
4125
4154
  "unknownFutureValue"
4126
4155
  ]);
4156
+ const microsoft_graph_singleValueExtendedProperty = z.object({
4157
+ id: z.string().describe("The unique identifier for an entity. Read-only.").optional(),
4158
+ value: z.string().describe("The value of the property.").nullish()
4159
+ }).loose();
4127
4160
  const microsoft_graph_taskStatus = z.enum([
4128
4161
  "notStarted",
4129
4162
  "inProgress",
@@ -4209,7 +4242,8 @@ const microsoft_graph_todoTask = z.object({
4209
4242
  attachmentSessions: z.array(microsoft_graph_attachmentSession).optional(),
4210
4243
  checklistItems: z.array(microsoft_graph_checklistItem).describe("A collection of checklistItems linked to a task.").optional(),
4211
4244
  extensions: z.array(microsoft_graph_extension).describe("The collection of open extensions defined for the task. Nullable.").optional(),
4212
- linkedResources: z.array(microsoft_graph_linkedResource).describe("A collection of resources linked to the task.").optional()
4245
+ linkedResources: z.array(microsoft_graph_linkedResource).describe("A collection of resources linked to the task.").optional(),
4246
+ singleValueExtendedProperties: z.array(microsoft_graph_singleValueExtendedProperty).describe("A collection of custom fields linked to the task.").optional()
4213
4247
  }).loose();
4214
4248
  const microsoft_graph_todoTaskList = z.object({
4215
4249
  id: z.string().describe("The unique identifier for an entity. Read-only.").optional(),
@@ -4218,6 +4252,9 @@ const microsoft_graph_todoTaskList = z.object({
4218
4252
  isShared: z.boolean().describe("True if the task list is shared with other users").optional(),
4219
4253
  wellknownListName: microsoft_graph_wellknownListName.optional(),
4220
4254
  extensions: z.array(microsoft_graph_extension).describe("The collection of open extensions defined for the task list. Nullable.").optional(),
4255
+ singleValueExtendedProperties: z.array(microsoft_graph_singleValueExtendedProperty).describe(
4256
+ "The collection of single-value extended properties defined for the task list. Nullable."
4257
+ ).optional(),
4221
4258
  tasks: z.array(microsoft_graph_todoTask).describe("The tasks in this task list. Read-only. Nullable.").optional()
4222
4259
  }).loose();
4223
4260
  const microsoft_graph_todoTaskListCollectionResponse = z.object({
@@ -4240,6 +4277,7 @@ const microsoft_graph_linkedResourceCollectionResponse = z.object({
4240
4277
  "@odata.nextLink": z.string().nullable(),
4241
4278
  value: z.array(microsoft_graph_linkedResource)
4242
4279
  }).partial().loose();
4280
+ const microsoft_graph_stringDictionary = z.object({}).loose();
4243
4281
  const microsoft_graph_checkInMethod = z.enum([
4244
4282
  "unspecified",
4245
4283
  "manual",
@@ -4261,10 +4299,16 @@ const microsoft_graph_checkInClaim = z.object({
4261
4299
  const microsoft_graph_place = z.object({
4262
4300
  id: z.string().describe("The unique identifier for an entity. Read-only.").optional(),
4263
4301
  address: microsoft_graph_physicalAddress.optional(),
4302
+ customProperties: microsoft_graph_stringDictionary.optional(),
4264
4303
  displayName: z.string().describe("The name that is associated with the place.").optional(),
4265
4304
  geoCoordinates: microsoft_graph_outlookGeoCoordinates.optional(),
4266
4305
  isWheelChairAccessible: z.boolean().describe("Indicates whether the place is wheelchair accessible.").nullish(),
4267
4306
  label: z.string().describe("User-defined description of the place.").nullish(),
4307
+ lastUpdatedTime: z.string().regex(
4308
+ /^[0-9]{4,}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]{1,12})?(Z|[+-][0-9][0-9]:[0-9][0-9])$/
4309
+ ).datetime({ offset: true }).describe(
4310
+ "The date and time when the place was last updated. The timestamp is in ISO 8601 format and is always in UTC. Read-only. Nullable."
4311
+ ).nullish(),
4268
4312
  parentId: z.string().describe("The ID of a parent place.").nullish(),
4269
4313
  phone: z.string().describe("The phone number of the place.").nullish(),
4270
4314
  placeId: z.string().describe("A stable service-level identifier for the place object used by Places workloads.").nullish(),
@@ -4283,10 +4327,16 @@ const microsoft_graph_placeFeatureEnablement = z.enum([
4283
4327
  const microsoft_graph_room = z.object({
4284
4328
  id: z.string().describe("The unique identifier for an entity. Read-only.").optional(),
4285
4329
  address: microsoft_graph_physicalAddress.optional(),
4330
+ customProperties: microsoft_graph_stringDictionary.optional(),
4286
4331
  displayName: z.string().describe("The name that is associated with the place.").optional(),
4287
4332
  geoCoordinates: microsoft_graph_outlookGeoCoordinates.optional(),
4288
4333
  isWheelChairAccessible: z.boolean().describe("Indicates whether the place is wheelchair accessible.").nullish(),
4289
4334
  label: z.string().describe("User-defined description of the place.").nullish(),
4335
+ lastUpdatedTime: z.string().regex(
4336
+ /^[0-9]{4,}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]{1,12})?(Z|[+-][0-9][0-9]:[0-9][0-9])$/
4337
+ ).datetime({ offset: true }).describe(
4338
+ "The date and time when the place was last updated. The timestamp is in ISO 8601 format and is always in UTC. Read-only. Nullable."
4339
+ ).nullish(),
4290
4340
  parentId: z.string().describe("The ID of a parent place.").nullish(),
4291
4341
  phone: z.string().describe("The phone number of the place.").nullish(),
4292
4342
  placeId: z.string().describe("A stable service-level identifier for the place object used by Places workloads.").nullish(),
@@ -4310,10 +4360,16 @@ const microsoft_graph_placeMode = z.object({}).loose();
4310
4360
  const microsoft_graph_workspace = z.object({
4311
4361
  id: z.string().describe("The unique identifier for an entity. Read-only.").optional(),
4312
4362
  address: microsoft_graph_physicalAddress.optional(),
4363
+ customProperties: microsoft_graph_stringDictionary.optional(),
4313
4364
  displayName: z.string().describe("The name that is associated with the place.").optional(),
4314
4365
  geoCoordinates: microsoft_graph_outlookGeoCoordinates.optional(),
4315
4366
  isWheelChairAccessible: z.boolean().describe("Indicates whether the place is wheelchair accessible.").nullish(),
4316
4367
  label: z.string().describe("User-defined description of the place.").nullish(),
4368
+ lastUpdatedTime: z.string().regex(
4369
+ /^[0-9]{4,}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]{1,12})?(Z|[+-][0-9][0-9]:[0-9][0-9])$/
4370
+ ).datetime({ offset: true }).describe(
4371
+ "The date and time when the place was last updated. The timestamp is in ISO 8601 format and is always in UTC. Read-only. Nullable."
4372
+ ).nullish(),
4317
4373
  parentId: z.string().describe("The ID of a parent place.").nullish(),
4318
4374
  phone: z.string().describe("The phone number of the place.").nullish(),
4319
4375
  placeId: z.string().describe("A stable service-level identifier for the place object used by Places workloads.").nullish(),
@@ -4336,10 +4392,16 @@ const microsoft_graph_workspace = z.object({
4336
4392
  const microsoft_graph_roomList = z.object({
4337
4393
  id: z.string().describe("The unique identifier for an entity. Read-only.").optional(),
4338
4394
  address: microsoft_graph_physicalAddress.optional(),
4395
+ customProperties: microsoft_graph_stringDictionary.optional(),
4339
4396
  displayName: z.string().describe("The name that is associated with the place.").optional(),
4340
4397
  geoCoordinates: microsoft_graph_outlookGeoCoordinates.optional(),
4341
4398
  isWheelChairAccessible: z.boolean().describe("Indicates whether the place is wheelchair accessible.").nullish(),
4342
4399
  label: z.string().describe("User-defined description of the place.").nullish(),
4400
+ lastUpdatedTime: z.string().regex(
4401
+ /^[0-9]{4,}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]{1,12})?(Z|[+-][0-9][0-9]:[0-9][0-9])$/
4402
+ ).datetime({ offset: true }).describe(
4403
+ "The date and time when the place was last updated. The timestamp is in ISO 8601 format and is always in UTC. Read-only. Nullable."
4404
+ ).nullish(),
4343
4405
  parentId: z.string().describe("The ID of a parent place.").nullish(),
4344
4406
  phone: z.string().describe("The phone number of the place.").nullish(),
4345
4407
  placeId: z.string().describe("A stable service-level identifier for the place object used by Places workloads.").nullish(),
@@ -5134,6 +5196,7 @@ const schemas = {
5134
5196
  microsoft_graph_contactFolderCollectionResponse,
5135
5197
  microsoft_graph_contactCollectionResponse,
5136
5198
  microsoft_graph_labelActionSource,
5199
+ microsoft_graph_applicationMode,
5137
5200
  microsoft_graph_usageRights,
5138
5201
  microsoft_graph_usageRightsIncluded,
5139
5202
  microsoft_graph_sensitivityLabel,
@@ -5275,6 +5338,8 @@ const schemas = {
5275
5338
  microsoft_graph_onlineMeetingCollectionResponse,
5276
5339
  microsoft_graph_virtualEventExternalInformation,
5277
5340
  microsoft_graph_attendanceInterval,
5341
+ microsoft_graph_meetingEngagementType,
5342
+ microsoft_graph_meetingEngagement,
5278
5343
  microsoft_graph_virtualEventExternalRegistrationInformation,
5279
5344
  microsoft_graph_attendanceRecord,
5280
5345
  microsoft_graph_meetingAttendanceReport,
@@ -5310,6 +5375,7 @@ const schemas = {
5310
5375
  microsoft_graph_keyValuePair,
5311
5376
  send_my_activity_notification_Body,
5312
5377
  microsoft_graph_wellknownListName,
5378
+ microsoft_graph_singleValueExtendedProperty,
5313
5379
  microsoft_graph_taskStatus,
5314
5380
  microsoft_graph_attachmentBase,
5315
5381
  microsoft_graph_attachmentSession,
@@ -5321,6 +5387,7 @@ const schemas = {
5321
5387
  microsoft_graph_todoTaskCollectionResponse,
5322
5388
  microsoft_graph_checklistItemCollectionResponse,
5323
5389
  microsoft_graph_linkedResourceCollectionResponse,
5390
+ microsoft_graph_stringDictionary,
5324
5391
  microsoft_graph_checkInMethod,
5325
5392
  microsoft_graph_checkInClaim,
5326
5393
  microsoft_graph_place,
package/dist/server.js CHANGED
@@ -143,6 +143,20 @@ function describeBoundAddress(bound) {
143
143
  return { label: authority, authority };
144
144
  }
145
145
  const PKCE_MAX_AGE_MS = 60 * 60 * 1e3;
146
+ const PKCE_SECRET_MIN_LENGTH = 32;
147
+ function deriveServerCodeVerifier(secret, clientCodeChallenge) {
148
+ return crypto.createHmac("sha256", secret).update(clientCodeChallenge).digest("base64url");
149
+ }
150
+ function statelessPkceSecret(env = process.env) {
151
+ const secret = env.MS365_MCP_PKCE_SECRET;
152
+ if (secret === void 0 || secret === "") return void 0;
153
+ if (secret.length < PKCE_SECRET_MIN_LENGTH) {
154
+ throw new Error(
155
+ `MS365_MCP_PKCE_SECRET must be at least ${PKCE_SECRET_MIN_LENGTH} characters; a short secret makes the derived PKCE verifier guessable.`
156
+ );
157
+ }
158
+ return secret;
159
+ }
146
160
  class MicrosoftGraphServer {
147
161
  constructor(authManager, options = {}) {
148
162
  this.version = "0.0.0";
@@ -200,7 +214,13 @@ class MicrosoftGraphServer {
200
214
  );
201
215
  const shouldRegisterAuthTools = !this.options.appMode && (!this.options.http || this.options.enableAuthTools);
202
216
  if (shouldRegisterAuthTools) {
203
- registerAuthTools(server, this.authManager);
217
+ registerAuthTools(server, this.authManager, {
218
+ enabledTools: this.options.enabledTools,
219
+ // With MS365_MCP_OAUTH_TOKEN the token comes from outside, so there is
220
+ // nothing to log in to or switch between. verify-login still checks the
221
+ // token, and list-accounts says cached accounts can't be used (#512).
222
+ readOnly: this.options.readOnly || Boolean(process.env.MS365_MCP_OAUTH_TOKEN)
223
+ });
204
224
  }
205
225
  const registrationOptions = {
206
226
  readOnly: this.options.readOnly,
@@ -340,6 +360,10 @@ class MicrosoftGraphServer {
340
360
  }
341
361
  if (this.options.http) {
342
362
  const { host, port } = parseHttpOption(this.options.http);
363
+ this.pkceSecret = statelessPkceSecret();
364
+ if (this.pkceSecret) {
365
+ logger.info("Two-leg PKCE is stateless (MS365_MCP_PKCE_SECRET set)");
366
+ }
343
367
  const app = express();
344
368
  if (this.isLoopbackOnlyHttp()) {
345
369
  app.use(hostHeaderValidation(LOOPBACK_HOSTNAMES));
@@ -498,7 +522,20 @@ class MicrosoftGraphServer {
498
522
  }
499
523
  }
500
524
  }
501
- if (clientCodeChallenge && state) {
525
+ if (clientCodeChallenge && this.pkceSecret) {
526
+ if (clientCodeChallengeMethod !== "S256") {
527
+ res.status(400).json({
528
+ error: "invalid_request",
529
+ error_description: "code_challenge_method must be S256"
530
+ });
531
+ return;
532
+ }
533
+ const serverCodeVerifier = deriveServerCodeVerifier(this.pkceSecret, clientCodeChallenge);
534
+ const serverCodeChallenge = crypto.createHash("sha256").update(serverCodeVerifier).digest("base64url");
535
+ microsoftAuthUrl.searchParams.set("code_challenge", serverCodeChallenge);
536
+ microsoftAuthUrl.searchParams.set("code_challenge_method", "S256");
537
+ logger.info("Two-leg PKCE (stateless): derived server challenge");
538
+ } else if (clientCodeChallenge && state) {
502
539
  const serverCodeVerifier = crypto.randomBytes(32).toString("base64url");
503
540
  const serverCodeChallenge = crypto.createHash("sha256").update(serverCodeVerifier).digest("base64url");
504
541
  const maxEntries = 1e3;
@@ -581,7 +618,12 @@ class MicrosoftGraphServer {
581
618
  });
582
619
  let matchedPkceState;
583
620
  let matchedPkceEntry;
584
- if (body.code_verifier) {
621
+ let derivedServerVerifier;
622
+ if (body.code_verifier && this.pkceSecret) {
623
+ const clientChallenge = crypto.createHash("sha256").update(body.code_verifier).digest("base64url");
624
+ derivedServerVerifier = deriveServerCodeVerifier(this.pkceSecret, clientChallenge);
625
+ logger.info("Two-leg PKCE (stateless): derived server verifier");
626
+ } else if (body.code_verifier) {
585
627
  const clientVerifier = body.code_verifier;
586
628
  const clientChallengeComputed = crypto.createHash("sha256").update(clientVerifier).digest("base64url");
587
629
  for (const [state, pkceData] of this.pkceStore) {
@@ -601,7 +643,7 @@ class MicrosoftGraphServer {
601
643
  clientId,
602
644
  clientSecret,
603
645
  tenantId,
604
- matchedPkceEntry?.serverCodeVerifier || body.code_verifier,
646
+ derivedServerVerifier || matchedPkceEntry?.serverCodeVerifier || body.code_verifier,
605
647
  this.secrets.cloudType,
606
648
  this.oboRedemptionScope()
607
649
  );
@@ -899,10 +941,13 @@ class MicrosoftGraphServer {
899
941
  }
900
942
  var server_default = MicrosoftGraphServer;
901
943
  export {
944
+ PKCE_SECRET_MIN_LENGTH,
902
945
  server_default as default,
946
+ deriveServerCodeVerifier,
903
947
  isLoopbackHost,
904
948
  loopbackOriginValidation,
905
949
  parseAttachmentHostOption,
906
950
  parseAttachmentPortOption,
907
- parseHttpOption
951
+ parseHttpOption,
952
+ statelessPkceSecret
908
953
  };
@@ -60,6 +60,14 @@ const PRESET_META = {
60
60
  }
61
61
  };
62
62
  const UNIVERSAL_UTILITY_TOOLS = ["download-bytes", "download-bytes-to-file"];
63
+ const ACCOUNT_TOOLS = [
64
+ "login",
65
+ "logout",
66
+ "verify-login",
67
+ "list-accounts",
68
+ "select-account",
69
+ "remove-account"
70
+ ];
63
71
  const SCOPED_UTILITY_TOOLS = {
64
72
  "get-download-url": ["files", "onedrive", "personal", "work", "search"],
65
73
  "get-upload-url": ["mail", "calendar", "outlook", "personal", "work"],
@@ -79,7 +87,11 @@ for (const [tool, presets] of Object.entries(SCOPED_UTILITY_TOOLS)) {
79
87
  function getToolsForPreset(preset) {
80
88
  if (preset === "all") {
81
89
  const endpointNames2 = [...new Set(endpointEntries.map((e) => e.toolName))];
82
- const utilityNames = [...UNIVERSAL_UTILITY_TOOLS, ...Object.keys(SCOPED_UTILITY_TOOLS)];
90
+ const utilityNames = [
91
+ ...UNIVERSAL_UTILITY_TOOLS,
92
+ ...Object.keys(SCOPED_UTILITY_TOOLS),
93
+ ...ACCOUNT_TOOLS
94
+ ];
83
95
  return [.../* @__PURE__ */ new Set([...endpointNames2, ...utilityNames])].sort();
84
96
  }
85
97
  const endpointNames = [
@@ -91,6 +103,7 @@ function getToolsForPreset(preset) {
91
103
  return [
92
104
  .../* @__PURE__ */ new Set([
93
105
  ...endpointNames,
106
+ ...ACCOUNT_TOOLS,
94
107
  ...PRESET_META[preset]?.omitUniversalUtilities ? [] : UNIVERSAL_UTILITY_TOOLS,
95
108
  ...Object.entries(SCOPED_UTILITY_TOOLS).filter(([, presets]) => presets.includes(preset)).map(([name]) => name)
96
109
  ])
@@ -97,8 +97,10 @@ docker run -p 3000:3000 \
97
97
  --max-replicas 3 \
98
98
  --cpu 0.5 --memory 1Gi \
99
99
  --system-assigned \
100
+ --secrets "pkce-secret=$(openssl rand -base64 48)" \
100
101
  --env-vars \
101
102
  "MS365_MCP_KEYVAULT_URL=https://your-keyvault.vault.azure.net" \
103
+ "MS365_MCP_PKCE_SECRET=secretref:pkce-secret" \
102
104
  "MS365_MCP_ORG_MODE=true" \
103
105
  "MS365_MCP_PUBLIC_URL=https://mcp.example.com" \
104
106
  --command "node" "dist/index.js" "--http" "3000" "--org-mode"
@@ -224,6 +226,7 @@ The client automatically discovers OAuth endpoints and opens a browser for authe
224
226
  ## Security Considerations
225
227
 
226
228
  - **Stateless**: the server does not store tokens — each request carries the user's Bearer token
229
+ - **More than one instance? Set `MS365_MCP_PKCE_SECRET`** (32+ random characters, the same on every instance). Otherwise the two-leg PKCE flow keeps a mapping in process memory between `/authorize` and `/token`, and a sign-in whose `/token` lands on another replica, or comes after a restart, fails with `AADSTS501481`. With the secret, the server side of the PKCE pair is derived from the client's challenge and nothing is stored. A single instance can leave it unset. Clients must use `code_challenge_method=S256`. Setting or rotating the secret fails sign-ins that are in progress at that moment.
227
230
  - **Account pinning**: `MS365_MCP_EXPECTED_USERNAME` and `MS365_MCP_EXPECTED_HOME_ACCOUNT_ID` protect local MSAL cache flows for headless stdio deployments. In `--http`, `--obo`, or `MS365_MCP_OAUTH_TOKEN` deployments they are warning-only because Graph calls use request-provided tokens.
228
231
  - **Admin consent**: grant tenant-wide consent to avoid per-user consent prompts
229
232
  - **Managed identity**: use managed identity for Key Vault access (no secrets in environment variables)
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.179.1",
4
+ "version": "0.180.1",
5
5
  "description": " A Model Context Protocol (MCP) server for interacting with Microsoft 365 and Office services through the Graph API",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",