@mediagraph/mcp 1.0.2 → 1.0.3

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 (2) hide show
  1. package/dist/index.js +41 -9
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -69,10 +69,11 @@ var OAuthHandler = class {
69
69
  });
70
70
  return `${this.config.oauthUrl}/oauth/authorize?${params.toString()}`;
71
71
  }
72
+ callbackPromise = null;
72
73
  /**
73
- * Start a local HTTP server to receive the OAuth callback
74
+ * Start the callback server and wait for it to be ready
74
75
  */
75
- async waitForCallback() {
76
+ async startCallbackServer() {
76
77
  return new Promise((resolve, reject) => {
77
78
  this.callbackServer = createServer((req, res) => {
78
79
  const url = new URL2(req.url || "/", `http://localhost:${this.config.redirectPort}`);
@@ -93,7 +94,8 @@ var OAuthHandler = class {
93
94
  </html>
94
95
  `);
95
96
  this.stopCallbackServer();
96
- reject(new Error(errorDescription || error));
97
+ this.callbackPromise?.reject(new Error(errorDescription || error));
98
+ this.callbackPromise = null;
97
99
  return;
98
100
  }
99
101
  if (!code || !state) {
@@ -108,7 +110,8 @@ var OAuthHandler = class {
108
110
  </html>
109
111
  `);
110
112
  this.stopCallbackServer();
111
- reject(new Error("Missing authorization code or state"));
113
+ this.callbackPromise?.reject(new Error("Missing authorization code or state"));
114
+ this.callbackPromise = null;
112
115
  return;
113
116
  }
114
117
  if (state !== this.state) {
@@ -123,7 +126,8 @@ var OAuthHandler = class {
123
126
  </html>
124
127
  `);
125
128
  this.stopCallbackServer();
126
- reject(new Error("State parameter mismatch"));
129
+ this.callbackPromise?.reject(new Error("State parameter mismatch"));
130
+ this.callbackPromise = null;
127
131
  return;
128
132
  }
129
133
  res.writeHead(200, { "Content-Type": "text/html" });
@@ -137,20 +141,43 @@ var OAuthHandler = class {
137
141
  </html>
138
142
  `);
139
143
  this.stopCallbackServer();
140
- resolve({ code, state });
144
+ this.callbackPromise?.resolve({ code, state });
145
+ this.callbackPromise = null;
141
146
  } else {
142
147
  res.writeHead(404);
143
148
  res.end("Not found");
144
149
  }
145
150
  });
151
+ this.callbackServer.on("error", (err) => {
152
+ reject(err);
153
+ });
146
154
  this.callbackServer.listen(this.config.redirectPort, () => {
155
+ resolve();
147
156
  });
157
+ });
158
+ }
159
+ /**
160
+ * Wait for the OAuth callback (server must be started first)
161
+ */
162
+ async waitForCallback() {
163
+ return new Promise((resolve, reject) => {
164
+ this.callbackPromise = { resolve, reject };
148
165
  setTimeout(() => {
149
- this.stopCallbackServer();
150
- reject(new Error("Authorization timed out"));
166
+ if (this.callbackPromise) {
167
+ this.stopCallbackServer();
168
+ this.callbackPromise.reject(new Error("Authorization timed out"));
169
+ this.callbackPromise = null;
170
+ }
151
171
  }, 5 * 60 * 1e3);
152
172
  });
153
173
  }
174
+ /**
175
+ * Start server and wait for callback (convenience method for CLI)
176
+ */
177
+ async startAndWaitForCallback() {
178
+ await this.startCallbackServer();
179
+ return this.waitForCallback();
180
+ }
154
181
  /**
155
182
  * Stop the callback server
156
183
  */
@@ -2962,6 +2989,7 @@ async function runAutoAuth() {
2962
2989
  isAuthInProgress = true;
2963
2990
  try {
2964
2991
  const authUrl = oauthHandler.getAuthorizationUrl();
2992
+ await oauthHandler.startCallbackServer();
2965
2993
  openBrowser(authUrl);
2966
2994
  const { code } = await oauthHandler.waitForCallback();
2967
2995
  const tokens = await oauthHandler.exchangeCode(code);
@@ -2978,6 +3006,7 @@ async function runAutoAuth() {
2978
3006
  return true;
2979
3007
  } catch (error) {
2980
3008
  console.error("Auto-auth failed:", error);
3009
+ oauthHandler.stopCallbackServer();
2981
3010
  return false;
2982
3011
  } finally {
2983
3012
  isAuthInProgress = false;
@@ -3131,7 +3160,10 @@ async function runAuthorize() {
3131
3160
  console.log("Starting Mediagraph OAuth authorization...");
3132
3161
  console.log("");
3133
3162
  const authUrl = oauthHandler.getAuthorizationUrl();
3134
- console.log("Please open this URL in your browser:");
3163
+ await oauthHandler.startCallbackServer();
3164
+ openBrowser(authUrl);
3165
+ console.log("Opening browser for authorization...");
3166
+ console.log("If the browser does not open, please visit:");
3135
3167
  console.log("");
3136
3168
  console.log(authUrl);
3137
3169
  console.log("");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mediagraph/mcp",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "MCP server for Mediagraph - Media Asset Management Platform",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",