powerautomate-mcp 0.9.0 → 0.9.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/index.js CHANGED
@@ -3837,6 +3837,7 @@ var DataverseApi = class {
3837
3837
  */
3838
3838
  static getDataverseUrl(environmentId, region = "crm") {
3839
3839
  const regionMap = {
3840
+ // Power Platform region names
3840
3841
  unitedstates: "crm",
3841
3842
  europe: "crm4",
3842
3843
  uk: "crm11",
@@ -3853,7 +3854,35 @@ var DataverseApi = class {
3853
3854
  government: "crm9",
3854
3855
  gcc: "crm9",
3855
3856
  gcchigh: "crm.microsoft.us",
3856
- dod: "crm.appsplatform.us"
3857
+ dod: "crm.appsplatform.us",
3858
+ // Azure region names (map to same CRM domains)
3859
+ westus: "crm",
3860
+ eastus: "crm",
3861
+ centralus: "crm",
3862
+ westus2: "crm",
3863
+ eastus2: "crm",
3864
+ southcentralus: "crm",
3865
+ northcentralus: "crm",
3866
+ westeurope: "crm4",
3867
+ northeurope: "crm4",
3868
+ uksouth: "crm11",
3869
+ ukwest: "crm11",
3870
+ eastasia: "crm5",
3871
+ southeastasia: "crm5",
3872
+ australiaeast: "crm6",
3873
+ australiasoutheast: "crm6",
3874
+ japaneast: "crm7",
3875
+ japanwest: "crm7",
3876
+ centralindia: "crm8",
3877
+ southindia: "crm8",
3878
+ canadacentral: "crm3",
3879
+ canadaeast: "crm3",
3880
+ brazilsouth: "crm2",
3881
+ francecentral: "crm12",
3882
+ francesouth: "crm12",
3883
+ switzerlandnorth: "crm17",
3884
+ germanywestcentral: "crm16",
3885
+ uaenorth: "crm15"
3857
3886
  };
3858
3887
  const crmDomain = regionMap[region.toLowerCase()] || region;
3859
3888
  return `${environmentId}.${crmDomain}.dynamics.com`;
@@ -15083,9 +15112,11 @@ async function createMcpServer(serverConfig) {
15083
15112
  source = "bap";
15084
15113
  }
15085
15114
  } catch (err) {
15115
+ const errMsg = err instanceof Error ? err.message : String(err);
15116
+ const isAuthError = errMsg.includes("cached credentials") || errMsg.includes("authenticate");
15086
15117
  logger.warn(
15087
- { err: err instanceof Error ? err.message : String(err) },
15088
- "BAP admin API did not return a Dataverse instanceUrl \u2014 falling back to region guess (may fail DNS)"
15118
+ { err: errMsg },
15119
+ isAuthError ? "BAP admin API token not cached \u2014 run --setup again or add dataverseUrl to your environment config" : "BAP admin API did not return a Dataverse instanceUrl \u2014 falling back to region guess (may fail DNS)"
15089
15120
  );
15090
15121
  }
15091
15122
  }
@@ -15319,6 +15350,7 @@ async function createDeviceCodeAuthProvider(config, silentOnly = false) {
15319
15350
  };
15320
15351
  const pca = new PublicClientApplication(msalConfig);
15321
15352
  let currentAccount = null;
15353
+ let interactiveAuthCompleted = false;
15322
15354
  const pendingTokenRequests = /* @__PURE__ */ new Map();
15323
15355
  currentAccount = loadAccount();
15324
15356
  if (!currentAccount) {
@@ -15365,7 +15397,7 @@ async function createDeviceCodeAuthProvider(config, silentOnly = false) {
15365
15397
  "No cached credentials available. Run 'powerautomate-mcp --setup' first to authenticate."
15366
15398
  );
15367
15399
  }
15368
- if (currentAccount) {
15400
+ if (currentAccount && interactiveAuthCompleted) {
15369
15401
  throw new AuthenticationError(
15370
15402
  `Silent token acquisition failed for scopes: ${mutableScopes.join(", ")}. Resource may not be registered in the app registration. Re-run --setup to update permissions.`
15371
15403
  );
@@ -15415,6 +15447,7 @@ async function createDeviceCodeAuthProvider(config, silentOnly = false) {
15415
15447
  currentAccount = result.account;
15416
15448
  saveAccount(result.account);
15417
15449
  }
15450
+ interactiveAuthCompleted = true;
15418
15451
  logger.info({ username: result.account?.username }, "Device code authentication succeeded");
15419
15452
  return result;
15420
15453
  } catch (err) {
@@ -15881,15 +15914,29 @@ async function runSetupWizard() {
15881
15914
  print(` ${icons.check} ${c.green}Signed in${c.reset}`);
15882
15915
  }
15883
15916
  const additionalResources = [
15884
- { url: "https://service.powerapps.com", label: "PowerApps (connections)" },
15885
- { url: "https://api.bap.microsoft.com", label: "Admin API (environments)" }
15917
+ { url: "https://service.powerapps.com", label: "PowerApps (connections)", critical: false },
15918
+ { url: "https://api.bap.microsoft.com", label: "Admin API (environments/Dataverse)", critical: true }
15886
15919
  ];
15887
- for (const { url, label } of additionalResources) {
15888
- const token = authProvider.tryGetTokenForResourceSilent ? await authProvider.tryGetTokenForResourceSilent(url) : null;
15889
- if (token) {
15890
- print(` ${icons.check} ${c.dim}${label}: authorized${c.reset}`);
15891
- } else {
15892
- print(` ${c.dim}${icons.info || "-"} ${label}: will be authorized via admin consent (Step 3)${c.reset}`);
15920
+ for (const { url, label, critical } of additionalResources) {
15921
+ try {
15922
+ let token = null;
15923
+ if (authProvider.tryGetTokenForResourceSilent) {
15924
+ token = await authProvider.tryGetTokenForResourceSilent(url);
15925
+ }
15926
+ if (token) {
15927
+ print(` ${icons.check} ${c.dim}${label}: authorized${c.reset}`);
15928
+ } else {
15929
+ print(` ${c.dim}Authorizing ${label}...${c.reset}`);
15930
+ await authProvider.getTokenForResource(url);
15931
+ print(` ${icons.check} ${c.dim}${label}: authorized (interactive)${c.reset}`);
15932
+ }
15933
+ } catch (err) {
15934
+ if (critical) {
15935
+ print(` ${c.yellow || ""}${icons.warn} ${label}: not authorized \u2014 Dataverse tools may not work.${c.reset}`);
15936
+ print(` ${c.dim} Add dataverseUrl to your environment config as a workaround.${c.reset}`);
15937
+ } else {
15938
+ print(` ${c.dim}${icons.info || "-"} ${label}: not authorized (non-critical)${c.reset}`);
15939
+ }
15893
15940
  }
15894
15941
  }
15895
15942
  } catch (error) {