@hubspot/cli 7.6.0-beta.7 → 7.6.0-beta.9

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.
Files changed (41) hide show
  1. package/commands/__tests__/create.test.js +20 -0
  2. package/commands/create/function.js +2 -2
  3. package/commands/create/module.js +2 -2
  4. package/commands/create/template.js +2 -2
  5. package/commands/create.js +47 -0
  6. package/commands/getStarted.js +3 -2
  7. package/commands/project/deploy.js +31 -1
  8. package/lang/en.d.ts +40 -4
  9. package/lang/en.js +44 -7
  10. package/lang/en.lyaml +23 -2
  11. package/lib/process.js +15 -4
  12. package/lib/prompts/__tests__/createFunctionPrompt.test.d.ts +1 -0
  13. package/lib/prompts/__tests__/createFunctionPrompt.test.js +129 -0
  14. package/lib/prompts/__tests__/createModulePrompt.test.d.ts +1 -0
  15. package/lib/prompts/__tests__/createModulePrompt.test.js +187 -0
  16. package/lib/prompts/__tests__/createTemplatePrompt.test.d.ts +1 -0
  17. package/lib/prompts/__tests__/createTemplatePrompt.test.js +102 -0
  18. package/lib/prompts/createFunctionPrompt.d.ts +2 -1
  19. package/lib/prompts/createFunctionPrompt.js +36 -7
  20. package/lib/prompts/createModulePrompt.d.ts +2 -1
  21. package/lib/prompts/createModulePrompt.js +48 -1
  22. package/lib/prompts/createTemplatePrompt.d.ts +3 -24
  23. package/lib/prompts/createTemplatePrompt.js +9 -1
  24. package/mcp-server/tools/index.js +4 -0
  25. package/mcp-server/tools/project/DocFetchTool.d.ts +17 -0
  26. package/mcp-server/tools/project/DocFetchTool.js +49 -0
  27. package/mcp-server/tools/project/DocsSearchTool.d.ts +26 -0
  28. package/mcp-server/tools/project/DocsSearchTool.js +62 -0
  29. package/mcp-server/tools/project/GetConfigValuesTool.js +3 -2
  30. package/mcp-server/tools/project/__tests__/DocFetchTool.test.d.ts +1 -0
  31. package/mcp-server/tools/project/__tests__/DocFetchTool.test.js +117 -0
  32. package/mcp-server/tools/project/__tests__/DocsSearchTool.test.d.ts +1 -0
  33. package/mcp-server/tools/project/__tests__/DocsSearchTool.test.js +190 -0
  34. package/mcp-server/tools/project/__tests__/GetConfigValuesTool.test.js +1 -1
  35. package/mcp-server/tools/project/constants.d.ts +2 -0
  36. package/mcp-server/tools/project/constants.js +6 -0
  37. package/mcp-server/utils/toolUsageTracking.d.ts +3 -1
  38. package/mcp-server/utils/toolUsageTracking.js +2 -1
  39. package/package.json +1 -1
  40. package/types/Cms.d.ts +16 -0
  41. package/types/Cms.js +25 -1
@@ -0,0 +1,187 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { createModulePrompt } from '../createModulePrompt.js';
3
+ import { promptUser } from '../promptUtils.js';
4
+ vi.mock('../promptUtils.js');
5
+ const mockPromptUser = vi.mocked(promptUser);
6
+ describe('createModulePrompt', () => {
7
+ beforeEach(() => {
8
+ vi.resetAllMocks();
9
+ });
10
+ describe('when all parameters are provided', () => {
11
+ it('should return provided values without prompting', async () => {
12
+ const commandArgs = {
13
+ moduleLabel: 'My Module',
14
+ reactType: true,
15
+ contentTypes: 'LANDING_PAGE,SITE_PAGE',
16
+ global: false,
17
+ availableForNewContent: true,
18
+ };
19
+ const result = await createModulePrompt(commandArgs);
20
+ expect(mockPromptUser).not.toHaveBeenCalled();
21
+ expect(result).toEqual({
22
+ moduleLabel: 'My Module',
23
+ reactType: true,
24
+ contentTypes: ['LANDING_PAGE', 'SITE_PAGE'],
25
+ global: false,
26
+ availableForNewContent: true,
27
+ });
28
+ });
29
+ it('should use default values when optional parameters not provided', async () => {
30
+ const commandArgs = {
31
+ moduleLabel: 'My Module',
32
+ };
33
+ mockPromptUser.mockResolvedValue({
34
+ reactType: false,
35
+ contentTypes: ['ANY'],
36
+ global: false,
37
+ availableForNewContent: true,
38
+ });
39
+ const result = await createModulePrompt(commandArgs);
40
+ expect(mockPromptUser).toHaveBeenCalledWith([
41
+ expect.objectContaining({ name: 'reactType' }),
42
+ expect.objectContaining({ name: 'contentTypes' }),
43
+ expect.objectContaining({ name: 'global' }),
44
+ expect.objectContaining({ name: 'availableForNewContent' }),
45
+ ]);
46
+ expect(result).toEqual({
47
+ moduleLabel: 'My Module',
48
+ reactType: false,
49
+ contentTypes: ['ANY'],
50
+ global: false,
51
+ availableForNewContent: true,
52
+ });
53
+ });
54
+ it('should parse contentTypes string correctly', async () => {
55
+ const commandArgs = {
56
+ moduleLabel: 'Test Module',
57
+ contentTypes: 'BLOG_POST, EMAIL, LANDING_PAGE',
58
+ };
59
+ mockPromptUser.mockResolvedValue({
60
+ reactType: false,
61
+ global: false,
62
+ availableForNewContent: true,
63
+ });
64
+ const result = await createModulePrompt(commandArgs);
65
+ expect(result.contentTypes).toEqual([
66
+ 'BLOG_POST',
67
+ 'EMAIL',
68
+ 'LANDING_PAGE',
69
+ ]);
70
+ });
71
+ });
72
+ describe('when some parameters are missing', () => {
73
+ it('should only prompt for missing parameters', async () => {
74
+ const commandArgs = {
75
+ moduleLabel: 'My Module',
76
+ reactType: true,
77
+ };
78
+ mockPromptUser.mockResolvedValue({
79
+ contentTypes: ['SITE_PAGE'],
80
+ global: true,
81
+ availableForNewContent: false,
82
+ });
83
+ const result = await createModulePrompt(commandArgs);
84
+ expect(mockPromptUser).toHaveBeenCalledWith([
85
+ expect.objectContaining({ name: 'contentTypes' }),
86
+ expect.objectContaining({ name: 'global' }),
87
+ expect.objectContaining({ name: 'availableForNewContent' }),
88
+ ]);
89
+ expect(result).toEqual({
90
+ moduleLabel: 'My Module',
91
+ reactType: true,
92
+ contentTypes: ['SITE_PAGE'],
93
+ global: true,
94
+ availableForNewContent: false,
95
+ });
96
+ });
97
+ });
98
+ describe('when no parameters are provided', () => {
99
+ it('should prompt for all parameters', async () => {
100
+ mockPromptUser.mockResolvedValue({
101
+ moduleLabel: 'Prompted Module',
102
+ reactType: false,
103
+ contentTypes: ['ANY'],
104
+ global: false,
105
+ availableForNewContent: true,
106
+ });
107
+ const result = await createModulePrompt();
108
+ expect(mockPromptUser).toHaveBeenCalledWith([
109
+ expect.objectContaining({ name: 'moduleLabel' }),
110
+ expect.objectContaining({ name: 'reactType' }),
111
+ expect.objectContaining({ name: 'contentTypes' }),
112
+ expect.objectContaining({ name: 'global' }),
113
+ expect.objectContaining({ name: 'availableForNewContent' }),
114
+ ]);
115
+ expect(result).toEqual({
116
+ moduleLabel: 'Prompted Module',
117
+ reactType: false,
118
+ contentTypes: ['ANY'],
119
+ global: false,
120
+ availableForNewContent: true,
121
+ });
122
+ });
123
+ });
124
+ describe('parameter precedence', () => {
125
+ it('should prioritize command args over prompted values', async () => {
126
+ const commandArgs = {
127
+ moduleLabel: 'Args Module',
128
+ global: true,
129
+ };
130
+ mockPromptUser.mockResolvedValue({
131
+ reactType: false,
132
+ contentTypes: ['EMAIL'],
133
+ availableForNewContent: false,
134
+ });
135
+ const result = await createModulePrompt(commandArgs);
136
+ expect(result).toEqual({
137
+ moduleLabel: 'Args Module', // from commandArgs
138
+ reactType: false, // from prompt
139
+ contentTypes: ['EMAIL'], // from prompt
140
+ global: true, // from commandArgs
141
+ availableForNewContent: false, // from prompt
142
+ });
143
+ });
144
+ it('should handle boolean false values correctly', async () => {
145
+ const commandArgs = {
146
+ moduleLabel: 'Test Module',
147
+ reactType: false,
148
+ contentTypes: 'ANY',
149
+ global: false,
150
+ availableForNewContent: false,
151
+ };
152
+ const result = await createModulePrompt(commandArgs);
153
+ expect(mockPromptUser).not.toHaveBeenCalled();
154
+ expect(result).toEqual({
155
+ moduleLabel: 'Test Module',
156
+ reactType: false,
157
+ contentTypes: ['ANY'],
158
+ global: false,
159
+ availableForNewContent: false,
160
+ });
161
+ });
162
+ it('should handle mixed scenario with partial command args and prompting', async () => {
163
+ const commandArgs = {
164
+ moduleLabel: 'Partial Module',
165
+ contentTypes: 'BLOG_POST,BLOG_LISTING',
166
+ };
167
+ mockPromptUser.mockResolvedValue({
168
+ reactType: true,
169
+ global: false,
170
+ availableForNewContent: true,
171
+ });
172
+ const result = await createModulePrompt(commandArgs);
173
+ expect(mockPromptUser).toHaveBeenCalledWith([
174
+ expect.objectContaining({ name: 'reactType' }),
175
+ expect.objectContaining({ name: 'global' }),
176
+ expect.objectContaining({ name: 'availableForNewContent' }),
177
+ ]);
178
+ expect(result).toEqual({
179
+ moduleLabel: 'Partial Module', // from commandArgs
180
+ reactType: true, // from prompt
181
+ contentTypes: ['BLOG_POST', 'BLOG_LISTING'], // from commandArgs (parsed)
182
+ global: false, // from prompt
183
+ availableForNewContent: true, // from prompt
184
+ });
185
+ });
186
+ });
187
+ });
@@ -0,0 +1,102 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { createTemplatePrompt } from '../createTemplatePrompt.js';
3
+ import { promptUser } from '../promptUtils.js';
4
+ vi.mock('../promptUtils.js');
5
+ const mockPromptUser = vi.mocked(promptUser);
6
+ describe('createTemplatePrompt', () => {
7
+ beforeEach(() => {
8
+ vi.resetAllMocks();
9
+ });
10
+ describe('when templateType is provided', () => {
11
+ it('should return provided templateType without prompting', async () => {
12
+ const commandArgs = {
13
+ templateType: 'page-template',
14
+ };
15
+ const result = await createTemplatePrompt(commandArgs);
16
+ expect(mockPromptUser).not.toHaveBeenCalled();
17
+ expect(result).toEqual({
18
+ templateType: 'page-template',
19
+ });
20
+ });
21
+ it('should work with different template types', async () => {
22
+ const testCases = [
23
+ 'email-template',
24
+ 'partial',
25
+ 'global-partial',
26
+ 'blog-listing-template',
27
+ 'blog-post-template',
28
+ 'search-template',
29
+ 'section',
30
+ ];
31
+ for (const templateType of testCases) {
32
+ const commandArgs = { templateType };
33
+ const result = await createTemplatePrompt(commandArgs);
34
+ expect(mockPromptUser).not.toHaveBeenCalled();
35
+ expect(result).toEqual({ templateType });
36
+ vi.resetAllMocks();
37
+ }
38
+ });
39
+ });
40
+ describe('when templateType is not provided', () => {
41
+ it('should prompt for templateType', async () => {
42
+ mockPromptUser.mockResolvedValue({
43
+ templateType: 'page-template',
44
+ });
45
+ const result = await createTemplatePrompt();
46
+ expect(mockPromptUser).toHaveBeenCalledWith([
47
+ expect.objectContaining({
48
+ name: 'templateType',
49
+ type: 'list',
50
+ choices: expect.any(Array),
51
+ }),
52
+ ]);
53
+ expect(result).toEqual({
54
+ templateType: 'page-template',
55
+ });
56
+ });
57
+ it('should prompt when commandArgs is empty', async () => {
58
+ mockPromptUser.mockResolvedValue({
59
+ templateType: 'email-template',
60
+ });
61
+ const result = await createTemplatePrompt({});
62
+ expect(mockPromptUser).toHaveBeenCalledWith([
63
+ expect.objectContaining({ name: 'templateType' }),
64
+ ]);
65
+ expect(result).toEqual({
66
+ templateType: 'email-template',
67
+ });
68
+ });
69
+ it('should prompt when templateType is undefined', async () => {
70
+ const commandArgs = {
71
+ templateType: undefined,
72
+ };
73
+ mockPromptUser.mockResolvedValue({
74
+ templateType: 'partial',
75
+ });
76
+ const result = await createTemplatePrompt(commandArgs);
77
+ expect(mockPromptUser).toHaveBeenCalledWith([
78
+ expect.objectContaining({ name: 'templateType' }),
79
+ ]);
80
+ expect(result).toEqual({
81
+ templateType: 'partial',
82
+ });
83
+ });
84
+ });
85
+ describe('integration scenarios', () => {
86
+ it('should handle mixed usage patterns', async () => {
87
+ // First call with templateType provided
88
+ let result = await createTemplatePrompt({
89
+ templateType: 'blog-post-template',
90
+ });
91
+ expect(result.templateType).toBe('blog-post-template');
92
+ expect(mockPromptUser).not.toHaveBeenCalled();
93
+ // Second call without templateType
94
+ mockPromptUser.mockResolvedValue({
95
+ templateType: 'section',
96
+ });
97
+ result = await createTemplatePrompt();
98
+ expect(result.templateType).toBe('section');
99
+ expect(mockPromptUser).toHaveBeenCalledTimes(1);
100
+ });
101
+ });
102
+ });
@@ -1,8 +1,9 @@
1
+ import { CreateArgs } from '../../types/Cms.js';
1
2
  type CreateFunctionPromptResponse = {
2
3
  functionsFolder: string;
3
4
  filename: string;
4
5
  endpointMethod: string;
5
6
  endpointPath: string;
6
7
  };
7
- export declare function createFunctionPrompt(): Promise<CreateFunctionPromptResponse>;
8
+ export declare function createFunctionPrompt(commandArgs?: Partial<CreateArgs>): Promise<CreateFunctionPromptResponse>;
8
9
  export {};
@@ -55,11 +55,40 @@ const ENDPOINT_PATH_PROMPT = {
55
55
  return true;
56
56
  },
57
57
  };
58
- export function createFunctionPrompt() {
59
- return promptUser([
60
- FUNCTIONS_FOLDER_PROMPT,
61
- FUNCTION_FILENAME_PROMPT,
62
- ENDPOINT_METHOD_PROMPT,
63
- ENDPOINT_PATH_PROMPT,
64
- ]);
58
+ export function createFunctionPrompt(commandArgs = {}) {
59
+ // Check if all required parameters are provided (endpointMethod has default)
60
+ const hasAllRequired = commandArgs.functionsFolder &&
61
+ commandArgs.filename &&
62
+ commandArgs.endpointPath;
63
+ if (hasAllRequired) {
64
+ return Promise.resolve({
65
+ functionsFolder: commandArgs.functionsFolder,
66
+ filename: commandArgs.filename,
67
+ endpointMethod: commandArgs.endpointMethod || 'GET',
68
+ endpointPath: commandArgs.endpointPath,
69
+ });
70
+ }
71
+ const prompts = [];
72
+ // Only prompt for missing parameters
73
+ if (!commandArgs.functionsFolder) {
74
+ prompts.push(FUNCTIONS_FOLDER_PROMPT);
75
+ }
76
+ if (!commandArgs.filename) {
77
+ prompts.push(FUNCTION_FILENAME_PROMPT);
78
+ }
79
+ if (!commandArgs.endpointMethod) {
80
+ prompts.push(ENDPOINT_METHOD_PROMPT);
81
+ }
82
+ if (!commandArgs.endpointPath) {
83
+ prompts.push(ENDPOINT_PATH_PROMPT);
84
+ }
85
+ return promptUser(prompts).then(promptResponse => {
86
+ // Merge prompted values with provided commandArgs
87
+ return {
88
+ functionsFolder: commandArgs.functionsFolder || promptResponse.functionsFolder,
89
+ filename: commandArgs.filename || promptResponse.filename,
90
+ endpointMethod: commandArgs.endpointMethod || promptResponse.endpointMethod || 'GET',
91
+ endpointPath: commandArgs.endpointPath || promptResponse.endpointPath,
92
+ };
93
+ });
65
94
  }
@@ -1,3 +1,4 @@
1
+ import { CreateArgs } from '../../types/Cms.js';
1
2
  type CreateModulePromptResponse = {
2
3
  moduleLabel: string;
3
4
  reactType: boolean;
@@ -5,5 +6,5 @@ type CreateModulePromptResponse = {
5
6
  global: boolean;
6
7
  availableForNewContent: boolean;
7
8
  };
8
- export declare function createModulePrompt(): Promise<CreateModulePromptResponse>;
9
+ export declare function createModulePrompt(commandArgs?: Partial<CreateArgs>): Promise<CreateModulePromptResponse>;
9
10
  export {};
@@ -58,7 +58,54 @@ const AVAILABLE_FOR_NEW_CONTENT = {
58
58
  message: i18n(`lib.prompts.createModulePrompt.availableForNewContent`),
59
59
  default: true,
60
60
  };
61
- export function createModulePrompt() {
61
+ export function createModulePrompt(commandArgs = {}) {
62
+ // Check if moduleLabel is provided (main requirement to skip full prompting)
63
+ // but still allow individual parameter prompting for enhanced UX
64
+ if (commandArgs.moduleLabel) {
65
+ const prompts = [];
66
+ // Only prompt for parameters not explicitly provided
67
+ if (commandArgs.reactType === undefined) {
68
+ prompts.push(REACT_TYPE_PROMPT);
69
+ }
70
+ if (!commandArgs.contentTypes) {
71
+ prompts.push(CONTENT_TYPES_PROMPT);
72
+ }
73
+ if (commandArgs.global === undefined) {
74
+ prompts.push(GLOBAL_PROMPT);
75
+ }
76
+ if (commandArgs.availableForNewContent === undefined) {
77
+ prompts.push(AVAILABLE_FOR_NEW_CONTENT);
78
+ }
79
+ // If no additional prompts needed, return with defaults
80
+ if (prompts.length === 0) {
81
+ const contentTypesArray = commandArgs.contentTypes
82
+ ? commandArgs.contentTypes.split(',').map((t) => t.trim())
83
+ : ['ANY'];
84
+ return Promise.resolve({
85
+ moduleLabel: commandArgs.moduleLabel,
86
+ reactType: commandArgs.reactType ?? false,
87
+ contentTypes: contentTypesArray,
88
+ global: commandArgs.global ?? false,
89
+ availableForNewContent: commandArgs.availableForNewContent ?? true,
90
+ });
91
+ }
92
+ // Prompt only for missing optional parameters
93
+ return promptUser(prompts).then(promptResponse => {
94
+ const contentTypesArray = commandArgs.contentTypes
95
+ ? commandArgs.contentTypes.split(',').map((t) => t.trim())
96
+ : promptResponse.contentTypes || ['ANY'];
97
+ return {
98
+ moduleLabel: commandArgs.moduleLabel,
99
+ reactType: commandArgs.reactType ?? promptResponse.reactType ?? false,
100
+ contentTypes: contentTypesArray,
101
+ global: commandArgs.global ?? promptResponse.global ?? false,
102
+ availableForNewContent: commandArgs.availableForNewContent ??
103
+ promptResponse.availableForNewContent ??
104
+ true,
105
+ };
106
+ });
107
+ }
108
+ // No moduleLabel provided, prompt for everything (original behavior)
62
109
  return promptUser([
63
110
  MODULE_LABEL_PROMPT,
64
111
  REACT_TYPE_PROMPT,
@@ -1,27 +1,6 @@
1
- declare const templateTypeChoices: [{
2
- readonly name: "page";
3
- readonly value: "page-template";
4
- }, {
5
- readonly name: "email";
6
- readonly value: "email-template";
7
- }, {
8
- readonly name: "partial";
9
- readonly value: "partial";
10
- }, {
11
- readonly name: "global partial";
12
- readonly value: "global-partial";
13
- }, {
14
- readonly name: "blog listing";
15
- readonly value: "blog-listing-template";
16
- }, {
17
- readonly name: "blog post";
18
- readonly value: "blog-post-template";
19
- }, {
20
- readonly name: "search results";
21
- readonly value: "search-template";
22
- }];
1
+ import { CreateArgs, TemplateType } from '../../types/Cms.js';
23
2
  interface CreateTemplatePromptResponse {
24
- templateType: (typeof templateTypeChoices)[number]['value'];
3
+ templateType: TemplateType;
25
4
  }
26
- export declare function createTemplatePrompt(): Promise<CreateTemplatePromptResponse>;
5
+ export declare function createTemplatePrompt(commandArgs?: Partial<CreateArgs>): Promise<CreateTemplatePromptResponse>;
27
6
  export {};
@@ -8,6 +8,7 @@ const templateTypeChoices = [
8
8
  { name: 'blog listing', value: 'blog-listing-template' },
9
9
  { name: 'blog post', value: 'blog-post-template' },
10
10
  { name: 'search results', value: 'search-template' },
11
+ { name: 'section', value: 'section' },
11
12
  ];
12
13
  const TEMPLATE_TYPE_PROMPT = {
13
14
  type: 'list',
@@ -16,6 +17,13 @@ const TEMPLATE_TYPE_PROMPT = {
16
17
  default: 'page',
17
18
  choices: templateTypeChoices,
18
19
  };
19
- export function createTemplatePrompt() {
20
+ export function createTemplatePrompt(commandArgs = {}) {
21
+ // If templateType is provided, return it directly
22
+ if (commandArgs.templateType) {
23
+ return Promise.resolve({
24
+ templateType: commandArgs.templateType,
25
+ });
26
+ }
27
+ // No templateType provided, prompt for it (original behavior)
20
28
  return promptUser([TEMPLATE_TYPE_PROMPT]);
21
29
  }
@@ -5,6 +5,8 @@ import { DeployProjectTool } from './project/DeployProjectTool.js';
5
5
  import { AddFeatureToProjectTool } from './project/AddFeatureToProjectTool.js';
6
6
  import { ValidateProjectTool } from './project/ValidateProjectTool.js';
7
7
  import { GetConfigValuesTool } from './project/GetConfigValuesTool.js';
8
+ import { DocsSearchTool } from './project/DocsSearchTool.js';
9
+ import { DocFetchTool } from './project/DocFetchTool.js';
8
10
  export function registerProjectTools(mcpServer) {
9
11
  return [
10
12
  new UploadProjectTools(mcpServer).register(),
@@ -14,5 +16,7 @@ export function registerProjectTools(mcpServer) {
14
16
  new AddFeatureToProjectTool(mcpServer).register(),
15
17
  new ValidateProjectTool(mcpServer).register(),
16
18
  new GetConfigValuesTool(mcpServer).register(),
19
+ new DocsSearchTool(mcpServer).register(),
20
+ new DocFetchTool(mcpServer).register(),
17
21
  ];
18
22
  }
@@ -0,0 +1,17 @@
1
+ import { McpServer, RegisteredTool } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import z from 'zod';
3
+ import { TextContentResponse, Tool } from '../../types.js';
4
+ declare const inputSchemaZodObject: z.ZodObject<{
5
+ docUrl: z.ZodString;
6
+ }, "strip", z.ZodTypeAny, {
7
+ docUrl: string;
8
+ }, {
9
+ docUrl: string;
10
+ }>;
11
+ type InputSchemaType = z.infer<typeof inputSchemaZodObject>;
12
+ export declare class DocFetchTool extends Tool<InputSchemaType> {
13
+ constructor(mcpServer: McpServer);
14
+ handler({ docUrl }: InputSchemaType): Promise<TextContentResponse>;
15
+ register(): RegisteredTool;
16
+ }
17
+ export {};
@@ -0,0 +1,49 @@
1
+ import z from 'zod';
2
+ import { Tool } from '../../types.js';
3
+ import { formatTextContents } from '../../utils/content.js';
4
+ import { trackToolUsage } from '../../utils/toolUsageTracking.js';
5
+ import { docUrl } from './constants.js';
6
+ import { http } from '@hubspot/local-dev-lib/http/unauthed';
7
+ import { isHubSpotHttpError } from '@hubspot/local-dev-lib/errors/index';
8
+ const inputSchema = {
9
+ docUrl,
10
+ };
11
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
12
+ const inputSchemaZodObject = z.object({
13
+ ...inputSchema,
14
+ });
15
+ const toolName = 'fetch-hubspot-doc';
16
+ export class DocFetchTool extends Tool {
17
+ constructor(mcpServer) {
18
+ super(mcpServer);
19
+ }
20
+ async handler({ docUrl }) {
21
+ await trackToolUsage(toolName);
22
+ try {
23
+ // Append .md extension to the URL
24
+ const markdownUrl = `${docUrl}.md`;
25
+ const response = await http.get({
26
+ url: markdownUrl,
27
+ });
28
+ const content = response.data;
29
+ if (!content || content.trim().length === 0) {
30
+ return formatTextContents('Document is empty or contains no content.');
31
+ }
32
+ return formatTextContents(content);
33
+ }
34
+ catch (error) {
35
+ if (isHubSpotHttpError(error)) {
36
+ return formatTextContents(error.toString());
37
+ }
38
+ const errorMessage = `Error fetching documentation: ${error instanceof Error ? error.message : String(error)}`;
39
+ return formatTextContents(errorMessage);
40
+ }
41
+ }
42
+ register() {
43
+ return this.mcpServer.registerTool(toolName, {
44
+ title: 'Fetch a single HubSpot Developer Documentation file',
45
+ description: 'Fetch a single HubSpot Developer Documentation file by URL. Call after search-hubspot-docs.',
46
+ inputSchema,
47
+ }, this.handler);
48
+ }
49
+ }
@@ -0,0 +1,26 @@
1
+ import { McpServer, RegisteredTool } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import z from 'zod';
3
+ import { TextContentResponse, Tool } from '../../types.js';
4
+ declare const inputSchemaZodObject: z.ZodObject<{
5
+ docsSearchQuery: z.ZodString;
6
+ }, "strip", z.ZodTypeAny, {
7
+ docsSearchQuery: string;
8
+ }, {
9
+ docsSearchQuery: string;
10
+ }>;
11
+ export interface DocsSearchResponse {
12
+ results: {
13
+ title: string;
14
+ content: string;
15
+ description: string;
16
+ url: string;
17
+ score: number;
18
+ }[];
19
+ }
20
+ type InputSchemaType = z.infer<typeof inputSchemaZodObject>;
21
+ export declare class DocsSearchTool extends Tool<InputSchemaType> {
22
+ constructor(mcpServer: McpServer);
23
+ handler({ docsSearchQuery, }: InputSchemaType): Promise<TextContentResponse>;
24
+ register(): RegisteredTool;
25
+ }
26
+ export {};
@@ -0,0 +1,62 @@
1
+ import { http } from '@hubspot/local-dev-lib/http';
2
+ import z from 'zod';
3
+ import { Tool } from '../../types.js';
4
+ import { formatTextContents } from '../../utils/content.js';
5
+ import { trackToolUsage } from '../../utils/toolUsageTracking.js';
6
+ import { docsSearchQuery } from './constants.js';
7
+ import { getAccountId, getConfigPath, loadConfig, } from '@hubspot/local-dev-lib/config';
8
+ import { isHubSpotHttpError } from '@hubspot/local-dev-lib/errors/index';
9
+ const inputSchema = {
10
+ docsSearchQuery,
11
+ };
12
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
13
+ const inputSchemaZodObject = z.object({
14
+ ...inputSchema,
15
+ });
16
+ const toolName = 'search-hubspot-docs';
17
+ export class DocsSearchTool extends Tool {
18
+ constructor(mcpServer) {
19
+ super(mcpServer);
20
+ }
21
+ async handler({ docsSearchQuery, }) {
22
+ await trackToolUsage(toolName, { mode: docsSearchQuery });
23
+ loadConfig(getConfigPath());
24
+ const accountId = getAccountId();
25
+ if (!accountId) {
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
+ return formatTextContents(authErrorMessage);
28
+ }
29
+ try {
30
+ const response = await http.post(accountId, {
31
+ url: 'dev/docs/llms/v1/docs-search',
32
+ data: {
33
+ query: docsSearchQuery,
34
+ },
35
+ });
36
+ const results = response.data.results;
37
+ if (!results || results.length === 0) {
38
+ return formatTextContents('No documentation found for your query.');
39
+ }
40
+ const formattedResults = results
41
+ .map(result => `**${result.title}**\n${result.description}\nURL: ${result.url}\nScore: ${result.score}\n\n${result.content}\n---\n`)
42
+ .join('\n');
43
+ const successMessage = `Found ${results.length} documentation results:\n\n${formattedResults}`;
44
+ return formatTextContents(successMessage);
45
+ }
46
+ catch (error) {
47
+ if (isHubSpotHttpError(error)) {
48
+ // Handle different status codes
49
+ return formatTextContents(error.toString());
50
+ }
51
+ const errorMessage = `Error searching documentation: ${error instanceof Error ? error.message : String(error)}`;
52
+ return formatTextContents(errorMessage);
53
+ }
54
+ }
55
+ register() {
56
+ return this.mcpServer.registerTool(toolName, {
57
+ title: 'Search the HubSpot docs',
58
+ description: 'Search the HubSpot docs for information. This will return results that include a url to be used in fetch-hubspot-doc.',
59
+ inputSchema,
60
+ }, this.handler);
61
+ }
62
+ }