@frustrated/ms-graph-mcp 0.1.7 → 0.1.8

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.
Files changed (3) hide show
  1. package/bun.lock +1 -1
  2. package/package.json +1 -1
  3. package/src/auth.ts +18 -23
package/bun.lock CHANGED
@@ -5,7 +5,7 @@
5
5
  "": {
6
6
  "name": "@frustrated/ms-graph-mcp",
7
7
  "dependencies": {
8
- "@azure/msal-node": "latest",
8
+ "@azure/msal-node": "^3.0.0",
9
9
  "@commander-js/extra-typings": "^14.0.0",
10
10
  "@microsoft/microsoft-graph-client": "^3.0.0",
11
11
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frustrated/ms-graph-mcp",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "A JSR-based TypeScript MCP package for personal Microsoft Graph access via CLI",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
package/src/auth.ts CHANGED
@@ -61,22 +61,10 @@ async function loadTokenCache(): Promise<boolean> {
61
61
 
62
62
  export async function initAuth(): Promise<void> {
63
63
  console.log("Initiating Microsoft Graph authentication...");
64
- console.log(
65
- "Please ensure you have registered a multi-tenant application in Azure AD with the following redirect URI: http://localhost:PORT/auth-callback",
66
- );
67
64
 
68
65
  const cryptoProvider = new CryptoProvider();
69
66
  const pkceCodes = await cryptoProvider.generatePkceCodes();
70
67
 
71
- const authCodeUrlParameters = {
72
- scopes: SCOPES,
73
- redirectUri: `http://localhost:0${REDIRECT_URI_PATH}`,
74
- codeChallenge: pkceCodes.challenge,
75
- codeChallengeMethod: "S256" as const,
76
- };
77
-
78
- const authCodeUrl = await pca.getAuthCodeUrl(authCodeUrlParameters);
79
-
80
68
  return new Promise((resolve, reject) => {
81
69
  const server = createServer(async (req, res) => {
82
70
  if (req.url?.startsWith(REDIRECT_URI_PATH)) {
@@ -86,10 +74,11 @@ export async function initAuth(): Promise<void> {
86
74
  if (code) {
87
75
  try {
88
76
  const addr = server.address() as AddressInfo;
77
+ const redirectUri = `http://localhost:${addr.port}${REDIRECT_URI_PATH}`;
89
78
  const tokenResult = await pca.acquireTokenByCode({
90
79
  code,
91
80
  scopes: SCOPES,
92
- redirectUri: `http://localhost:${addr.port}${REDIRECT_URI_PATH}`,
81
+ redirectUri,
93
82
  codeVerifier: pkceCodes.verifier,
94
83
  });
95
84
 
@@ -123,16 +112,22 @@ export async function initAuth(): Promise<void> {
123
112
  }
124
113
  });
125
114
 
126
- server.listen(0, () => {
127
- const addr = server.address() as AddressInfo;
128
- const finalRedirectUri = `http://localhost:${addr.port}${REDIRECT_URI_PATH}`;
129
- const finalAuthUrl = authCodeUrl.replace(
130
- `http://localhost:0${REDIRECT_URI_PATH}`,
131
- finalRedirectUri,
132
- );
133
- console.log(
134
- `\nOpen this URL in your browser to authenticate:\n\n ${finalAuthUrl}\n`,
135
- );
115
+ server.listen(0, async () => {
116
+ try {
117
+ const addr = server.address() as AddressInfo;
118
+ const redirectUri = `http://localhost:${addr.port}${REDIRECT_URI_PATH}`;
119
+ const authCodeUrl = await pca.getAuthCodeUrl({
120
+ scopes: SCOPES,
121
+ redirectUri,
122
+ codeChallenge: pkceCodes.challenge,
123
+ codeChallengeMethod: "S256" as const,
124
+ });
125
+ console.log(
126
+ `\nOpen this URL in your browser to authenticate:\n\n ${authCodeUrl}\n`,
127
+ );
128
+ } catch (err) {
129
+ server.close(() => reject(err));
130
+ }
136
131
  });
137
132
 
138
133
  server.on("error", (err) => {