@egain/egain-mcp-server 1.0.24 → 1.0.26

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/bin/mcp-server.js CHANGED
@@ -40890,6 +40890,15 @@ class AuthenticationHook {
40890
40890
  }
40891
40891
  return "--incognito";
40892
40892
  }
40893
+ cleanEnvironmentUrl(url) {
40894
+ if (!url) {
40895
+ return url;
40896
+ }
40897
+ let cleaned = url.trim();
40898
+ cleaned = cleaned.replace(/^https?:\/\//i, "");
40899
+ cleaned = cleaned.replace(/\/+$/, "");
40900
+ return cleaned;
40901
+ }
40893
40902
  saveConfigToFile(config) {
40894
40903
  try {
40895
40904
  const configPath = getConfigPath();
@@ -40909,6 +40918,14 @@ class AuthenticationHook {
40909
40918
  if (fs.existsSync(configPath)) {
40910
40919
  const configContent = fs.readFileSync(configPath, "utf8");
40911
40920
  const config = JSON.parse(configContent);
40921
+ if (config.environmentUrl) {
40922
+ const cleaned = this.cleanEnvironmentUrl(config.environmentUrl);
40923
+ if (cleaned) {
40924
+ config.environmentUrl = cleaned;
40925
+ } else {
40926
+ delete config.environmentUrl;
40927
+ }
40928
+ }
40912
40929
  console.error(`✅ Loaded config from: ${configPath}`);
40913
40930
  return config;
40914
40931
  }
@@ -40944,9 +40961,13 @@ class AuthenticationHook {
40944
40961
  const cleanKey = key;
40945
40962
  const cleanValue = value.replace(/['"]/g, "");
40946
40963
  switch (cleanKey) {
40947
- case "EGAIN_URL":
40948
- config.environmentUrl = cleanValue;
40964
+ case "EGAIN_URL": {
40965
+ const cleaned = this.cleanEnvironmentUrl(cleanValue);
40966
+ if (cleaned) {
40967
+ config.environmentUrl = cleaned;
40968
+ }
40949
40969
  break;
40970
+ }
40950
40971
  case "CLIENT_ID":
40951
40972
  config.clientId = cleanValue;
40952
40973
  break;
@@ -40962,9 +40983,13 @@ class AuthenticationHook {
40962
40983
  case "SCOPE_PREFIX":
40963
40984
  config.scopePrefix = cleanValue;
40964
40985
  break;
40965
- case "EGAIN_ENVIRONMENT_URL":
40966
- config.environmentUrl = cleanValue;
40986
+ case "EGAIN_ENVIRONMENT_URL": {
40987
+ const cleaned = this.cleanEnvironmentUrl(cleanValue);
40988
+ if (cleaned) {
40989
+ config.environmentUrl = cleaned;
40990
+ }
40967
40991
  break;
40992
+ }
40968
40993
  case "EGAIN_CLIENT_ID":
40969
40994
  config.clientId = cleanValue;
40970
40995
  break;
@@ -41067,7 +41092,11 @@ class AuthenticationHook {
41067
41092
  }
41068
41093
  const prefix = scopePrefix || "";
41069
41094
  const scope = `${prefix}knowledge.portalmgr.manage ${prefix}knowledge.portalmgr.read ${prefix}core.aiservices.read`;
41070
- existingParams.set("domain_hint", environmentUrl.trim());
41095
+ const cleanedEnvironmentUrl = this.cleanEnvironmentUrl(environmentUrl);
41096
+ if (!cleanedEnvironmentUrl) {
41097
+ throw new Error("Environment URL is required");
41098
+ }
41099
+ existingParams.set("domain_hint", cleanedEnvironmentUrl);
41071
41100
  existingParams.set("client_id", clientId.trim());
41072
41101
  existingParams.set("response_type", "code");
41073
41102
  existingParams.set("redirect_uri", cleanRedirectUri);
@@ -41392,14 +41421,17 @@ class AuthenticationHook {
41392
41421
  return;
41393
41422
  }
41394
41423
  }
41424
+ const cleanedEnvUrl = this.cleanEnvironmentUrl(config.egainUrl);
41395
41425
  this.authConfig = {
41396
- environmentUrl: config.egainUrl,
41397
41426
  authUrl: config.authUrl,
41398
41427
  accessUrl: config.accessTokenUrl,
41399
41428
  clientId: config.clientId,
41400
41429
  redirectUri: config.redirectUrl,
41401
41430
  scopePrefix: config.scopePrefix || undefined
41402
41431
  };
41432
+ if (cleanedEnvUrl) {
41433
+ this.authConfig.environmentUrl = cleanedEnvUrl;
41434
+ }
41403
41435
  try {
41404
41436
  this.saveConfigToFile(this.authConfig);
41405
41437
  console.error("✅ Configuration saved to secure file storage");
@@ -42030,34 +42062,42 @@ class AuthenticationHook {
42030
42062
  }
42031
42063
  }
42032
42064
  if (currentUrl && currentUrl.includes("error=")) {
42033
- if (currentUrl !== lastErrorUrl) {
42065
+ const errorMatch = currentUrl.match(/[?&]error=([^&]+)/);
42066
+ const errorDescMatch = currentUrl.match(/error_description=([^&]+)/);
42067
+ const error = errorMatch && errorMatch[1] ? decodeURIComponent(errorMatch[1]) : "unknown_error";
42068
+ const errorDesc = errorDescMatch && errorDescMatch[1] ? decodeURIComponent(errorDescMatch[1]) : "No description";
42069
+ const errorLower = error.toLowerCase();
42070
+ const errorDescLower = errorDesc.toLowerCase();
42071
+ const isScopeError = error === "invalid_scope" || errorDescLower.includes("scope") || errorLower.includes("scope");
42072
+ const isRetryableError = error === "access_denied" || error === "invalid_grant" || errorDescLower.includes("password") || errorLower.includes("password") || errorDescLower.includes("username") || errorLower.includes("username") || errorDescLower.includes("credential") || errorLower.includes("credential") || errorLower.includes("user not found") || errorDescLower.includes("user not found");
42073
+ const isNewError = currentUrl !== lastErrorUrl;
42074
+ if (isNewError) {
42034
42075
  lastErrorUrl = currentUrl;
42035
- const errorMatch = currentUrl.match(/[?&]error=([^&]+)/);
42036
- const errorDescMatch = currentUrl.match(/error_description=([^&]+)/);
42037
- const error = errorMatch && errorMatch[1] ? decodeURIComponent(errorMatch[1]) : "unknown_error";
42038
- const errorDesc = errorDescMatch && errorDescMatch[1] ? decodeURIComponent(errorDescMatch[1]) : "No description";
42039
- const isScopeError = error === "invalid_scope" || errorDesc.toLowerCase().includes("scope");
42040
- const isRetryableError = error === "access_denied" || error === "invalid_grant" || errorDesc.toLowerCase().includes("password") || errorDesc.toLowerCase().includes("username") || errorDesc.toLowerCase().includes("credential");
42041
- if (!oAuthErrorLogged) {
42076
+ }
42077
+ if (isScopeError) {
42078
+ if (!oAuthErrorLogged || isNewError) {
42042
42079
  console.error("❌ OAuth authentication error:", `${error} - ${errorDesc}`);
42043
- if (isScopeError) {
42044
- console.error("\uD83D\uDCA1 This is a configuration error. Please check your scope settings and close this window.");
42045
- console.error("\uD83D\uDED1 Stopping monitoring - please fix the configuration and try again.");
42046
- oAuthErrorLogged = true;
42047
- this.stopConfigServer();
42048
- return;
42049
- } else if (isRetryableError) {
42050
- console.error("\uD83D\uDCA1 The configuration server will remain running. Please try again with correct credentials.");
42051
- console.error("\uD83D\uDD0D Continuing to monitor browser for authorization code...");
42052
- oAuthErrorLogged = true;
42053
- } else {
42054
- console.error("\uD83D\uDCA1 Please check the error message displayed in your browser and close the window.");
42055
- console.error("\uD83D\uDED1 Stopping monitoring.");
42056
- oAuthErrorLogged = true;
42057
- this.stopConfigServer();
42058
- return;
42059
- }
42080
+ console.error("\uD83D\uDCA1 This is a configuration error. Please check your scope settings and close this window.");
42081
+ console.error("\uD83D\uDED1 Stopping monitoring - please fix the configuration and try again.");
42082
+ oAuthErrorLogged = true;
42083
+ }
42084
+ this.stopConfigServer();
42085
+ return;
42086
+ } else if (!isRetryableError) {
42087
+ if (!oAuthErrorLogged || isNewError) {
42088
+ console.error(" OAuth authentication error:", `${error} - ${errorDesc}`);
42089
+ console.error("\uD83D\uDCA1 Please check the error message displayed in your browser and close the window.");
42090
+ console.error("\uD83D\uDED1 Stopping monitoring.");
42091
+ oAuthErrorLogged = true;
42060
42092
  }
42093
+ this.stopConfigServer();
42094
+ return;
42095
+ }
42096
+ if (isNewError) {
42097
+ console.error("❌ OAuth authentication error:", `${error} - ${errorDesc}`);
42098
+ console.error("\uD83D\uDCA1 The configuration server will remain running. Please try again with correct credentials.");
42099
+ console.error("\uD83D\uDD0D Continuing to monitor browser for authorization code...");
42100
+ oAuthErrorLogged = true;
42061
42101
  }
42062
42102
  } else {
42063
42103
  if (lastErrorUrl !== null) {
@@ -48688,5 +48728,5 @@ export {
48688
48728
  app
48689
48729
  };
48690
48730
 
48691
- //# debugId=3C2C86165F82B22964756E2164756E21
48731
+ //# debugId=BD1B9CC5744D3D7D64756E2164756E21
48692
48732
  //# sourceMappingURL=mcp-server.js.map