powerautomate-mcp 0.5.2 → 0.5.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.
package/dist/index.js CHANGED
@@ -381,6 +381,20 @@ Create the file with your Microsoft Entra app client ID and Power Automate envir
381
381
  err
382
382
  );
383
383
  }
384
+ const envClientId = env["PA_MCP_CLIENT_ID"];
385
+ if (envClientId) {
386
+ const UUID_RE3 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
387
+ if (!UUID_RE3.test(envClientId)) {
388
+ throw new ConfigurationError(
389
+ `PA_MCP_CLIENT_ID is not a valid UUID: ${envClientId.substring(0, 50)}`
390
+ );
391
+ }
392
+ parsed.auth = {
393
+ ...parsed.auth ?? {},
394
+ clientId: envClientId
395
+ };
396
+ logger.info("Using client ID from PA_MCP_CLIENT_ID environment variable");
397
+ }
384
398
  try {
385
399
  const config = validateConfig(parsed);
386
400
  logger.info(
@@ -14162,7 +14176,7 @@ async function createMcpServer(serverConfig) {
14162
14176
  const server = new Server(
14163
14177
  {
14164
14178
  name: "powerautomate-mcp",
14165
- version: "0.5.1"
14179
+ version: "0.5.3"
14166
14180
  },
14167
14181
  {
14168
14182
  capabilities: {
@@ -14519,7 +14533,6 @@ function getDefaultEnvironment(environments) {
14519
14533
  }
14520
14534
 
14521
14535
  // src/setup/published-app.ts
14522
- var PUBLISHED_APP_CLIENT_ID = "244786c8-30ec-4b2e-8c7a-025fc97f6872";
14523
14536
  var APP_DISPLAY_NAME = "Power Automate MCP";
14524
14537
  var REDIRECT_URI = "https://login.microsoftonline.com/common/oauth2/nativeclient";
14525
14538
  var REQUIRED_RESOURCE_ACCESS = [
@@ -14737,56 +14750,69 @@ function readExistingClientId() {
14737
14750
  return null;
14738
14751
  }
14739
14752
  }
14740
- async function resolveAppRegistration() {
14753
+ async function promptForClientId(askUser) {
14754
+ print("");
14755
+ print(` ${c.yellow}You need a Microsoft Entra app registration for your tenant.${c.reset}`);
14756
+ print(` ${c.dim}Create one in the Azure portal with these delegated permissions:${c.reset}`);
14757
+ print(` ${c.dim}\u2022 Microsoft Graph: User.Read, Sites.ReadWrite.All, Files.ReadWrite.All${c.reset}`);
14758
+ print(` ${c.dim}\u2022 Power Automate: Flows.Read.All, Flows.Manage.All, Activity.Read.All, Approvals.Manage.All${c.reset}`);
14759
+ print(` ${c.dim}\u2022 Dynamics CRM: user_impersonation${c.reset}`);
14760
+ print(` ${c.dim}Enable "Allow public client flows" for device code auth.${c.reset}`);
14761
+ print("");
14762
+ while (true) {
14763
+ const input = await askUser(` ${c.cyan}?${c.reset} Paste your app's ${c.bold}Client ID${c.reset}: `);
14764
+ if (input && UUID_RE2.test(input)) {
14765
+ return input;
14766
+ }
14767
+ print(` ${c.red}Invalid format \u2014 must be a UUID (e.g., 12345678-abcd-1234-abcd-123456789abc)${c.reset}`);
14768
+ }
14769
+ }
14770
+ async function resolveAppRegistration(askUser) {
14771
+ const envClientId = process.env["PA_MCP_CLIENT_ID"];
14772
+ if (envClientId && UUID_RE2.test(envClientId)) {
14773
+ print(` ${icons.check} Using client ID from PA_MCP_CLIENT_ID: ${c.dim}${envClientId}${c.reset}`);
14774
+ return { clientId: envClientId, created: false };
14775
+ }
14741
14776
  const existingId = readExistingClientId();
14742
14777
  if (existingId) {
14743
14778
  print(` ${icons.check} Reusing app from existing config: ${c.dim}${existingId}${c.reset}`);
14744
14779
  return { clientId: existingId, created: false };
14745
14780
  }
14746
14781
  const hasAzCli = await checkAzureCli();
14747
- if (!hasAzCli) {
14748
- print(` ${c.dim}Azure CLI not found \u2014 using shared app${c.reset}`);
14749
- print(` ${icons.check} Client ID: ${c.dim}${PUBLISHED_APP_CLIENT_ID}${c.reset}`);
14750
- return { clientId: PUBLISHED_APP_CLIENT_ID, created: false };
14751
- }
14752
- print(` ${c.dim}Azure CLI detected${c.reset}`);
14753
- try {
14754
- const azUser = await ensureAzureCliLogin();
14755
- print(` ${icons.check} Azure CLI signed in as ${c.bold}${azUser}${c.reset}`);
14756
- } catch (error) {
14757
- const msg = error instanceof Error ? error.message : String(error);
14758
- print(` ${c.yellow}Azure CLI login failed: ${msg}${c.reset}`);
14759
- print(` ${c.dim}Falling back to shared app${c.reset}`);
14760
- print(` ${icons.check} Client ID: ${c.dim}${PUBLISHED_APP_CLIENT_ID}${c.reset}`);
14761
- return { clientId: PUBLISHED_APP_CLIENT_ID, created: false };
14762
- }
14763
- const existingAppId = await findExistingApp(APP_DISPLAY_NAME);
14764
- if (existingAppId) {
14765
- print(` ${icons.check} Found existing app: ${c.dim}${existingAppId}${c.reset}`);
14766
- try {
14767
- await addWamRedirectUri(existingAppId);
14768
- } catch {
14769
- }
14770
- return { clientId: existingAppId, created: false };
14771
- }
14772
- print(` ${c.dim}Creating app registration...${c.reset}`);
14773
- try {
14774
- const newId = await createAppRegistration(APP_DISPLAY_NAME);
14775
- print(` ${icons.check} App created: ${c.dim}${newId}${c.reset}`);
14782
+ if (hasAzCli) {
14783
+ print(` ${c.dim}Azure CLI detected${c.reset}`);
14776
14784
  try {
14777
- await addWamRedirectUri(newId);
14778
- print(` ${icons.check} WAM redirect URI configured`);
14779
- } catch {
14780
- print(` ${c.dim}WAM redirect URI skipped (non-critical)${c.reset}`);
14785
+ const azUser = await ensureAzureCliLogin();
14786
+ print(` ${icons.check} Azure CLI signed in as ${c.bold}${azUser}${c.reset}`);
14787
+ const existingAppId = await findExistingApp(APP_DISPLAY_NAME);
14788
+ if (existingAppId) {
14789
+ print(` ${icons.check} Found existing app: ${c.dim}${existingAppId}${c.reset}`);
14790
+ try {
14791
+ await addWamRedirectUri(existingAppId);
14792
+ } catch {
14793
+ }
14794
+ return { clientId: existingAppId, created: false };
14795
+ }
14796
+ print(` ${c.dim}Creating app registration...${c.reset}`);
14797
+ const newId = await createAppRegistration(APP_DISPLAY_NAME);
14798
+ print(` ${icons.check} App created: ${c.dim}${newId}${c.reset}`);
14799
+ try {
14800
+ await addWamRedirectUri(newId);
14801
+ print(` ${icons.check} WAM redirect URI configured`);
14802
+ } catch {
14803
+ print(` ${c.dim}WAM redirect URI skipped (non-critical)${c.reset}`);
14804
+ }
14805
+ return { clientId: newId, created: true };
14806
+ } catch (error) {
14807
+ const msg = error instanceof Error ? error.message : String(error);
14808
+ print(` ${c.yellow}Azure CLI failed: ${msg}${c.reset}`);
14781
14809
  }
14782
- return { clientId: newId, created: true };
14783
- } catch (error) {
14784
- const msg = error instanceof Error ? error.message : String(error);
14785
- print(` ${c.yellow}App creation failed: ${msg}${c.reset}`);
14786
- print(` ${c.dim}Falling back to shared app${c.reset}`);
14787
- print(` ${icons.check} Client ID: ${c.dim}${PUBLISHED_APP_CLIENT_ID}${c.reset}`);
14788
- return { clientId: PUBLISHED_APP_CLIENT_ID, created: false };
14810
+ } else {
14811
+ print(` ${c.dim}Azure CLI not found \u2014 skipping automatic app creation${c.reset}`);
14789
14812
  }
14813
+ const manualId = await promptForClientId(askUser);
14814
+ print(` ${icons.check} Client ID: ${c.dim}${manualId}${c.reset}`);
14815
+ return { clientId: manualId, created: false };
14790
14816
  }
14791
14817
  async function runSetupWizard() {
14792
14818
  const rl = createInterface({
@@ -14804,7 +14830,7 @@ async function runSetupWizard() {
14804
14830
  printHeader();
14805
14831
  const totalSteps = 5;
14806
14832
  printStep(1, totalSteps, "App Registration");
14807
- const appResult = await resolveAppRegistration();
14833
+ const appResult = await resolveAppRegistration(prompt);
14808
14834
  const clientId = appResult.clientId;
14809
14835
  printStep(2, totalSteps, "Sign In");
14810
14836
  const cacheResult = clearTokenCache();
@@ -15011,10 +15037,17 @@ Options:
15011
15037
  --port <N> Port for HTTP transport (default: 3000)
15012
15038
  --help, -h Show this help message
15013
15039
 
15040
+ Environment Variables:
15041
+ PA_MCP_CLIENT_ID Microsoft Entra app client ID (overrides config file)
15042
+ PA_CONFIG_PATH Custom path to config.json
15043
+
15014
15044
  First Run:
15015
15045
  If no configuration exists, the setup wizard will run automatically.
15016
15046
  You can also run it manually with --setup.
15017
15047
 
15048
+ Each tenant needs its own Microsoft Entra app registration.
15049
+ The wizard can create one via Azure CLI, or you can provide one manually.
15050
+
15018
15051
  Configuration:
15019
15052
  Config file: ${configPath}
15020
15053