@hubspot/cli 8.16.0-beta.0 → 8.16.0-beta.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.
@@ -9,7 +9,7 @@ import { EXIT_CODES } from '../../lib/enums/exitCodes.js';
9
9
  import { migrateApp } from '../../lib/app/migrate.js';
10
10
  import { getIsInProject } from '../../lib/projects/config.js';
11
11
  import { makeYargsBuilder } from '../../lib/yargsUtils.js';
12
- const { v2025_2, v2026_03_BETA, v2026_03 } = PLATFORM_VERSIONS;
12
+ const { v2025_2, v2026_03_BETA, v2026_03, v2026_09 } = PLATFORM_VERSIONS;
13
13
  const command = 'migrate';
14
14
  const describe = commands.project.migrateApp.describe;
15
15
  export function handlerGenerator(commandTrackingName) {
@@ -67,7 +67,7 @@ function appMigrateBuilder(yargs) {
67
67
  },
68
68
  'platform-version': {
69
69
  type: 'string',
70
- choices: [v2025_2, v2026_03_BETA, v2026_03],
70
+ choices: [v2025_2, v2026_03_BETA, v2026_03, v2026_09],
71
71
  default: v2026_03,
72
72
  },
73
73
  unstable: {
@@ -81,7 +81,7 @@ function appMigrateBuilder(yargs) {
81
81
  ]);
82
82
  return yargs;
83
83
  }
84
- const builder = makeYargsBuilder(appMigrateBuilder, command, commands.project.migrateApp.describe, {
84
+ const builder = makeYargsBuilder(appMigrateBuilder, command, commands.project.migrateApp.verboseDescribe, {
85
85
  useGlobalOptions: true,
86
86
  useConfigOptions: true,
87
87
  useAccountOptions: true,
@@ -12,7 +12,7 @@ import { renderInline } from '../../ui/render.js';
12
12
  import { getWarningBox } from '../../ui/components/StatusMessageBoxes.js';
13
13
  import { getHasMigratableThemes, migrateThemesV2, } from '../../lib/theme/migrate.js';
14
14
  import { trackCommandMetadataUsage } from '../../lib/usageTracking.js';
15
- const { v2025_2, v2026_03_BETA, v2026_03 } = PLATFORM_VERSIONS;
15
+ const { v2025_2, v2026_03_BETA, v2026_03, v2026_09 } = PLATFORM_VERSIONS;
16
16
  const command = 'migrate';
17
17
  const describe = commands.project.migrate.describe;
18
18
  async function handler(args) {
@@ -62,8 +62,8 @@ function projectMigrateBuilder(yargs) {
62
62
  yargs
63
63
  .option('platform-version', {
64
64
  type: 'string',
65
- choices: [v2025_2, v2026_03_BETA, v2026_03],
66
- default: v2026_03,
65
+ choices: [v2025_2, v2026_03_BETA, v2026_03, v2026_09],
66
+ default: v2026_09,
67
67
  })
68
68
  .option('unstable', {
69
69
  type: 'boolean',
@@ -72,7 +72,7 @@ function projectMigrateBuilder(yargs) {
72
72
  });
73
73
  return yargs;
74
74
  }
75
- const builder = makeYargsBuilder(projectMigrateBuilder, command, commands.project.migrate.describe, {
75
+ const builder = makeYargsBuilder(projectMigrateBuilder, command, commands.project.migrate.verboseDescribe, {
76
76
  useGlobalOptions: true,
77
77
  useConfigOptions: true,
78
78
  useAccountOptions: true,
package/lang/en.d.ts CHANGED
@@ -1601,6 +1601,7 @@ export declare const commands: {
1601
1601
  };
1602
1602
  migrateApp: {
1603
1603
  describe: string;
1604
+ verboseDescribe: string;
1604
1605
  examples: {
1605
1606
  default: string;
1606
1607
  };
@@ -1645,6 +1646,7 @@ export declare const commands: {
1645
1646
  migrate: {
1646
1647
  preamble: (platformVersion: string) => string;
1647
1648
  describe: string;
1649
+ verboseDescribe: string;
1648
1650
  errors: {
1649
1651
  noProjectConfig: (command: string) => string;
1650
1652
  };
package/lang/en.js CHANGED
@@ -7,6 +7,7 @@ import { ARCHIVED_HUBSPOT_CONFIG_YAML_FILE_NAME, DEFAULT_HUBSPOT_CONFIG_YAML_FIL
7
7
  import { indent, UI_COLORS, uiAccountDescription, uiAuthCommandReference, uiBetaTag, uiCommandReference, uiDeprecatedTag, uiLink, } from '../lib/ui/index.js';
8
8
  import { getLocalDevUiUrl, getProjectDetailUrl, getProjectSettingsUrl, } from '../lib/projects/urls.js';
9
9
  import { getProductUpdatesUrl } from '../lib/links.js';
10
+ const MIGRATION_SUPPORT_CUTOFF_NOTICE = 'Automated platform version migrations beyond 2026.09 will not be supported.';
10
11
  export const commands = {
11
12
  generalErrors: {
12
13
  srcIsProject: (src, command) => `"${src}" is in a project folder. Did you mean "hs project ${command}"?`,
@@ -1616,7 +1617,8 @@ export const commands = {
1616
1617
  },
1617
1618
  },
1618
1619
  migrateApp: {
1619
- describe: 'Migrate a public app to the projects framework.',
1620
+ describe: uiDeprecatedTag(`Migrate a public app to the projects framework. ${MIGRATION_SUPPORT_CUTOFF_NOTICE}`, false),
1621
+ verboseDescribe: uiDeprecatedTag(`Migrate a public app to the projects framework. This command walks you through the fields required to complete the migration and downloads the project source code into a directory of your choosing.\n\n${chalk.bold.yellow(MIGRATION_SUPPORT_CUTOFF_NOTICE)}`, false),
1620
1622
  examples: {
1621
1623
  default: 'Migrate a public app to the projects framework',
1622
1624
  },
@@ -1660,7 +1662,8 @@ export const commands = {
1660
1662
  },
1661
1663
  migrate: {
1662
1664
  preamble: (platformVersion) => `This command will migrate an existing project to platformVersion ${platformVersion}. It will walk you through the fields required to complete the migration and download the new project source code into the project source directory. It will also copy all of your existing files to a new directory (archive) in case you need access to your old files later.`,
1663
- describe: 'Migrate an existing project to the new version of the projects framework.',
1665
+ describe: uiDeprecatedTag(`Migrate an existing project to the new version of the projects framework. ${MIGRATION_SUPPORT_CUTOFF_NOTICE}`, false),
1666
+ verboseDescribe: uiDeprecatedTag(`Migrate an existing project to a newer platform version. This command walks you through the fields required to complete the migration and downloads the new project source code into the project source directory. Your existing files are copied to a new directory (archive) in case you need access to them later.\n\n${chalk.bold.yellow(MIGRATION_SUPPORT_CUTOFF_NOTICE)}`, false),
1664
1667
  errors: {
1665
1668
  noProjectConfig: (command) => `No project detected. Please run this command again from a project directory. If you are trying to migrate an app, run ${command}`,
1666
1669
  },
@@ -1,5 +1,6 @@
1
1
  import { Environment } from '@hubspot/local-dev-lib/types/Accounts';
2
2
  import { HubSpotConfigAccount } from '@hubspot/local-dev-lib/types/Accounts';
3
+ export declare function getCurrentDefaultAccount(): HubSpotConfigAccount | undefined;
3
4
  type AuthenticateNewAccountOptions = {
4
5
  env: Environment;
5
6
  providedPersonalAccessKey?: string;
@@ -100,6 +100,14 @@ async function handleConfigMigration() {
100
100
  return false;
101
101
  }
102
102
  }
103
+ export function getCurrentDefaultAccount() {
104
+ try {
105
+ return getConfigDefaultAccountIfExists();
106
+ }
107
+ catch {
108
+ return undefined;
109
+ }
110
+ }
103
111
  export async function authenticateNewAccount({ env, providedPersonalAccessKey, accountId, setAsDefaultAccount, accountName: providedAccountName, useDefaultAccountName, }) {
104
112
  const configMigrationSuccess = await handleConfigMigration();
105
113
  if (!configMigrationSuccess) {
@@ -11,6 +11,7 @@ export declare const CLI_DEPRECATED_MAJOR_VERSION_EOL_DATE = "2027-03-01";
11
11
  export declare const CLI_SUPPORT_GUIDELINES_URL: "https://developers.hubspot.com/docs/developer-tooling/local-development/hubspot-cli/version-support";
12
12
  export declare const DEFAULT_POLLING_DELAY = 2000;
13
13
  export declare const PREVIEW_POLL_TIMEOUT: number;
14
+ export declare const MCP_ELICITATION_TIMEOUT: number;
14
15
  export declare const PROJECT_CONFIG_FILE: "hsproject.json";
15
16
  export declare const PROJECT_BUILD_STATES: {
16
17
  readonly BUILDING: "BUILDING";
package/lib/constants.js CHANGED
@@ -15,6 +15,8 @@ export const CLI_DEPRECATED_MAJOR_VERSION_EOL_DATE = '2027-03-01';
15
15
  export const CLI_SUPPORT_GUIDELINES_URL = 'https://developers.hubspot.com/docs/developer-tooling/local-development/hubspot-cli/version-support';
16
16
  export const DEFAULT_POLLING_DELAY = 2000;
17
17
  export const PREVIEW_POLL_TIMEOUT = 5 * 60 * 1000;
18
+ // MCP forms wait on a person, so they need longer than the SDK default of 60s.
19
+ export const MCP_ELICITATION_TIMEOUT = 5 * 60 * 1000;
18
20
  export const PROJECT_CONFIG_FILE = 'hsproject.json';
19
21
  export const PROJECT_BUILD_STATES = {
20
22
  BUILDING: 'BUILDING',
@@ -1,2 +1,9 @@
1
1
  import { ProjectConfig } from '../../types/Projects.js';
2
+ type ProfilePromptOption = {
3
+ name: string;
4
+ value: string;
5
+ disabled?: boolean;
6
+ };
7
+ export declare function generateProfilePromptOption(projectDir: string, projectConfig: ProjectConfig, profileName: string): ProfilePromptOption;
2
8
  export declare function projectProfilePrompt(projectDir: string, projectConfig: ProjectConfig, profileName?: string, exitIfMissing?: boolean): Promise<string | null>;
9
+ export {};
@@ -3,7 +3,7 @@ import { getAllHsProfiles } from '@hubspot/project-parsing-lib/profiles';
3
3
  import { listPrompt } from './promptUtils.js';
4
4
  import { loadProfile } from '../projects/projectProfiles.js';
5
5
  import { lib } from '../../lang/en.js';
6
- function generateProfilePromptOption(projectDir, projectConfig, profileName) {
6
+ export function generateProfilePromptOption(projectDir, projectConfig, profileName) {
7
7
  const choice = {
8
8
  name: profileName,
9
9
  value: profileName,
@@ -1,5 +1,7 @@
1
1
  import { HubSpotPromise } from '@hubspot/local-dev-lib/types/Http';
2
2
  import { HubSpotHttpError } from '@hubspot/local-dev-lib/models/HubSpotHttpError';
3
+ import { HubSpotConfigAccount } from '@hubspot/local-dev-lib/types/Accounts';
4
+ import { AccountTargetCandidate } from '../types/AccountTargets.js';
3
5
  type MockErrorResponse = {
4
6
  status: number;
5
7
  data: {
@@ -12,4 +14,7 @@ type MockErrorResponse = {
12
14
  export declare function mockHubSpotHttpResponse<T>(data?: any): HubSpotPromise<T>;
13
15
  export declare function mockHubSpotHttpError(message: string, response: MockErrorResponse): HubSpotHttpError;
14
16
  export declare function stubColorEnv(): void;
17
+ export declare const MOCK_SANDBOX_TARGET: AccountTargetCandidate;
18
+ export declare const MOCK_PRODUCTION_TARGET: AccountTargetCandidate;
19
+ export declare function getMockConfigAccount(identifier: number | string): HubSpotConfigAccount | undefined;
15
20
  export {};
package/lib/testUtils.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { vi } from 'vitest';
2
2
  import { HubSpotHttpError } from '@hubspot/local-dev-lib/models/HubSpotHttpError';
3
+ import { ACCOUNT_TARGET_CATEGORIES, ACCOUNT_TARGET_SELECTION_SOURCES, } from '../types/AccountTargets.js';
3
4
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
5
  export function mockHubSpotHttpResponse(data) {
5
6
  return Promise.resolve({
@@ -30,3 +31,26 @@ export function stubColorEnv() {
30
31
  ].forEach(key => vi.stubEnv(key, undefined));
31
32
  vi.stubEnv('TERM', 'xterm-256color');
32
33
  }
34
+ export const MOCK_SANDBOX_TARGET = {
35
+ accountId: 222,
36
+ accountName: 'Sandbox',
37
+ source: ACCOUNT_TARGET_SELECTION_SOURCES.GLOBAL_DEFAULT,
38
+ category: ACCOUNT_TARGET_CATEGORIES.RECOMMENDED_TESTING,
39
+ };
40
+ export const MOCK_PRODUCTION_TARGET = {
41
+ accountId: 111,
42
+ accountName: 'Prod Portal',
43
+ source: ACCOUNT_TARGET_SELECTION_SOURCES.GLOBAL_DEFAULT,
44
+ category: ACCOUNT_TARGET_CATEGORIES.PRODUCTION_WITH_CARE,
45
+ };
46
+ // A getConfigAccountIfExists stand-in that knows only MOCK_PRODUCTION_TARGET.
47
+ export function getMockConfigAccount(identifier) {
48
+ if (identifier !== MOCK_PRODUCTION_TARGET.accountId) {
49
+ return undefined;
50
+ }
51
+ return {
52
+ accountId: MOCK_PRODUCTION_TARGET.accountId,
53
+ name: MOCK_PRODUCTION_TARGET.accountName,
54
+ accountType: 'STANDARD',
55
+ };
56
+ }
package/lib/ui/index.js CHANGED
@@ -130,8 +130,18 @@ export function uiDeprecatedDescription(message, command, url) {
130
130
  const tag = message || uiMessages.disabledMessage(command, url);
131
131
  return uiDeprecatedTag(tag);
132
132
  }
133
+ // export function uiCommandRenamedDescription(
134
+ // describe: string | false | undefined,
135
+ // newCommand: string
136
+ // ): string | undefined {
137
+ // return uiDeprecatedTag(
138
+ // `${describe} ${uiMessages.commandRenamedMessage(newCommand)}`,
139
+ // false
140
+ // );
141
+ // }
142
+ // Replace this with the above code once we've upgraded to yargs 18.0.0
133
143
  export function uiCommandRenamedDescription(describe, newCommand) {
134
- return uiDeprecatedTag(`${describe} ${uiMessages.commandRenamedMessage(newCommand)}`, false);
144
+ return uiDeprecatedTag(`${describe} ${uiMessages.commandRenamedPlainMessage(newCommand)}`, false);
135
145
  }
136
146
  export function uiDeprecatedMessage(command, url, message) {
137
147
  const tag = uiMessages.deprecatedDescription(message || '', command, url);
@@ -5,6 +5,7 @@ export declare const uiMessages: {
5
5
  disabledMessage: (command: string, url?: string) => string;
6
6
  disabledUrlText: string;
7
7
  commandRenamedMessage: (newCommand: string) => string;
8
+ commandRenamedPlainMessage: (newCommand: string) => string;
8
9
  featureHighlight: {
9
10
  defaultTitle: string;
10
11
  featureKeys: {
@@ -8,6 +8,7 @@ export const uiMessages = {
8
8
  disabledMessage: (command, url) => `The ${uiCommandReference(command)} command is disabled. Run ${uiCommandReference('npm i -g @hubspot/cli@latest')} to update to the latest HubSpot CLI version. ${url ? uiLink('Learn more', url) : ''}`,
9
9
  disabledUrlText: 'See all HubSpot CLI commands here.',
10
10
  commandRenamedMessage: (newCommand) => `This command has been deprecated. Please use ${uiCommandReference(newCommand)} instead.`,
11
+ commandRenamedPlainMessage: (newCommand) => `This command has been deprecated. Please use \`${newCommand}\` instead.`,
11
12
  featureHighlight: {
12
13
  defaultTitle: "What's next?",
13
14
  featureKeys: {
@@ -13,6 +13,7 @@ export type AuthAccountInputSchema = z.infer<typeof inputSchemaZodObject>;
13
13
  export declare class AuthAccountTool extends Tool<AuthAccountInputSchema> {
14
14
  constructor(mcpServer: McpServer, logger: McpLogger);
15
15
  handler({ absoluteCurrentWorkingDirectory, accountId, name, setAsDefault, }: AuthAccountInputSchema, extra?: ToolExtra): Promise<McpToolResponse>;
16
+ private resolveSetAsDefault;
16
17
  register(): RegisteredTool;
17
18
  }
18
19
  export {};
@@ -4,8 +4,10 @@ import { formatTextContents } from '../../utils/content.js';
4
4
  import { HubSpotCommand } from '../../utils/command.js';
5
5
  import { setupHubSpotConfig } from '../../utils/config.js';
6
6
  import { parseCommandJsonOutput } from '../../utils/json.js';
7
+ import { booleanField } from '../../utils/elicitation.js';
7
8
  import { absoluteCurrentWorkingDirectory } from './constants.js';
8
9
  import { getErrorMessage } from '../../../lib/errorHandlers/index.js';
10
+ import { getCurrentDefaultAccount } from '../../../lib/accountAuth.js';
9
11
  import { AccountAuthSchema } from '../../../lib/jsonOutput/accountAuth.js';
10
12
  const inputSchema = {
11
13
  absoluteCurrentWorkingDirectory,
@@ -20,7 +22,7 @@ const inputSchema = {
20
22
  setAsDefault: z
21
23
  .boolean()
22
24
  .optional()
23
- .describe('Set this account as the default for CLI operations. Defaults to true when not specified.'),
25
+ .describe('Optional: set this account as the default for CLI operations. Omit unless the user stated a preference. If omitted and another account is already the default, the user is asked whether to replace it.'),
24
26
  };
25
27
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
26
28
  const inputSchemaZodObject = z.object({ ...inputSchema });
@@ -43,7 +45,8 @@ export class AuthAccountTool extends Tool {
43
45
  if (accountId !== undefined) {
44
46
  command.addFlag('account', accountId);
45
47
  }
46
- command.addFlag('default', setAsDefault === false ? 'false' : 'true');
48
+ const resolvedSetAsDefault = setAsDefault ?? (await this.resolveSetAsDefault(accountId));
49
+ command.addFlag('default', resolvedSetAsDefault ? 'true' : 'false');
47
50
  try {
48
51
  const { stdout, stderr } = await this.runCommand(absoluteCurrentWorkingDirectory, command, extra);
49
52
  const structuredContent = parseCommandJsonOutput(stdout, AccountAuthSchema, this.logger, toolName);
@@ -61,6 +64,24 @@ export class AuthAccountTool extends Tool {
61
64
  return formatTextContents(getErrorMessage(error));
62
65
  }
63
66
  }
67
+ async resolveSetAsDefault(accountId) {
68
+ const currentDefault = getCurrentDefaultAccount();
69
+ if (!currentDefault || currentDefault.accountId === accountId) {
70
+ return true;
71
+ }
72
+ const elicitation = await this.elicit({
73
+ message: `${currentDefault.name} is the default HubSpot account. Set the account you authenticate now as the new default?`,
74
+ fields: {
75
+ setAsDefault: booleanField('Set as default account', `Other CLI commands will use the new account instead of ${currentDefault.name}.`, true),
76
+ },
77
+ required: ['setAsDefault'],
78
+ });
79
+ if (!elicitation) {
80
+ return true;
81
+ }
82
+ return (elicitation.action === 'accept' &&
83
+ elicitation.content?.setAsDefault === true);
84
+ }
64
85
  register() {
65
86
  return this.mcpServer.registerTool(toolName, {
66
87
  title: 'Authenticate a HubSpot Account',
@@ -74,7 +95,7 @@ export class AuthAccountTool extends Tool {
74
95
  '2. The user clicks "Connect to CLI" in the browser\n' +
75
96
  '3. Auth completes automatically via WebSocket\n' +
76
97
  '4. Retry any operation that was blocked by missing auth\n\n' +
77
- 'setAsDefault defaults to true. Pass setAsDefault: false to keep an existing default account.',
98
+ 'If another account is already the default and setAsDefault is omitted, the tool asks the user whether to replace it. If the client cannot ask the user, the new account becomes the default.',
78
99
  inputSchema,
79
100
  outputSchema: AccountAuthSchema.shape,
80
101
  annotations: {
@@ -41,7 +41,7 @@ export class CreateProjectTool extends Tool {
41
41
  async handler({ name, destination, projectBase, distribution, auth, features, absoluteCurrentWorkingDirectory, }, extra) {
42
42
  setupHubSpotConfig(absoluteCurrentWorkingDirectory);
43
43
  const command = new HubSpotCommand('project create', [
44
- { name: 'platform-version', value: PLATFORM_VERSIONS.v2026_03 },
44
+ { name: 'platform-version', value: PLATFORM_VERSIONS.v2026_09 },
45
45
  { name: 'json', value: true },
46
46
  ]);
47
47
  const content = [];
@@ -5,13 +5,13 @@ import { McpLogger } from '../../utils/logger.js';
5
5
  import { z } from 'zod';
6
6
  declare const inputSchemaZodObject: z.ZodObject<{
7
7
  absoluteProjectPath: z.ZodString;
8
- absoluteCurrentWorkingDirectory: z.ZodString;
9
8
  buildNumber: z.ZodOptional<z.ZodNumber>;
9
+ confirmProductionAccount: z.ZodOptional<z.ZodBoolean>;
10
10
  }, z.core.$strip>;
11
11
  type InputSchemaType = z.infer<typeof inputSchemaZodObject>;
12
12
  export declare class DeployProjectTool extends Tool<InputSchemaType> {
13
13
  constructor(mcpServer: McpServer, logger: McpLogger);
14
- handler({ absoluteProjectPath, absoluteCurrentWorkingDirectory, buildNumber, }: InputSchemaType, extra?: ToolExtra): Promise<McpToolResponse>;
14
+ handler({ absoluteProjectPath, buildNumber, confirmProductionAccount, }: InputSchemaType, extra?: ToolExtra): Promise<McpToolResponse>;
15
15
  register(): RegisteredTool;
16
16
  }
17
17
  export {};
@@ -1,17 +1,20 @@
1
1
  import { Tool } from '../../Tool.js';
2
2
  import { z } from 'zod';
3
3
  import { HubSpotCommand } from '../../utils/command.js';
4
- import { absoluteCurrentWorkingDirectory, absoluteProjectPath, } from './constants.js';
5
- import { formatTextContents, formatTextContent } from '../../utils/content.js';
4
+ import { absoluteProjectPath, confirmProductionAccount } from './constants.js';
5
+ import { formatErrorTextContents, formatTextContents, } from '../../utils/content.js';
6
6
  import { setupHubSpotConfig } from '../../utils/config.js';
7
7
  import { parseCommandJsonOutput } from '../../utils/json.js';
8
8
  import { ProjectDeploySchema } from '../../../lib/jsonOutput/projectDeploy.js';
9
+ import { getProjectConfig } from '../../../lib/projects/config.js';
10
+ import { discoverAccountTargets } from '../../../lib/accountTargetDiscovery.js';
11
+ import { confirmProductionTargets, setTargetAccount, } from './productionConfirmation.js';
9
12
  const inputSchema = {
10
13
  absoluteProjectPath,
11
- absoluteCurrentWorkingDirectory,
12
14
  buildNumber: z
13
15
  .optional(z.number())
14
- .describe('The build number to be deployed. This can be found in the project details page using `hs project open`. If no build number is specified, the most recent build is deployed'),
16
+ .describe('The build number to deploy. This can be found in the project details page using `hs project open`. If omitted, the tool deploys nothing and returns the recent builds, so you can ask the user which one to deploy.'),
17
+ confirmProductionAccount,
15
18
  };
16
19
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
17
20
  const inputSchemaZodObject = z.object({
@@ -22,25 +25,32 @@ export class DeployProjectTool extends Tool {
22
25
  constructor(mcpServer, logger) {
23
26
  super(mcpServer, logger, toolName);
24
27
  }
25
- async handler({ absoluteProjectPath, absoluteCurrentWorkingDirectory, buildNumber, }, extra) {
26
- setupHubSpotConfig(absoluteCurrentWorkingDirectory);
27
- const content = [];
28
+ async handler({ absoluteProjectPath, buildNumber, confirmProductionAccount, }, extra) {
29
+ setupHubSpotConfig(absoluteProjectPath);
30
+ const { projectDir, projectConfig } = getProjectConfig(absoluteProjectPath);
31
+ const targets = await discoverAccountTargets({ projectDir, projectConfig });
28
32
  if (!buildNumber) {
29
- const { stdout } = await this.runCommand(absoluteProjectPath, new HubSpotCommand('project list-builds', [
33
+ const listBuildsCommand = new HubSpotCommand('project list-builds', [
30
34
  { name: 'limit', value: 100 },
31
- ]), extra);
32
- content.push(formatTextContent(`Ask the user which build number they would like to deploy? Build information: ${stdout}`));
35
+ ]);
36
+ setTargetAccount(listBuildsCommand, targets);
37
+ const { stdout } = await this.runCommand(absoluteProjectPath, listBuildsCommand, extra);
38
+ return formatErrorTextContents(`Ask the user which build number they would like to deploy? Build information: ${stdout}`);
33
39
  }
34
- if (content.length) {
35
- return {
36
- content,
37
- structuredContent: {},
38
- };
40
+ const blockedResponse = await confirmProductionTargets(this.mcpServer, this.logger, {
41
+ targets,
42
+ action: `Deploy build #${buildNumber}`,
43
+ toolName,
44
+ confirmedInConversation: confirmProductionAccount,
45
+ });
46
+ if (blockedResponse) {
47
+ return blockedResponse;
39
48
  }
40
49
  const command = new HubSpotCommand('project deploy', [
41
50
  { name: 'build', value: buildNumber },
42
51
  { name: 'json', value: true },
43
52
  ]);
53
+ setTargetAccount(command, targets);
44
54
  const { stdout, stderr } = await this.runCommand(absoluteProjectPath, command, extra);
45
55
  const response = await formatTextContents(stdout, stderr);
46
56
  response.structuredContent =
@@ -50,7 +60,7 @@ export class DeployProjectTool extends Tool {
50
60
  register() {
51
61
  return this.mcpServer.registerTool(toolName, {
52
62
  title: 'Deploy a build of HubSpot Project',
53
- description: 'Takes a build number and a project name and deploys that build of the project. DO NOT run this tool unless the user specifies they would like to deploy the project. If you do not know the project path, use the find-projects tool first to locate HubSpot projects in the workspace.',
63
+ description: 'Takes a build number and a project name and deploys that build of the project. DO NOT run this tool unless the user specifies they would like to deploy the project. Deploys to production accounts require confirmation from the user. If you do not know the project path, use the find-projects tool first to locate HubSpot projects in the workspace.',
54
64
  inputSchema,
55
65
  outputSchema: ProjectDeploySchema.shape,
56
66
  annotations: {
@@ -5,14 +5,14 @@ import { McpToolResponse } from '../../types.js';
5
5
  import { Tool, ToolExtra } from '../../Tool.js';
6
6
  declare const inputSchemaZodObject: z.ZodObject<{
7
7
  absoluteProjectPath: z.ZodString;
8
- absoluteCurrentWorkingDirectory: z.ZodString;
9
8
  uploadMessage: z.ZodString;
10
9
  profile: z.ZodOptional<z.ZodString>;
10
+ confirmProductionAccount: z.ZodOptional<z.ZodBoolean>;
11
11
  }, z.z.core.$strip>;
12
12
  type InputSchemaType = z.infer<typeof inputSchemaZodObject>;
13
13
  export declare class UploadProjectTools extends Tool<InputSchemaType> {
14
14
  constructor(mcpServer: McpServer, logger: McpLogger);
15
- handler({ absoluteProjectPath, absoluteCurrentWorkingDirectory, profile, uploadMessage, }: InputSchemaType, extra?: ToolExtra): Promise<McpToolResponse>;
15
+ handler({ absoluteProjectPath, profile, uploadMessage, confirmProductionAccount, }: InputSchemaType, extra?: ToolExtra): Promise<McpToolResponse>;
16
16
  register(): RegisteredTool;
17
17
  }
18
18
  export {};
@@ -3,21 +3,25 @@ import z from 'zod';
3
3
  import { getAllHsProfiles } from '@hubspot/project-parsing-lib/profiles';
4
4
  import { getProjectConfig } from '../../../lib/projects/config.js';
5
5
  import { Tool } from '../../Tool.js';
6
- import { absoluteCurrentWorkingDirectory, absoluteProjectPath, } from './constants.js';
7
- import { formatTextContent, formatTextContents } from '../../utils/content.js';
6
+ import { absoluteProjectPath, confirmProductionAccount } from './constants.js';
7
+ import { formatErrorTextContents, formatTextContent, formatTextContents, } from '../../utils/content.js';
8
8
  import { HubSpotCommand } from '../../utils/command.js';
9
9
  import { setupHubSpotConfig } from '../../utils/config.js';
10
10
  import { parseCommandJsonOutput } from '../../utils/json.js';
11
11
  import { ProjectUploadSchema } from '../../../lib/jsonOutput/projectUpload.js';
12
+ import { discoverAccountTargets } from '../../../lib/accountTargetDiscovery.js';
13
+ import { generateProfilePromptOption } from '../../../lib/prompts/projectProfilePrompt.js';
14
+ import { elicitSelection } from '../../utils/elicitSelection.js';
15
+ import { confirmProductionTargets, setTargetAccount, } from './productionConfirmation.js';
12
16
  const inputSchema = {
13
17
  absoluteProjectPath,
14
- absoluteCurrentWorkingDirectory,
15
18
  uploadMessage: z
16
19
  .string()
17
20
  .describe('A 1 sentence message that concisely describes the changes that are being uploaded.'),
18
21
  profile: z
19
22
  .optional(z.string())
20
- .describe('The profile to use for the upload. Only required for projects configured with profiles. If the project uses profiles and the user has not specified one, ask them rather than inferring from filenames in the directory. NEVER automatically choose a profile based on files you see. Profile files have the format: "hsprofile.<profile>.json".'),
23
+ .describe('The profile to use for the upload. Only set this when the user names a profile. If it is omitted and the project uses profiles, the tool asks the user to choose one. NEVER automatically choose a profile based on files you see. Profile files have the format: "hsprofile.<profile>.json".'),
24
+ confirmProductionAccount,
21
25
  };
22
26
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
23
27
  const inputSchemaZodObject = z.object({
@@ -28,44 +32,53 @@ export class UploadProjectTools extends Tool {
28
32
  constructor(mcpServer, logger) {
29
33
  super(mcpServer, logger, toolName);
30
34
  }
31
- async handler({ absoluteProjectPath, absoluteCurrentWorkingDirectory, profile, uploadMessage, }, extra) {
32
- setupHubSpotConfig(absoluteCurrentWorkingDirectory);
35
+ async handler({ absoluteProjectPath, profile, uploadMessage, confirmProductionAccount, }, extra) {
36
+ setupHubSpotConfig(absoluteProjectPath);
37
+ const { projectDir, projectConfig } = getProjectConfig(absoluteProjectPath);
38
+ let selectedProfile = profile;
39
+ if (!selectedProfile) {
40
+ const profiles = await getAllHsProfiles(path.join(projectDir, projectConfig.srcDir));
41
+ if (profiles.length > 0) {
42
+ const options = profiles.map(profileName => ({
43
+ value: profileName,
44
+ label: generateProfilePromptOption(projectDir, projectConfig, profileName).name,
45
+ }));
46
+ selectedProfile = await elicitSelection(this.mcpServer, this.logger, {
47
+ message: 'Select the profile to use for the upload.',
48
+ title: 'Project profile',
49
+ options,
50
+ });
51
+ if (!selectedProfile) {
52
+ return formatErrorTextContents(`Several profiles are available. Ask the user which to use, then call ${toolName} again with the profile argument set to one of these profile names: ${options
53
+ .map(option => option.value)
54
+ .join(', ')}. The profiles target these accounts: ${options
55
+ .map(option => option.label)
56
+ .join(', ')}.`);
57
+ }
58
+ }
59
+ }
60
+ const targets = await discoverAccountTargets({
61
+ projectDir,
62
+ projectConfig,
63
+ profileName: selectedProfile,
64
+ });
65
+ const blockedResponse = await confirmProductionTargets(this.mcpServer, this.logger, {
66
+ targets,
67
+ action: `Upload ${projectConfig.name}`,
68
+ toolName,
69
+ confirmedInConversation: confirmProductionAccount,
70
+ });
71
+ if (blockedResponse) {
72
+ return blockedResponse;
73
+ }
33
74
  const command = new HubSpotCommand('project upload', [
34
75
  { name: 'force', value: true },
35
76
  { name: 'json', value: true },
36
77
  ]);
37
- const content = [];
38
78
  if (uploadMessage) {
39
79
  command.addFlag('message', uploadMessage);
40
80
  }
41
- if (profile) {
42
- command.addFlag('profile', profile);
43
- }
44
- else {
45
- let hasProfiles = false;
46
- try {
47
- const { projectConfig } = getProjectConfig(absoluteProjectPath);
48
- const profiles = await getAllHsProfiles(path.join(absoluteProjectPath, projectConfig.srcDir));
49
- hasProfiles = profiles.length > 0;
50
- }
51
- catch (e) {
52
- this.logger.debug(toolName, {
53
- message: 'Handler caught error checking for profiles',
54
- error: e instanceof Error ? e.message : String(e),
55
- });
56
- // If any of these checks fail, the safest thing to do is to assume there are no profiles.
57
- hasProfiles = false;
58
- }
59
- if (hasProfiles) {
60
- content.push(formatTextContent(`Ask the user which profile they would like to use for the upload.`));
61
- }
62
- }
63
- if (content.length > 0) {
64
- return {
65
- content,
66
- structuredContent: {},
67
- };
68
- }
81
+ setTargetAccount(command, targets, selectedProfile);
69
82
  const { stdout, stderr } = await this.runCommand(absoluteProjectPath, command, extra);
70
83
  const response = await formatTextContents(stdout, stderr);
71
84
  // Add reminder about cards needing to be added to views
@@ -77,7 +90,7 @@ export class UploadProjectTools extends Tool {
77
90
  register() {
78
91
  return this.mcpServer.registerTool(toolName, {
79
92
  title: 'Upload HubSpot Project',
80
- description: 'DO NOT run this tool unless the user specifies they would like to upload the project, it is potentially destructive. Uploads the HubSpot project in current working directory. If the project does not exist, it will be created. MUST be ran from within the project directory. IMPORTANT: Uploading a project does NOT automatically make cards live or visible to users. Cards must be manually added to a view in HubSpot after upload to become visible. If you do not know the project path, use the find-projects tool first to locate HubSpot projects in the workspace.',
93
+ description: 'DO NOT run this tool unless the user specifies they would like to upload the project, it is potentially destructive. Uploads the HubSpot project in current working directory. If the project does not exist, it will be created. MUST be ran from within the project directory. IMPORTANT: Uploading a project does NOT automatically make cards live or visible to users. Cards must be manually added to a view in HubSpot after upload to become visible. Uploads to production accounts require confirmation from the user. If you do not know the project path, use the find-projects tool first to locate HubSpot projects in the workspace.',
81
94
  inputSchema,
82
95
  outputSchema: ProjectUploadSchema.shape,
83
96
  annotations: {
@@ -2,6 +2,7 @@ import z from 'zod';
2
2
  export declare const absoluteProjectPath: z.ZodString;
3
3
  export declare const absoluteCurrentWorkingDirectory: z.ZodString;
4
4
  export declare const account: z.ZodOptional<z.ZodString>;
5
+ export declare const confirmProductionAccount: z.ZodOptional<z.ZodBoolean>;
5
6
  export declare const features: z.ZodOptional<z.ZodArray<z.ZodEnum<{
6
7
  card: "card";
7
8
  settings: "settings";
@@ -9,6 +9,9 @@ export const account = z
9
9
  .string()
10
10
  .optional()
11
11
  .describe('Optional: the HubSpot account ID or name to use. If omitted and several accounts are available, you will be asked to choose.');
12
+ export const confirmProductionAccount = z
13
+ .optional(z.boolean())
14
+ .describe('Set to true only after this tool names a production account and the user then explicitly confirms that account in the conversation. NEVER set this on your own. The tool ignores this value when the client can show a confirmation form.');
12
15
  export const features = z
13
16
  .array(z.enum([
14
17
  'card',
@@ -0,0 +1,12 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { DiscoverAccountTargetsResult } from '../../../types/AccountTargets.js';
3
+ import { McpToolResponse } from '../../types.js';
4
+ import { HubSpotCommand } from '../../utils/command.js';
5
+ import { McpLogger } from '../../utils/logger.js';
6
+ export declare function setTargetAccount(command: HubSpotCommand, { recommended }: DiscoverAccountTargetsResult, profileName?: string): void;
7
+ export declare function confirmProductionTargets(mcpServer: McpServer, logger: McpLogger, { targets, action, toolName, confirmedInConversation, }: {
8
+ targets: DiscoverAccountTargetsResult;
9
+ action: string;
10
+ toolName: string;
11
+ confirmedInConversation?: boolean;
12
+ }): Promise<McpToolResponse | undefined>;
@@ -0,0 +1,45 @@
1
+ import { ACCOUNT_TARGET_CATEGORIES, } from '../../../types/AccountTargets.js';
2
+ import { uiAccountDescription } from '../../../lib/ui/index.js';
3
+ import { formatErrorTextContents } from '../../utils/content.js';
4
+ import { canElicit, requestElicitation } from '../../utils/elicitation.js';
5
+ // Sets the command to run against the account that was checked. hs rejects
6
+ // --profile with --account, and a profile already sets the account, so a
7
+ // profile wins.
8
+ export function setTargetAccount(command, { recommended }, profileName) {
9
+ if (profileName) {
10
+ command.addFlag('profile', profileName);
11
+ return;
12
+ }
13
+ if (recommended) {
14
+ command.addFlag('account', recommended.accountId);
15
+ }
16
+ }
17
+ // Without a recommended account the command can act on any candidate, so every
18
+ // production candidate is a possible target.
19
+ function getProductionTargets({ candidates, recommended, }) {
20
+ return (recommended ? [recommended] : candidates).filter(candidate => candidate.category === ACCOUNT_TARGET_CATEGORIES.PRODUCTION_WITH_CARE);
21
+ }
22
+ // Returns an error response when the action must not run, or `undefined` when
23
+ // it can run. `confirmedInConversation` only counts when the client cannot show
24
+ // a confirmation form.
25
+ export async function confirmProductionTargets(mcpServer, logger, { targets, action, toolName, confirmedInConversation, }) {
26
+ const productionTargets = getProductionTargets(targets);
27
+ if (productionTargets.length === 0) {
28
+ return undefined;
29
+ }
30
+ const accounts = productionTargets
31
+ .map(({ accountId }) => uiAccountDescription(accountId, false))
32
+ .join(' or ');
33
+ if (!canElicit(mcpServer)) {
34
+ return confirmedInConversation
35
+ ? undefined
36
+ : formatErrorTextContents(`${action} targets production account ${accounts}, which is not a test account or sandbox. Ask the user to confirm this account. If the user confirms, call ${toolName} again with confirmProductionAccount set to true.`);
37
+ }
38
+ // A failed or timed-out request counts as a decline, so the flag cannot skip
39
+ // the form.
40
+ const elicitation = await requestElicitation(mcpServer, { message: `${action} to production account ${accounts}?`, fields: {} }, logger);
41
+ if (elicitation?.action === 'accept') {
42
+ return undefined;
43
+ }
44
+ return formatErrorTextContents(`The user did not confirm production account ${accounts}, so ${toolName} did not run. Tell the user that the action was canceled. Do not ask the user to confirm again, and do not call ${toolName} again unless the user asks.`);
45
+ }
@@ -2,6 +2,8 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  import { ElicitResult, PrimitiveSchemaDefinition } from '@modelcontextprotocol/sdk/types.js';
3
3
  import { McpLogger } from './logger.js';
4
4
  export declare function enumField(title: string, description: string, values: string[], names?: string[]): PrimitiveSchemaDefinition;
5
+ export declare function booleanField(title: string, description: string, defaultValue?: boolean): PrimitiveSchemaDefinition;
6
+ export declare function canElicit(mcpServer: McpServer): boolean;
5
7
  export declare function requestElicitation(mcpServer: McpServer, params: {
6
8
  message: string;
7
9
  fields: Record<string, PrimitiveSchemaDefinition>;
@@ -1,6 +1,13 @@
1
+ import { MCP_ELICITATION_TIMEOUT } from '../../lib/constants.js';
1
2
  export function enumField(title, description, values, names) {
2
3
  return { type: 'string', title, description, enum: values, enumNames: names };
3
4
  }
5
+ export function booleanField(title, description, defaultValue) {
6
+ return { type: 'boolean', title, description, default: defaultValue };
7
+ }
8
+ export function canElicit(mcpServer) {
9
+ return Boolean(mcpServer.server.getClientCapabilities()?.elicitation?.form);
10
+ }
4
11
  // Sends a JSON Schema of the required inputs to the client, pauses the tool
5
12
  // call, and resumes when the client returns a response that matches the schema.
6
13
  // The client collects the values from the user. The SDK checks the returned
@@ -10,8 +17,7 @@ export function enumField(title, description, values, names) {
10
17
  // (it did not advertise form elicitation, or the request failed). Callers treat
11
18
  // `undefined` and any non-`accept` action as "no answer" and fall back to text.
12
19
  export async function requestElicitation(mcpServer, params, logger) {
13
- const capabilities = mcpServer.server.getClientCapabilities();
14
- if (!capabilities?.elicitation?.form) {
20
+ if (!canElicit(mcpServer)) {
15
21
  return undefined;
16
22
  }
17
23
  const requestedSchema = {
@@ -20,10 +26,7 @@ export async function requestElicitation(mcpServer, params, logger) {
20
26
  required: params.required,
21
27
  };
22
28
  try {
23
- return await mcpServer.server.elicitInput({
24
- message: params.message,
25
- requestedSchema,
26
- });
29
+ return await mcpServer.server.elicitInput({ message: params.message, requestedSchema }, { timeout: MCP_ELICITATION_TIMEOUT });
27
30
  }
28
31
  catch (error) {
29
32
  logger?.warn('elicitation', {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/cli",
3
- "version": "8.16.0-beta.0",
3
+ "version": "8.16.0-beta.2",
4
4
  "description": "The official CLI for developing on HubSpot",
5
5
  "license": "Apache-2.0",
6
6
  "repository": "https://github.com/HubSpot/hubspot-cli",