@softeria/ms-365-mcp-server 0.157.0 → 0.157.2
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/dist/lib/microsoft-auth.js +8 -2
- package/dist/server.js +17 -3
- package/package.json +1 -1
|
@@ -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;
|
|
@@ -518,7 +529,8 @@ class MicrosoftGraphServer {
|
|
|
518
529
|
this.options.enabledTools,
|
|
519
530
|
this.options.readOnly
|
|
520
531
|
);
|
|
521
|
-
const
|
|
532
|
+
const oboExtraScopes = this.options.obo ? parseAllowedScopes(this.options.extraScopes) ?? [] : [];
|
|
533
|
+
const scopeSet = /* @__PURE__ */ new Set([...baseScopes, ...oboExtraScopes, "User.Read", "offline_access"]);
|
|
522
534
|
microsoftAuthUrl.searchParams.set("scope", Array.from(scopeSet).join(" "));
|
|
523
535
|
res.redirect(microsoftAuthUrl.toString());
|
|
524
536
|
});
|
|
@@ -582,7 +594,8 @@ class MicrosoftGraphServer {
|
|
|
582
594
|
clientSecret,
|
|
583
595
|
tenantId,
|
|
584
596
|
matchedPkceEntry?.serverCodeVerifier || body.code_verifier,
|
|
585
|
-
this.secrets.cloudType
|
|
597
|
+
this.secrets.cloudType,
|
|
598
|
+
this.oboRedemptionScope()
|
|
586
599
|
);
|
|
587
600
|
if (matchedPkceState && this.pkceStore.get(matchedPkceState) === matchedPkceEntry) {
|
|
588
601
|
this.pkceStore.delete(matchedPkceState);
|
|
@@ -602,7 +615,8 @@ class MicrosoftGraphServer {
|
|
|
602
615
|
clientId,
|
|
603
616
|
clientSecret,
|
|
604
617
|
tenantId,
|
|
605
|
-
this.secrets.cloudType
|
|
618
|
+
this.secrets.cloudType,
|
|
619
|
+
this.oboRedemptionScope()
|
|
606
620
|
);
|
|
607
621
|
res.json(result);
|
|
608
622
|
} 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.
|
|
4
|
+
"version": "0.157.2",
|
|
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",
|