@hubspot/cli 7.7.35-experimental.0 → 7.8.1-experimental.0

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.
@@ -0,0 +1,233 @@
1
+ import { getProjectThemeDetails, migrateThemes, } from '@hubspot/project-parsing-lib';
2
+ import { confirmPrompt } from '../../prompts/promptUtils.js';
3
+ import { writeProjectConfig, } from '../../projects/config.js';
4
+ import { ensureProjectExists } from '../../projects/ensureProjectExists.js';
5
+ import { useV3Api } from '../../projects/platformVersion.js';
6
+ import { fetchMigrationApps } from '../../app/migrate.js';
7
+ import { getHasMigratableThemes, validateMigrationAppsAndThemes, handleThemesMigration, migrateThemes2025_2, } from '../migrate.js';
8
+ import { lib } from '../../../lang/en.js';
9
+ vi.mock('@hubspot/local-dev-lib/logger');
10
+ vi.mock('@hubspot/project-parsing-lib');
11
+ vi.mock('../../prompts/promptUtils');
12
+ vi.mock('../../projects/config');
13
+ vi.mock('../../projects/ensureProjectExists');
14
+ vi.mock('../../projects/platformVersion');
15
+ vi.mock('../../app/migrate');
16
+ const mockedGetProjectThemeDetails = getProjectThemeDetails;
17
+ const mockedMigrateThemes = migrateThemes;
18
+ const mockedConfirmPrompt = confirmPrompt;
19
+ const mockedWriteProjectConfig = writeProjectConfig;
20
+ const mockedEnsureProjectExists = ensureProjectExists;
21
+ const mockedUseV3Api = useV3Api;
22
+ const mockedFetchMigrationApps = fetchMigrationApps;
23
+ const ACCOUNT_ID = 123;
24
+ const PROJECT_NAME = 'Test Project';
25
+ const PLATFORM_VERSION = '2025.2';
26
+ const MOCK_PROJECT_DIR = '/mock/project/dir';
27
+ const createLoadedProjectConfig = (name) => ({
28
+ projectConfig: { name, srcDir: 'src', platformVersion: '2024.1' },
29
+ projectDir: MOCK_PROJECT_DIR,
30
+ });
31
+ describe('lib/theme/migrate', () => {
32
+ beforeEach(() => {
33
+ mockedUseV3Api.mockReturnValue(false);
34
+ });
35
+ describe('getHasMigratableThemes', () => {
36
+ it('should return false when no projectConfig is provided', async () => {
37
+ const result = await getHasMigratableThemes();
38
+ expect(result).toEqual({
39
+ hasMigratableThemes: false,
40
+ migratableThemesCount: 0,
41
+ });
42
+ });
43
+ it('should return false when projectConfig is missing required properties', async () => {
44
+ const invalidProjectConfig = {
45
+ projectConfig: { name: undefined, srcDir: 'src' },
46
+ projectDir: undefined,
47
+ };
48
+ const result = await getHasMigratableThemes(invalidProjectConfig);
49
+ expect(result).toEqual({
50
+ hasMigratableThemes: false,
51
+ migratableThemesCount: 0,
52
+ });
53
+ });
54
+ it('should return true when there are legacy themes', async () => {
55
+ mockedGetProjectThemeDetails.mockResolvedValue({
56
+ legacyThemeDetails: [
57
+ {
58
+ configFilepath: 'src/theme.json',
59
+ themePath: 'src/theme',
60
+ themeConfig: {
61
+ secret_names: ['my-secret'],
62
+ },
63
+ },
64
+ ],
65
+ legacyReactThemeDetails: [],
66
+ });
67
+ const projectConfig = createLoadedProjectConfig(PROJECT_NAME);
68
+ const result = await getHasMigratableThemes(projectConfig);
69
+ expect(result).toEqual({
70
+ hasMigratableThemes: true,
71
+ migratableThemesCount: 1,
72
+ });
73
+ });
74
+ it('should return true when there are legacy React themes', async () => {
75
+ mockedGetProjectThemeDetails.mockResolvedValue({
76
+ legacyThemeDetails: [],
77
+ legacyReactThemeDetails: [
78
+ {
79
+ configFilepath: 'src/react-theme.json',
80
+ themePath: 'src/react-theme',
81
+ themeConfig: {
82
+ secretNames: ['my-secret'],
83
+ },
84
+ },
85
+ ],
86
+ });
87
+ const projectConfig = createLoadedProjectConfig(PROJECT_NAME);
88
+ const result = await getHasMigratableThemes(projectConfig);
89
+ expect(result).toEqual({
90
+ hasMigratableThemes: true,
91
+ migratableThemesCount: 1,
92
+ });
93
+ });
94
+ it('should return true when there are both legacy and React themes', async () => {
95
+ mockedGetProjectThemeDetails.mockResolvedValue({
96
+ legacyThemeDetails: [
97
+ {
98
+ configFilepath: 'src/theme.json',
99
+ themePath: 'src/theme',
100
+ themeConfig: {
101
+ secret_names: ['my-secret'],
102
+ },
103
+ },
104
+ ],
105
+ legacyReactThemeDetails: [
106
+ {
107
+ configFilepath: 'src/react-theme.json',
108
+ themePath: 'src/react-theme',
109
+ themeConfig: {
110
+ secretNames: ['my-secret'],
111
+ },
112
+ },
113
+ ],
114
+ });
115
+ const projectConfig = createLoadedProjectConfig(PROJECT_NAME);
116
+ const result = await getHasMigratableThemes(projectConfig);
117
+ expect(result).toEqual({
118
+ hasMigratableThemes: true,
119
+ migratableThemesCount: 2,
120
+ });
121
+ });
122
+ });
123
+ describe('validateMigrationAppsAndThemes', () => {
124
+ it('should throw an error when themes are already migrated (v3 API)', async () => {
125
+ mockedUseV3Api.mockReturnValue(true);
126
+ const projectConfig = createLoadedProjectConfig(PROJECT_NAME);
127
+ await expect(validateMigrationAppsAndThemes(0, projectConfig)).rejects.toThrow(lib.migrate.errors.project.themesAlreadyMigrated);
128
+ });
129
+ it('should throw an error when apps and themes are both present', async () => {
130
+ const projectConfig = createLoadedProjectConfig(PROJECT_NAME);
131
+ await expect(validateMigrationAppsAndThemes(1, projectConfig)).rejects.toThrow(lib.migrate.errors.project.themesAndAppsNotAllowed);
132
+ });
133
+ it('should throw an error when no project config is provided', async () => {
134
+ await expect(validateMigrationAppsAndThemes(0)).rejects.toThrow(lib.migrate.errors.project.noProjectForThemesMigration);
135
+ });
136
+ it('should not throw an error when validation passes', async () => {
137
+ const projectConfig = createLoadedProjectConfig(PROJECT_NAME);
138
+ await expect(validateMigrationAppsAndThemes(0, projectConfig)).resolves.not.toThrow();
139
+ });
140
+ });
141
+ describe('handleThemesMigration', () => {
142
+ const projectConfig = createLoadedProjectConfig(PROJECT_NAME);
143
+ beforeEach(() => {
144
+ mockedMigrateThemes.mockResolvedValue({
145
+ migrated: true,
146
+ failureReason: undefined,
147
+ legacyThemeDetails: [],
148
+ legacyReactThemeDetails: [],
149
+ });
150
+ mockedWriteProjectConfig.mockReturnValue(true);
151
+ });
152
+ it('should throw an error when project config is invalid', async () => {
153
+ const invalidProjectConfig = {
154
+ projectConfig: { name: PROJECT_NAME, srcDir: undefined },
155
+ projectDir: undefined,
156
+ };
157
+ await expect(handleThemesMigration(invalidProjectConfig, PLATFORM_VERSION)).rejects.toThrow(lib.migrate.errors.project.invalidConfig);
158
+ });
159
+ it('should successfully migrate themes and update project config', async () => {
160
+ await handleThemesMigration(projectConfig, PLATFORM_VERSION);
161
+ expect(mockedMigrateThemes).toHaveBeenCalledWith(MOCK_PROJECT_DIR, `${MOCK_PROJECT_DIR}/src`);
162
+ expect(mockedWriteProjectConfig).toHaveBeenCalledWith(`${MOCK_PROJECT_DIR}/hsproject.json`, expect.objectContaining({
163
+ platformVersion: PLATFORM_VERSION,
164
+ }));
165
+ });
166
+ it('should throw an error when theme migration fails', async () => {
167
+ mockedMigrateThemes.mockResolvedValue({
168
+ migrated: false,
169
+ failureReason: 'Migration failed',
170
+ legacyThemeDetails: [],
171
+ legacyReactThemeDetails: [],
172
+ });
173
+ await expect(handleThemesMigration(projectConfig, PLATFORM_VERSION)).rejects.toThrow('Migration failed');
174
+ });
175
+ it('should throw an error when project config write fails', async () => {
176
+ mockedWriteProjectConfig.mockReturnValue(false);
177
+ await expect(handleThemesMigration(projectConfig, PLATFORM_VERSION)).rejects.toThrow(lib.migrate.errors.project.failedToUpdateProjectConfig);
178
+ });
179
+ it('should throw an error when migrateThemes throws an exception', async () => {
180
+ mockedMigrateThemes.mockRejectedValue(new Error('Unexpected error'));
181
+ await expect(handleThemesMigration(projectConfig, PLATFORM_VERSION)).rejects.toThrow(lib.migrate.errors.project.failedToMigrateThemes);
182
+ });
183
+ });
184
+ describe('migrateThemes2025_2', () => {
185
+ const options = {
186
+ platformVersion: PLATFORM_VERSION,
187
+ };
188
+ const projectConfig = createLoadedProjectConfig(PROJECT_NAME);
189
+ const themeCount = 2;
190
+ beforeEach(() => {
191
+ mockedEnsureProjectExists.mockResolvedValue({ projectExists: true });
192
+ mockedFetchMigrationApps.mockResolvedValue({
193
+ migratableApps: [],
194
+ unmigratableApps: [],
195
+ });
196
+ mockedConfirmPrompt.mockResolvedValue(true);
197
+ mockedMigrateThemes.mockResolvedValue({
198
+ migrated: true,
199
+ failureReason: undefined,
200
+ legacyThemeDetails: [],
201
+ legacyReactThemeDetails: [],
202
+ });
203
+ mockedWriteProjectConfig.mockReturnValue(true);
204
+ });
205
+ it('should throw an error when project config is invalid', async () => {
206
+ const invalidProjectConfig = {
207
+ projectConfig: undefined,
208
+ projectDir: MOCK_PROJECT_DIR,
209
+ };
210
+ await expect(migrateThemes2025_2(ACCOUNT_ID, options, themeCount, invalidProjectConfig)).rejects.toThrow(lib.migrate.errors.project.invalidConfig);
211
+ });
212
+ it('should throw an error when project does not exist', async () => {
213
+ mockedEnsureProjectExists.mockResolvedValue({ projectExists: false });
214
+ await expect(migrateThemes2025_2(ACCOUNT_ID, options, themeCount, projectConfig)).rejects.toThrow(lib.migrate.errors.project.doesNotExist(ACCOUNT_ID));
215
+ });
216
+ it('should proceed with migration when user confirms', async () => {
217
+ await migrateThemes2025_2(ACCOUNT_ID, options, themeCount, projectConfig);
218
+ expect(mockedFetchMigrationApps).toHaveBeenCalledWith(ACCOUNT_ID, PLATFORM_VERSION, projectConfig);
219
+ expect(mockedConfirmPrompt).toHaveBeenCalledWith(lib.migrate.prompt.proceed, { defaultAnswer: false });
220
+ expect(mockedMigrateThemes).toHaveBeenCalledWith(MOCK_PROJECT_DIR, `${MOCK_PROJECT_DIR}/src`);
221
+ });
222
+ it('should exit without migrating when user cancels', async () => {
223
+ mockedConfirmPrompt.mockResolvedValue(false);
224
+ await migrateThemes2025_2(ACCOUNT_ID, options, themeCount, projectConfig);
225
+ expect(mockedMigrateThemes).not.toHaveBeenCalled();
226
+ });
227
+ it('should validate migration apps and themes', async () => {
228
+ await migrateThemes2025_2(ACCOUNT_ID, options, themeCount, projectConfig);
229
+ // The validation is called internally, so we verify it through the error handling
230
+ expect(mockedFetchMigrationApps).toHaveBeenCalled();
231
+ });
232
+ });
233
+ });
@@ -0,0 +1,13 @@
1
+ import { ArgumentsCamelCase } from 'yargs';
2
+ import { LoadedProjectConfig } from '../projects/config.js';
3
+ import { AccountArgs, CommonArgs, ConfigArgs, EnvironmentArgs } from '../../types/Yargs.js';
4
+ export type MigrateThemesArgs = CommonArgs & AccountArgs & EnvironmentArgs & ConfigArgs & {
5
+ platformVersion: string;
6
+ };
7
+ export declare function getHasMigratableThemes(projectConfig?: LoadedProjectConfig): Promise<{
8
+ hasMigratableThemes: boolean;
9
+ migratableThemesCount: number;
10
+ }>;
11
+ export declare function validateMigrationAppsAndThemes(hasApps: number, projectConfig?: LoadedProjectConfig): Promise<void>;
12
+ export declare function handleThemesMigration(projectConfig: LoadedProjectConfig, platformVersion: string): Promise<void>;
13
+ export declare function migrateThemes2025_2(derivedAccountId: number, options: ArgumentsCamelCase<MigrateThemesArgs>, themeCount: number, projectConfig: LoadedProjectConfig): Promise<void>;
@@ -0,0 +1,90 @@
1
+ import path from 'path';
2
+ import { migrateThemes, getProjectThemeDetails, } from '@hubspot/project-parsing-lib';
3
+ import { writeProjectConfig } from '../projects/config.js';
4
+ import { ensureProjectExists } from '../projects/ensureProjectExists.js';
5
+ import SpinniesManager from '../ui/SpinniesManager.js';
6
+ import { lib } from '../../lang/en.js';
7
+ import { PROJECT_CONFIG_FILE } from '../constants.js';
8
+ import { uiLogger } from '../ui/logger.js';
9
+ import { debugError } from '../errorHandlers/index.js';
10
+ import { useV3Api } from '../projects/platformVersion.js';
11
+ import { confirmPrompt } from '../prompts/promptUtils.js';
12
+ import { fetchMigrationApps } from '../app/migrate.js';
13
+ export async function getHasMigratableThemes(projectConfig) {
14
+ if (!projectConfig?.projectConfig?.name || !projectConfig?.projectDir) {
15
+ return { hasMigratableThemes: false, migratableThemesCount: 0 };
16
+ }
17
+ const projectSrcDir = path.resolve(projectConfig.projectDir, projectConfig.projectConfig.srcDir);
18
+ const { legacyThemeDetails, legacyReactThemeDetails } = await getProjectThemeDetails(projectSrcDir);
19
+ return {
20
+ hasMigratableThemes: legacyThemeDetails.length > 0 || legacyReactThemeDetails.length > 0,
21
+ migratableThemesCount: legacyThemeDetails.length + legacyReactThemeDetails.length,
22
+ };
23
+ }
24
+ export async function validateMigrationAppsAndThemes(hasApps, projectConfig) {
25
+ if (useV3Api(projectConfig?.projectConfig?.platformVersion)) {
26
+ throw new Error(lib.migrate.errors.project.themesAlreadyMigrated);
27
+ }
28
+ if (hasApps > 0 && projectConfig) {
29
+ throw new Error(lib.migrate.errors.project.themesAndAppsNotAllowed);
30
+ }
31
+ if (!projectConfig) {
32
+ throw new Error(lib.migrate.errors.project.noProjectForThemesMigration);
33
+ }
34
+ }
35
+ export async function handleThemesMigration(projectConfig, platformVersion) {
36
+ if (!projectConfig?.projectDir || !projectConfig?.projectConfig?.srcDir) {
37
+ throw new Error(lib.migrate.errors.project.invalidConfig);
38
+ }
39
+ const projectSrcDir = path.resolve(projectConfig.projectDir, projectConfig.projectConfig.srcDir);
40
+ let migrated = false;
41
+ let failureReason;
42
+ try {
43
+ const migrationResult = await migrateThemes(projectConfig.projectDir, projectSrcDir);
44
+ migrated = migrationResult.migrated;
45
+ failureReason = migrationResult.failureReason;
46
+ }
47
+ catch (error) {
48
+ debugError(error);
49
+ throw new Error(lib.migrate.errors.project.failedToMigrateThemes);
50
+ }
51
+ if (!migrated) {
52
+ throw new Error(failureReason || lib.migrate.errors.project.failedToMigrateThemes);
53
+ }
54
+ const newProjectConfig = { ...projectConfig.projectConfig };
55
+ newProjectConfig.platformVersion = platformVersion;
56
+ const projectConfigPath = path.join(projectConfig.projectDir, PROJECT_CONFIG_FILE);
57
+ const success = writeProjectConfig(projectConfigPath, newProjectConfig);
58
+ if (!success) {
59
+ throw new Error(lib.migrate.errors.project.failedToUpdateProjectConfig);
60
+ }
61
+ uiLogger.log('');
62
+ uiLogger.log(lib.migrate.success.themesMigrationSuccess(platformVersion));
63
+ }
64
+ export async function migrateThemes2025_2(derivedAccountId, options, themeCount, projectConfig) {
65
+ SpinniesManager.init();
66
+ if (!projectConfig?.projectConfig || !projectConfig?.projectDir) {
67
+ throw new Error(lib.migrate.errors.project.invalidConfig);
68
+ }
69
+ const { projectExists } = await ensureProjectExists(derivedAccountId, projectConfig.projectConfig.name, { allowCreate: false, noLogs: true });
70
+ if (!projectExists) {
71
+ throw new Error(lib.migrate.errors.project.doesNotExist(derivedAccountId));
72
+ }
73
+ SpinniesManager.add('checkingForMigratableComponents', {
74
+ text: lib.migrate.spinners.checkingForMigratableComponents,
75
+ });
76
+ const { migratableApps, unmigratableApps } = await fetchMigrationApps(derivedAccountId, options.platformVersion, projectConfig);
77
+ const hasApps = [...migratableApps, ...unmigratableApps].length;
78
+ SpinniesManager.remove('checkingForMigratableComponents');
79
+ await validateMigrationAppsAndThemes(hasApps, projectConfig);
80
+ uiLogger.log(lib.migrate.prompt.themesMigration(themeCount));
81
+ const proceed = await confirmPrompt(lib.migrate.prompt.proceed, {
82
+ defaultAnswer: false,
83
+ });
84
+ if (proceed) {
85
+ await handleThemesMigration(projectConfig, options.platformVersion);
86
+ }
87
+ else {
88
+ uiLogger.log(lib.migrate.exitWithoutMigrating);
89
+ }
90
+ }
@@ -44,7 +44,7 @@ export async function trackCommandUsage(command, meta = {}, accountId) {
44
44
  action: 'cli-command',
45
45
  command,
46
46
  authType,
47
- ...meta,
47
+ meta,
48
48
  accountId,
49
49
  });
50
50
  }
@@ -133,12 +133,12 @@ async function trackCliInteraction({ action, accountId, command, authType, meta
133
133
  }
134
134
  }
135
135
  try {
136
+ logger.debug('Sent usage tracking command event: %o', usageTrackingEvent);
136
137
  return trackUsage('cli-interaction', EventClass.INTERACTION, usageTrackingEvent, accountId);
137
138
  }
138
139
  catch (error) {
139
140
  debugError(error);
140
141
  }
141
- logger.debug('Sent usage tracking command event: %o', usageTrackingEvent);
142
142
  }
143
143
  catch (e) {
144
144
  debugError(e);
@@ -12,13 +12,13 @@ declare const inputSchemaZodObject: z.ZodObject<{
12
12
  addApp: boolean;
13
13
  auth?: "oauth" | "static" | undefined;
14
14
  distribution?: "marketplace" | "private" | undefined;
15
- features?: ("card" | "page" | "settings" | "app-event" | "workflow-action-tool" | "workflow-action" | "app-function" | "webhooks" | "app-object" | "scim")[] | undefined;
15
+ features?: ("card" | "settings" | "page" | "app-event" | "workflow-action-tool" | "workflow-action" | "app-function" | "webhooks" | "app-object" | "scim")[] | undefined;
16
16
  }, {
17
17
  absoluteProjectPath: string;
18
18
  addApp: boolean;
19
19
  auth?: "oauth" | "static" | undefined;
20
20
  distribution?: "marketplace" | "private" | undefined;
21
- features?: ("card" | "page" | "settings" | "app-event" | "workflow-action-tool" | "workflow-action" | "app-function" | "webhooks" | "app-object" | "scim")[] | undefined;
21
+ features?: ("card" | "settings" | "page" | "app-event" | "workflow-action-tool" | "workflow-action" | "app-function" | "webhooks" | "app-object" | "scim")[] | undefined;
22
22
  }>;
23
23
  export type AddFeatureInputSchema = z.infer<typeof inputSchemaZodObject>;
24
24
  export declare class AddFeatureToProjectTool extends Tool<AddFeatureInputSchema> {
@@ -16,7 +16,7 @@ declare const inputSchemaZodObject: z.ZodObject<{
16
16
  name?: string | undefined;
17
17
  auth?: "oauth" | "static" | undefined;
18
18
  distribution?: "marketplace" | "private" | undefined;
19
- features?: ("card" | "page" | "settings" | "app-event" | "workflow-action-tool" | "workflow-action" | "app-function" | "webhooks" | "app-object" | "scim")[] | undefined;
19
+ features?: ("card" | "settings" | "page" | "app-event" | "workflow-action-tool" | "workflow-action" | "app-function" | "webhooks" | "app-object" | "scim")[] | undefined;
20
20
  }, {
21
21
  projectBase: "app" | "empty";
22
22
  absoluteCurrentWorkingDirectory: string;
@@ -24,7 +24,7 @@ declare const inputSchemaZodObject: z.ZodObject<{
24
24
  name?: string | undefined;
25
25
  auth?: "oauth" | "static" | undefined;
26
26
  distribution?: "marketplace" | "private" | undefined;
27
- features?: ("card" | "page" | "settings" | "app-event" | "workflow-action-tool" | "workflow-action" | "app-function" | "webhooks" | "app-object" | "scim")[] | undefined;
27
+ features?: ("card" | "settings" | "page" | "app-event" | "workflow-action-tool" | "workflow-action" | "app-function" | "webhooks" | "app-object" | "scim")[] | undefined;
28
28
  }>;
29
29
  export type CreateProjectInputSchema = z.infer<typeof inputSchemaZodObject>;
30
30
  export declare class CreateProjectTool extends Tool<CreateProjectInputSchema> {
@@ -2,10 +2,13 @@ import { McpServer, RegisteredTool } from '@modelcontextprotocol/sdk/server/mcp.
2
2
  import z from 'zod';
3
3
  import { TextContentResponse, Tool } from '../../types.js';
4
4
  declare const inputSchemaZodObject: z.ZodObject<{
5
+ absoluteCurrentWorkingDirectory: z.ZodString;
5
6
  docsSearchQuery: z.ZodString;
6
7
  }, "strip", z.ZodTypeAny, {
8
+ absoluteCurrentWorkingDirectory: string;
7
9
  docsSearchQuery: string;
8
10
  }, {
11
+ absoluteCurrentWorkingDirectory: string;
9
12
  docsSearchQuery: string;
10
13
  }>;
11
14
  export interface DocsSearchResponse {
@@ -20,7 +23,7 @@ export interface DocsSearchResponse {
20
23
  type InputSchemaType = z.infer<typeof inputSchemaZodObject>;
21
24
  export declare class DocsSearchTool extends Tool<InputSchemaType> {
22
25
  constructor(mcpServer: McpServer);
23
- handler({ docsSearchQuery, }: InputSchemaType): Promise<TextContentResponse>;
26
+ handler({ absoluteCurrentWorkingDirectory, docsSearchQuery, }: InputSchemaType): Promise<TextContentResponse>;
24
27
  register(): RegisteredTool;
25
28
  }
26
29
  export {};
@@ -3,10 +3,11 @@ import z from 'zod';
3
3
  import { Tool } from '../../types.js';
4
4
  import { formatTextContents } from '../../utils/content.js';
5
5
  import { trackToolUsage } from '../../utils/toolUsageTracking.js';
6
- import { docsSearchQuery } from './constants.js';
7
- import { getAccountId, getConfigPath, loadConfig, } from '@hubspot/local-dev-lib/config';
6
+ import { absoluteCurrentWorkingDirectory, docsSearchQuery, } from './constants.js';
8
7
  import { isHubSpotHttpError } from '@hubspot/local-dev-lib/errors/index';
8
+ import { getAccountIdFromCliConfig } from '../../utils/cliConfig.js';
9
9
  const inputSchema = {
10
+ absoluteCurrentWorkingDirectory,
10
11
  docsSearchQuery,
11
12
  };
12
13
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -18,10 +19,9 @@ export class DocsSearchTool extends Tool {
18
19
  constructor(mcpServer) {
19
20
  super(mcpServer);
20
21
  }
21
- async handler({ docsSearchQuery, }) {
22
+ async handler({ absoluteCurrentWorkingDirectory, docsSearchQuery, }) {
22
23
  await trackToolUsage(toolName, { mode: docsSearchQuery });
23
- loadConfig(getConfigPath());
24
- const accountId = getAccountId();
24
+ const accountId = getAccountIdFromCliConfig(absoluteCurrentWorkingDirectory);
25
25
  if (!accountId) {
26
26
  const authErrorMessage = `No account ID found. Please run \`hs account auth\` to configure an account, or set a default account with \`hs account use <account>\``;
27
27
  return formatTextContents(authErrorMessage);
@@ -2,19 +2,22 @@ import { TextContentResponse, Tool } from '../../types.js';
2
2
  import { McpServer, RegisteredTool } from '@modelcontextprotocol/sdk/server/mcp.js';
3
3
  import { z } from 'zod';
4
4
  declare const inputSchemaZodObject: z.ZodObject<{
5
+ absoluteCurrentWorkingDirectory: z.ZodString;
5
6
  platformVersion: z.ZodString;
6
7
  featureType: z.ZodString;
7
8
  }, "strip", z.ZodTypeAny, {
8
9
  platformVersion: string;
10
+ absoluteCurrentWorkingDirectory: string;
9
11
  featureType: string;
10
12
  }, {
11
13
  platformVersion: string;
14
+ absoluteCurrentWorkingDirectory: string;
12
15
  featureType: string;
13
16
  }>;
14
17
  type InputSchemaType = z.infer<typeof inputSchemaZodObject>;
15
18
  export declare class GetConfigValuesTool extends Tool<InputSchemaType> {
16
19
  constructor(mcpServer: McpServer);
17
- handler({ platformVersion, featureType, }: InputSchemaType): Promise<TextContentResponse>;
20
+ handler({ absoluteCurrentWorkingDirectory, platformVersion, featureType, }: InputSchemaType): Promise<TextContentResponse>;
18
21
  register(): RegisteredTool;
19
22
  }
20
23
  export {};
@@ -1,10 +1,12 @@
1
1
  import { Tool } from '../../types.js';
2
2
  import { z } from 'zod';
3
3
  import { formatTextContents } from '../../utils/content.js';
4
+ import { absoluteCurrentWorkingDirectory } from './constants.js';
4
5
  import { getIntermediateRepresentationSchema, mapToInternalType, } from '@hubspot/project-parsing-lib';
5
- import { getAccountId, getConfigPath, loadConfig, } from '@hubspot/local-dev-lib/config';
6
6
  import { useV3Api } from '../../../lib/projects/platformVersion.js';
7
+ import { getAccountIdFromCliConfig } from '../../utils/cliConfig.js';
7
8
  const inputSchema = {
9
+ absoluteCurrentWorkingDirectory,
8
10
  platformVersion: z
9
11
  .string()
10
12
  .describe('The platform version for the project. Located in the hsproject.json file.'),
@@ -21,16 +23,20 @@ export class GetConfigValuesTool extends Tool {
21
23
  constructor(mcpServer) {
22
24
  super(mcpServer);
23
25
  }
24
- async handler({ platformVersion, featureType, }) {
26
+ async handler({ absoluteCurrentWorkingDirectory, platformVersion, featureType, }) {
25
27
  try {
26
28
  if (!useV3Api(platformVersion)) {
27
29
  return formatTextContents(`Can only be used on projects with a minimum platformVersion of 2025.2`);
28
30
  }
29
- loadConfig(getConfigPath());
31
+ const accountId = getAccountIdFromCliConfig(absoluteCurrentWorkingDirectory);
32
+ if (!accountId) {
33
+ const authErrorMessage = `No account ID found. Please run \`hs account auth\` to configure an account, or set a default account with \`hs account use <account>\``;
34
+ return formatTextContents(authErrorMessage);
35
+ }
30
36
  const schema = await getIntermediateRepresentationSchema({
31
37
  platformVersion,
32
38
  projectSourceDir: '',
33
- accountId: getAccountId(),
39
+ accountId,
34
40
  });
35
41
  const internalComponentType = mapToInternalType(featureType);
36
42
  if (schema[internalComponentType]) {
@@ -1,14 +1,14 @@
1
1
  import { DocsSearchTool } from '../DocsSearchTool.js';
2
2
  import { http } from '@hubspot/local-dev-lib/http';
3
- import { getAccountId } from '@hubspot/local-dev-lib/config';
4
3
  import { isHubSpotHttpError } from '@hubspot/local-dev-lib/errors/index';
4
+ import { getAccountIdFromCliConfig } from '../../../utils/cliConfig.js';
5
5
  vi.mock('@modelcontextprotocol/sdk/server/mcp.js');
6
6
  vi.mock('@hubspot/local-dev-lib/http');
7
- vi.mock('@hubspot/local-dev-lib/config');
8
7
  vi.mock('@hubspot/local-dev-lib/errors/index');
9
8
  vi.mock('../../../utils/toolUsageTracking');
9
+ vi.mock('../../../utils/cliConfig.js');
10
10
  const mockHttp = http;
11
- const mockGetAccountId = getAccountId;
11
+ const mockGetAccountIdFromCliConfig = getAccountIdFromCliConfig;
12
12
  const mockIsHubSpotHttpError = vi.mocked(isHubSpotHttpError);
13
13
  describe('mcp-server/tools/project/DocsSearchTool', () => {
14
14
  let mockMcpServer;
@@ -38,9 +38,10 @@ describe('mcp-server/tools/project/DocsSearchTool', () => {
38
38
  describe('handler', () => {
39
39
  const mockInput = {
40
40
  docsSearchQuery: 'test query',
41
+ absoluteCurrentWorkingDirectory: '/foo',
41
42
  };
42
43
  it('should return auth error message when no account ID is found', async () => {
43
- mockGetAccountId.mockReturnValue(null);
44
+ mockGetAccountIdFromCliConfig.mockReturnValue(null);
44
45
  const result = await tool.handler(mockInput);
45
46
  expect(result).toEqual({
46
47
  content: [
@@ -52,7 +53,7 @@ describe('mcp-server/tools/project/DocsSearchTool', () => {
52
53
  });
53
54
  });
54
55
  it('should return successful results when docs are found', async () => {
55
- mockGetAccountId.mockReturnValue(12345);
56
+ mockGetAccountIdFromCliConfig.mockReturnValue(12345);
56
57
  const mockResponse = {
57
58
  results: [
58
59
  {
@@ -76,6 +77,7 @@ describe('mcp-server/tools/project/DocsSearchTool', () => {
76
77
  data: mockResponse,
77
78
  });
78
79
  const result = await tool.handler(mockInput);
80
+ expect(mockGetAccountIdFromCliConfig).toHaveBeenCalledWith('/foo');
79
81
  expect(mockHttp.post).toHaveBeenCalledWith(12345, {
80
82
  url: 'dev/docs/llms/v1/docs-search',
81
83
  data: {
@@ -103,7 +105,7 @@ describe('mcp-server/tools/project/DocsSearchTool', () => {
103
105
  expect(resultText).toContain('Test content 2');
104
106
  });
105
107
  it('should return no results message when no documentation is found', async () => {
106
- mockGetAccountId.mockReturnValue(12345);
108
+ mockGetAccountIdFromCliConfig.mockReturnValue(12345);
107
109
  const mockResponse = {
108
110
  results: [],
109
111
  };
@@ -122,7 +124,7 @@ describe('mcp-server/tools/project/DocsSearchTool', () => {
122
124
  });
123
125
  });
124
126
  it('should return no results message when results is null', async () => {
125
- mockGetAccountId.mockReturnValue(12345);
127
+ mockGetAccountIdFromCliConfig.mockReturnValue(12345);
126
128
  const mockResponse = {
127
129
  results: null,
128
130
  };
@@ -141,7 +143,7 @@ describe('mcp-server/tools/project/DocsSearchTool', () => {
141
143
  });
142
144
  });
143
145
  it('should handle HubSpot HTTP errors', async () => {
144
- mockGetAccountId.mockReturnValue(12345);
146
+ mockGetAccountIdFromCliConfig.mockReturnValue(12345);
145
147
  const mockError = {
146
148
  toString: () => 'HubSpot API Error: 404 Not Found',
147
149
  };
@@ -158,7 +160,7 @@ describe('mcp-server/tools/project/DocsSearchTool', () => {
158
160
  });
159
161
  });
160
162
  it('should handle generic errors', async () => {
161
- mockGetAccountId.mockReturnValue(12345);
163
+ mockGetAccountIdFromCliConfig.mockReturnValue(12345);
162
164
  const mockError = new Error('Network error');
163
165
  mockHttp.post.mockRejectedValue(mockError);
164
166
  mockIsHubSpotHttpError.mockReturnValue(false);
@@ -173,7 +175,7 @@ describe('mcp-server/tools/project/DocsSearchTool', () => {
173
175
  });
174
176
  });
175
177
  it('should handle non-Error rejections', async () => {
176
- mockGetAccountId.mockReturnValue(12345);
178
+ mockGetAccountIdFromCliConfig.mockReturnValue(12345);
177
179
  mockHttp.post.mockRejectedValue('String error');
178
180
  mockIsHubSpotHttpError.mockReturnValue(false);
179
181
  const result = await tool.handler(mockInput);
@@ -1,13 +1,13 @@
1
1
  import { GetConfigValuesTool } from '../GetConfigValuesTool.js';
2
2
  import { getIntermediateRepresentationSchema, mapToInternalType, } from '@hubspot/project-parsing-lib';
3
- import { getAccountId } from '@hubspot/local-dev-lib/config';
3
+ import { getAccountIdFromCliConfig } from '../../../utils/cliConfig.js';
4
4
  vi.mock('@modelcontextprotocol/sdk/server/mcp.js');
5
5
  vi.mock('@hubspot/project-parsing-lib');
6
- vi.mock('@hubspot/local-dev-lib/config');
6
+ vi.mock('../../../utils/cliConfig.js');
7
7
  vi.mock('../../../utils/toolUsageTracking');
8
8
  const mockGetIntermediateRepresentationSchema = getIntermediateRepresentationSchema;
9
9
  const mockMapToInternalType = mapToInternalType;
10
- const mockGetAccountId = getAccountId;
10
+ const mockGetAccountIdFromCliConfig = getAccountIdFromCliConfig;
11
11
  describe('mcp-server/tools/project/GetConfigValuesTool', () => {
12
12
  let mockMcpServer;
13
13
  let tool;
@@ -44,9 +44,10 @@ describe('mcp-server/tools/project/GetConfigValuesTool', () => {
44
44
  const input = {
45
45
  platformVersion: '2025.2',
46
46
  featureType: 'card',
47
+ absoluteCurrentWorkingDirectory: '/foo',
47
48
  };
48
49
  beforeEach(() => {
49
- mockGetAccountId.mockReturnValue(123456789);
50
+ mockGetAccountIdFromCliConfig.mockReturnValue(123456789);
50
51
  });
51
52
  it('should return config schema when component type exists', async () => {
52
53
  const mockSchema = {
@@ -61,6 +62,7 @@ describe('mcp-server/tools/project/GetConfigValuesTool', () => {
61
62
  mockGetIntermediateRepresentationSchema.mockResolvedValue(mockSchema);
62
63
  mockMapToInternalType.mockReturnValue('internal-card-type');
63
64
  const result = await tool.handler(input);
65
+ expect(mockGetAccountIdFromCliConfig).toHaveBeenCalledWith('/foo');
64
66
  expect(mockGetIntermediateRepresentationSchema).toHaveBeenCalledWith({
65
67
  platformVersion: '2025.2',
66
68
  projectSourceDir: '',
@@ -133,14 +135,13 @@ describe('mcp-server/tools/project/GetConfigValuesTool', () => {
133
135
  });
134
136
  });
135
137
  it('should handle null account id', async () => {
136
- mockGetAccountId.mockReturnValue(null);
137
- mockGetIntermediateRepresentationSchema.mockRejectedValue(new Error('No account ID'));
138
+ mockGetAccountIdFromCliConfig.mockReturnValue(null);
138
139
  const result = await tool.handler(input);
139
140
  expect(result).toEqual({
140
141
  content: [
141
142
  {
142
143
  type: 'text',
143
- text: 'Unable to locate JSON schema for type card',
144
+ text: 'No account ID found. Please run `hs account auth` to configure an account, or set a default account with `hs account use <account>`',
144
145
  },
145
146
  ],
146
147
  });