@softeria/ms-365-mcp-server 0.157.0 → 0.157.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.
@@ -169,7 +169,7 @@ function unwrapToken(result, failureMessage) {
169
169
  logger.error(`${failureMessage}: ${result.raw}`);
170
170
  throw new Error(`${failureMessage}: ${result.raw}`);
171
171
  }
172
- async function exchangeCodeForToken(code, redirectUri, clientId, clientSecret, tenantId = "common", codeVerifier, cloudType = "global") {
172
+ async function exchangeCodeForToken(code, redirectUri, clientId, clientSecret, tenantId = "common", codeVerifier, cloudType = "global", scope) {
173
173
  const cloudEndpoints = getCloudEndpoints(cloudType);
174
174
  const params = new URLSearchParams({
175
175
  grant_type: "authorization_code",
@@ -180,6 +180,9 @@ async function exchangeCodeForToken(code, redirectUri, clientId, clientSecret, t
180
180
  if (codeVerifier) {
181
181
  params.append("code_verifier", codeVerifier);
182
182
  }
183
+ if (scope) {
184
+ params.append("scope", scope);
185
+ }
183
186
  return requestToken(
184
187
  `${cloudEndpoints.authority}/${tenantId}/oauth2/v2.0/token`,
185
188
  params,
@@ -187,13 +190,16 @@ async function exchangeCodeForToken(code, redirectUri, clientId, clientSecret, t
187
190
  "Failed to exchange code for token"
188
191
  );
189
192
  }
190
- async function refreshAccessToken(refreshToken, clientId, clientSecret, tenantId = "common", cloudType = "global") {
193
+ async function refreshAccessToken(refreshToken, clientId, clientSecret, tenantId = "common", cloudType = "global", scope) {
191
194
  const cloudEndpoints = getCloudEndpoints(cloudType);
192
195
  const params = new URLSearchParams({
193
196
  grant_type: "refresh_token",
194
197
  refresh_token: refreshToken,
195
198
  client_id: clientId
196
199
  });
200
+ if (scope) {
201
+ params.append("scope", scope);
202
+ }
197
203
  return requestToken(
198
204
  `${cloudEndpoints.authority}/${tenantId}/oauth2/v2.0/token`,
199
205
  params,
package/dist/server.js CHANGED
@@ -217,6 +217,17 @@ class MicrosoftGraphServer {
217
217
  installToolSchemaRefNormalization(server);
218
218
  return server;
219
219
  }
220
+ /**
221
+ * Under --obo the token Entra issues to the MCP client is for this app
222
+ * itself (`<clientId>/access_as_user`). Personal Microsoft accounts refuse
223
+ * to redeem a code or refresh token for that audience unless the request
224
+ * names the scope (AADSTS70011), so both /token grants send it in OBO mode.
225
+ * Outside OBO the request is unchanged.
226
+ */
227
+ oboRedemptionScope() {
228
+ if (!this.options.obo || !this.secrets?.clientId) return void 0;
229
+ return `${this.secrets.clientId}/access_as_user offline_access`;
230
+ }
220
231
  async initialize(version) {
221
232
  this.secrets = await getSecrets();
222
233
  this.version = version;
@@ -582,7 +593,8 @@ class MicrosoftGraphServer {
582
593
  clientSecret,
583
594
  tenantId,
584
595
  matchedPkceEntry?.serverCodeVerifier || body.code_verifier,
585
- this.secrets.cloudType
596
+ this.secrets.cloudType,
597
+ this.oboRedemptionScope()
586
598
  );
587
599
  if (matchedPkceState && this.pkceStore.get(matchedPkceState) === matchedPkceEntry) {
588
600
  this.pkceStore.delete(matchedPkceState);
@@ -602,7 +614,8 @@ class MicrosoftGraphServer {
602
614
  clientId,
603
615
  clientSecret,
604
616
  tenantId,
605
- this.secrets.cloudType
617
+ this.secrets.cloudType,
618
+ this.oboRedemptionScope()
606
619
  );
607
620
  res.json(result);
608
621
  } else {
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.157.0",
4
+ "version": "0.157.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",