@salesforce/b2c-dx-mcp 0.4.6 → 0.4.8

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.
@@ -14,6 +14,9 @@ import { z } from 'zod';
14
14
  import { createToolAdapter, jsonResult } from '../adapter.js';
15
15
  import { findAndDeployCartridges, getActiveCodeVersion } from '@salesforce/b2c-tooling-sdk/operations/code';
16
16
  import { getLogger } from '@salesforce/b2c-tooling-sdk/logging';
17
+ /** Reminder shown after deploy so users add cartridges to the site cartridge path. */
18
+ const CARTRIDGE_PATH_REMINDER = "If this is a new or updated cartridge, add it to your site's cartridge path in Business Manager: " +
19
+ 'Sites → Manage Sites → [your site] → Settings tab → Cartridges field.';
17
20
  /**
18
21
  * Creates the cartridge_deploy tool.
19
22
  *
@@ -36,7 +39,8 @@ function createCartridgeDeployTool(loadServices, injections) {
36
39
  'Searches the directory for cartridges (by .project files), applies include/exclude filters, ' +
37
40
  'creates a zip archive, uploads via WebDAV, and optionally reloads the code version. ' +
38
41
  'Use this tool to deploy custom code cartridges for SFRA or other B2C Commerce code. ' +
39
- 'Requires the instance to have a code version configured.',
42
+ 'Requires the instance to have a code version configured. ' +
43
+ "After deploy, add new cartridges to your site's cartridge path in Business Manager: Sites → Manage Sites → [site] → Settings tab → Cartridges.",
40
44
  toolsets: ['CARTRIDGES'],
41
45
  isGA: false,
42
46
  requiresInstance: true,
@@ -100,7 +104,10 @@ function createCartridgeDeployTool(loadServices, injections) {
100
104
  }, '[Cartridges] Deploying cartridges with computed options');
101
105
  // Deploy cartridges
102
106
  const result = await findAndDeployCartridgesFn(instance, directory, options);
103
- return result;
107
+ return {
108
+ ...result,
109
+ postInstructions: CARTRIDGE_PATH_REMINDER,
110
+ };
104
111
  }
105
112
  catch (error) {
106
113
  // Handle communication and authentication errors
@@ -2,12 +2,17 @@ import type { McpTool } from '../../utils/index.js';
2
2
  import type { Services } from '../../services.js';
3
3
  import type { PushResult, PushOptions } from '@salesforce/b2c-tooling-sdk/operations/mrt';
4
4
  import type { AuthStrategy } from '@salesforce/b2c-tooling-sdk/auth';
5
+ import { type ProjectType } from '@salesforce/b2c-tooling-sdk/discovery';
5
6
  /**
6
7
  * Optional dependency injections for testing.
7
8
  */
8
9
  interface MrtToolInjections {
9
10
  /** Mock pushBundle function for testing */
10
11
  pushBundle?: (options: PushOptions, auth: AuthStrategy) => Promise<PushResult>;
12
+ /** Mock detectWorkspaceType function for testing */
13
+ detectWorkspaceType?: (path: string) => Promise<{
14
+ projectTypes: ProjectType[];
15
+ }>;
11
16
  }
12
17
  /**
13
18
  * Creates all tools for the MRT toolset.
@@ -13,7 +13,98 @@
13
13
  import { z } from 'zod';
14
14
  import { createToolAdapter, jsonResult } from '../adapter.js';
15
15
  import { pushBundle } from '@salesforce/b2c-tooling-sdk/operations/mrt';
16
+ import { detectWorkspaceType } from '@salesforce/b2c-tooling-sdk/discovery';
16
17
  import { getLogger } from '@salesforce/b2c-tooling-sdk/logging';
18
+ /**
19
+ * Parses a glob pattern string into an array of patterns.
20
+ * Accepts either a JSON array (e.g. '["server/**\/*", "ssr.{js,mjs}"]')
21
+ * or a comma-separated string (e.g. 'server/**\/*,ssr.js').
22
+ * JSON array format supports brace expansion in individual patterns.
23
+ */
24
+ function parseGlobPatterns(value) {
25
+ const trimmed = value.trim();
26
+ if (trimmed.startsWith('[')) {
27
+ const parsed = JSON.parse(trimmed);
28
+ if (!Array.isArray(parsed) || !parsed.every((item) => typeof item === 'string')) {
29
+ throw new Error('Invalid glob pattern array: expected an array of strings');
30
+ }
31
+ return parsed.map((s) => s.trim()).filter(Boolean);
32
+ }
33
+ return trimmed
34
+ .split(',')
35
+ .map((s) => s.trim())
36
+ .filter(Boolean);
37
+ }
38
+ const MRT_DEFAULTS = {
39
+ 'storefront-next': {
40
+ // ssrEntryPoint is 'streamingHandler' (production + MRT_BUNDLE_TYPE!=='ssr') or 'ssr' otherwise.
41
+ // Include both patterns so the bundle works regardless of MRT_BUNDLE_TYPE / mode.
42
+ ssrOnly: [
43
+ 'server/**/*',
44
+ 'loader.js',
45
+ 'streamingHandler.{js,mjs,cjs}',
46
+ 'streamingHandler.{js,mjs,cjs}.map',
47
+ 'ssr.{js,mjs,cjs}',
48
+ 'ssr.{js,mjs,cjs}.map',
49
+ '!static/**/*',
50
+ 'sfnext-server-*.mjs',
51
+ '!**/*.stories.tsx',
52
+ '!**/*.stories.ts',
53
+ '!**/*-snapshot.tsx',
54
+ '!.storybook/**/*',
55
+ '!storybook-static/**/*',
56
+ '!**/__mocks__/**/*',
57
+ '!**/__snapshots__/**/*',
58
+ ],
59
+ ssrShared: [
60
+ 'client/**/*',
61
+ 'static/**/*',
62
+ '**/*.css',
63
+ '**/*.png',
64
+ '**/*.jpg',
65
+ '**/*.jpeg',
66
+ '**/*.gif',
67
+ '**/*.svg',
68
+ '**/*.ico',
69
+ '**/*.woff',
70
+ '**/*.woff2',
71
+ '**/*.ttf',
72
+ '**/*.eot',
73
+ '!**/*.stories.tsx',
74
+ '!**/*.stories.ts',
75
+ '!**/*-snapshot.tsx',
76
+ '!.storybook/**/*',
77
+ '!storybook-static/**/*',
78
+ '!**/__mocks__/**/*',
79
+ '!**/__snapshots__/**/*',
80
+ ],
81
+ buildDirectory: 'build',
82
+ },
83
+ 'pwa-kit-v3': {
84
+ ssrOnly: ['ssr.js', 'ssr.js.map', 'node_modules/**/*.*'],
85
+ ssrShared: ['static/ico/favicon.ico', 'static/robots.txt', '**/*.js', '**/*.js.map', '**/*.json'],
86
+ buildDirectory: 'build',
87
+ },
88
+ default: {
89
+ ssrOnly: ['ssr.js', 'ssr.mjs', 'server/**/*'],
90
+ ssrShared: ['static/**/*', 'client/**/*'],
91
+ buildDirectory: 'build',
92
+ },
93
+ };
94
+ /**
95
+ * Returns MRT bundle defaults for the given project types.
96
+ * For hybrid projects (multiple types detected), prefers storefront-next over pwa-kit-v3.
97
+ *
98
+ * @param projectTypes - Detected project types from workspace discovery
99
+ * @returns Defaults for ssrOnly, ssrShared, and buildDirectory
100
+ */
101
+ function getDefaultsForProjectTypes(projectTypes) {
102
+ if (projectTypes.includes('storefront-next'))
103
+ return MRT_DEFAULTS['storefront-next'];
104
+ if (projectTypes.includes('pwa-kit-v3'))
105
+ return MRT_DEFAULTS['pwa-kit-v3'];
106
+ return MRT_DEFAULTS.default;
107
+ }
17
108
  /**
18
109
  * Creates the mrt_bundle_push tool.
19
110
  *
@@ -28,6 +119,7 @@ import { getLogger } from '@salesforce/b2c-tooling-sdk/logging';
28
119
  */
29
120
  function createMrtBundlePushTool(loadServices, injections) {
30
121
  const pushBundleFn = injections?.pushBundle || pushBundle;
122
+ const detectWorkspaceTypeFn = injections?.detectWorkspaceType ?? detectWorkspaceType;
31
123
  return createToolAdapter({
32
124
  name: 'mrt_bundle_push',
33
125
  description: 'Bundle a pre-built PWA Kit or Storefront Next project and push to Managed Runtime. Optionally deploy to a target environment.',
@@ -36,16 +128,19 @@ function createMrtBundlePushTool(loadServices, injections) {
36
128
  // MRT operations use ApiKeyStrategy from MRT_API_KEY or ~/.mobify
37
129
  requiresMrtAuth: true,
38
130
  inputSchema: {
39
- buildDirectory: z.string().optional().describe('Path to build directory (default: ./build)'),
131
+ buildDirectory: z
132
+ .string()
133
+ .optional()
134
+ .describe('Path to build directory. Defaults vary by project type: Storefront Next, PWA Kit v3, or generic (./build).'),
40
135
  message: z.string().optional().describe('Deployment message'),
41
136
  ssrOnly: z
42
137
  .string()
43
138
  .optional()
44
- .describe('Glob patterns for server-only files, comma-separated (default: ssr.js,ssr.mjs,server/**/*)'),
139
+ .describe('Glob patterns for server-only files (comma-separated or JSON array). Defaults vary by project type: Storefront Next, PWA Kit v3, or generic.'),
45
140
  ssrShared: z
46
141
  .string()
47
142
  .optional()
48
- .describe('Glob patterns for shared files, comma-separated (default: static/**/*,client/**/*)'),
143
+ .describe('Glob patterns for shared files (comma-separated or JSON array). Defaults vary by project type: Storefront Next, PWA Kit v3, or generic.'),
49
144
  deploy: z
50
145
  .boolean()
51
146
  .optional()
@@ -71,10 +166,13 @@ function createMrtBundlePushTool(loadServices, injections) {
71
166
  }
72
167
  // Get origin from --cloud-origin flag or mrtOrigin config (optional)
73
168
  const origin = context.mrtConfig?.origin;
74
- // Parse comma-separated glob patterns (same as CLI defaults)
75
- const ssrOnly = (args.ssrOnly || 'ssr.js,ssr.mjs,server/**/*').split(',').map((s) => s.trim());
76
- const ssrShared = (args.ssrShared || 'static/**/*,client/**/*').split(',').map((s) => s.trim());
77
- const buildDirectory = context.services.resolveWithProjectDirectory(args.buildDirectory || 'build');
169
+ // Detect project type and get project-type-aware defaults
170
+ const projectDir = context.services.resolveWithProjectDirectory();
171
+ const { projectTypes } = await detectWorkspaceTypeFn(projectDir);
172
+ const defaults = getDefaultsForProjectTypes(projectTypes);
173
+ const ssrOnly = args.ssrOnly ? parseGlobPatterns(args.ssrOnly) : defaults.ssrOnly;
174
+ const ssrShared = args.ssrShared ? parseGlobPatterns(args.ssrShared) : defaults.ssrShared;
175
+ const buildDirectory = context.services.resolveWithProjectDirectory(args.buildDirectory ?? defaults.buildDirectory);
78
176
  // Log all computed variables before pushing bundle
79
177
  const logger = getLogger();
80
178
  logger.debug({
@@ -83,6 +181,7 @@ function createMrtBundlePushTool(loadServices, injections) {
83
181
  origin,
84
182
  buildDirectory,
85
183
  message: args.message,
184
+ projectTypes,
86
185
  ssrOnly,
87
186
  ssrShared,
88
187
  }, '[MRT] Pushing bundle with computed options');
@@ -390,5 +390,5 @@
390
390
  "enableJsonFlag": false
391
391
  }
392
392
  },
393
- "version": "0.4.6"
393
+ "version": "0.4.8"
394
394
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@salesforce/b2c-dx-mcp",
3
3
  "description": "MCP server for B2C Commerce developer experience tools",
4
- "version": "0.4.6",
4
+ "version": "0.4.8",
5
5
  "author": "Salesforce",
6
6
  "license": "Apache-2.0",
7
7
  "repository": "SalesforceCommerceCloud/b2c-developer-tooling",
@@ -80,7 +80,7 @@
80
80
  "yaml": "2.8.1",
81
81
  "postcss": "8.5.6",
82
82
  "zod": "3.25.76",
83
- "@salesforce/b2c-tooling-sdk": "0.5.5"
83
+ "@salesforce/b2c-tooling-sdk": "0.7.0"
84
84
  },
85
85
  "devDependencies": {
86
86
  "@eslint/compat": "^1",