Skip to content

Commit bc49943

Browse files
@W-21386533 MCP MRT Push now uses correct defaults based on detected project type
1 parent cf79e4d commit bc49943

File tree

4 files changed

+364
-26
lines changed

4 files changed

+364
-26
lines changed

.changeset/early-clubs-eat.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@salesforce/b2c-dx-mcp': patch
3+
'@salesforce/b2c-dx-docs': patch
4+
---
5+
6+
MCP MRT Push now uses correct defaults based on detected project type

docs/mcp/tools/mrt-bundle-push.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,38 @@ Requires Managed Runtime (MRT) credentials. See [MRT Credentials](../configurati
3030

3131
## Parameters
3232

33+
Defaults for `buildDirectory`, `ssrOnly`, and `ssrShared` are chosen by detected project type (Storefront Next, PWA Kit v3, or generic). Explicit parameters override the project-type defaults.
34+
3335
| Parameter | Type | Required | Default | Description |
3436
|-----------|------|----------|---------|-------------|
3537
| `buildDirectory` | string | No | `./build` | Path to build directory containing the built project files. Can be absolute or relative to the project directory. |
3638
| `message` | string | No | None | Deployment message to include with the bundle push. Useful for tracking deployments. |
37-
| `ssrOnly` | string | No | `ssr.js,ssr.mjs,server/**/*` | Comma-separated glob patterns for server-only files (SSR). These files are only included in the server bundle. |
38-
| `ssrShared` | string | No | `static/**/*,client/**/*` | Comma-separated glob patterns for shared files. These files are included in both server and client bundles. |
39+
| `ssrOnly` | string | No | Varies by project type | Glob patterns for server-only files (SSR), comma-separated or JSON array. These files are only included in the server bundle. |
40+
| `ssrShared` | string | No | Varies by project type | Glob patterns for shared files, comma-separated or JSON array. These files are included in both server and client bundles. |
3941
| `deploy` | boolean | No | `false` | Whether to deploy to an environment after push. When `true`, `environment` must be provided via `--environment` flag or `SFCC_MRT_ENVIRONMENT`. |
4042

43+
### Default values by project type
44+
45+
When `buildDirectory`, `ssrOnly`, or `ssrShared` are omitted, the tool detects the project type and applies these defaults:
46+
47+
**Generic** (used when no project type is detected; matches CLI `b2c mrt bundle deploy` defaults):
48+
49+
- `buildDirectory`: `./build`
50+
- `ssrOnly`: `ssr.js`, `ssr.mjs`, `server/**/*`
51+
- `ssrShared`: `static/**/*`, `client/**/*`
52+
53+
**PWA Kit v3**:
54+
55+
- `buildDirectory`: `./build`
56+
- `ssrOnly`: `ssr.js`, `ssr.js.map`, `node_modules/**/*.*`
57+
- `ssrShared`: `static/ico/favicon.ico`, `static/robots.txt`, `**/*.js`, `**/*.js.map`, `**/*.json`
58+
59+
**Storefront Next**:
60+
61+
- `buildDirectory`: `./build`
62+
- `ssrOnly`: `server/**/*`, `loader.js`, `streamingHandler.{js,mjs,cjs}`, `streamingHandler.{js,mjs,cjs}.map`, `ssr.{js,mjs,cjs}`, `ssr.{js,mjs,cjs}.map`, `!static/**/*`, `sfnext-server-*.mjs`, plus exclusions for Storybook and test files
63+
- `ssrShared`: `client/**/*`, `static/**/*`, `**/*.css`, image/font extensions, plus exclusions for Storybook and test files
64+
4165
## Usage Examples
4266

4367
### Push Bundle Only

packages/b2c-dx-mcp/src/tools/mrt/index.ts

Lines changed: 124 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,106 @@ import {createToolAdapter, jsonResult} from '../adapter.js';
1919
import {pushBundle} from '@salesforce/b2c-tooling-sdk/operations/mrt';
2020
import type {PushResult, PushOptions} from '@salesforce/b2c-tooling-sdk/operations/mrt';
2121
import type {AuthStrategy} from '@salesforce/b2c-tooling-sdk/auth';
22+
import {detectWorkspaceType, type ProjectType} from '@salesforce/b2c-tooling-sdk/discovery';
2223
import {getLogger} from '@salesforce/b2c-tooling-sdk/logging';
2324

25+
/**
26+
* Parses a glob pattern string into an array of patterns.
27+
* Accepts either a JSON array (e.g. '["server/**\/*", "ssr.{js,mjs}"]')
28+
* or a comma-separated string (e.g. 'server/**\/*,ssr.js').
29+
* JSON array format supports brace expansion in individual patterns.
30+
*/
31+
function parseGlobPatterns(value: string): string[] {
32+
const trimmed = value.trim();
33+
if (trimmed.startsWith('[')) {
34+
const parsed: unknown = JSON.parse(trimmed);
35+
if (!Array.isArray(parsed) || !parsed.every((item) => typeof item === 'string')) {
36+
throw new Error('Invalid glob pattern array: expected an array of strings');
37+
}
38+
return parsed.map((s: string) => (s as string).trim()).filter(Boolean);
39+
}
40+
return trimmed
41+
.split(',')
42+
.map((s) => s.trim())
43+
.filter(Boolean);
44+
}
45+
46+
interface MrtDefaults {
47+
ssrOnly: string[];
48+
ssrShared: string[];
49+
buildDirectory: string;
50+
}
51+
52+
const MRT_DEFAULTS: Record<'default' | 'pwa-kit-v3' | 'storefront-next', MrtDefaults> = {
53+
'storefront-next': {
54+
// ssrEntryPoint is 'streamingHandler' (production + MRT_BUNDLE_TYPE!=='ssr') or 'ssr' otherwise.
55+
// Include both patterns so the bundle works regardless of MRT_BUNDLE_TYPE / mode.
56+
ssrOnly: [
57+
'server/**/*',
58+
'loader.js',
59+
'streamingHandler.{js,mjs,cjs}',
60+
'streamingHandler.{js,mjs,cjs}.map',
61+
'ssr.{js,mjs,cjs}',
62+
'ssr.{js,mjs,cjs}.map',
63+
'!static/**/*',
64+
'sfnext-server-*.mjs',
65+
'!**/*.stories.tsx',
66+
'!**/*.stories.ts',
67+
'!**/*-snapshot.tsx',
68+
'!.storybook/**/*',
69+
'!storybook-static/**/*',
70+
'!**/__mocks__/**/*',
71+
'!**/__snapshots__/**/*',
72+
],
73+
ssrShared: [
74+
'client/**/*',
75+
'static/**/*',
76+
'**/*.css',
77+
'**/*.png',
78+
'**/*.jpg',
79+
'**/*.jpeg',
80+
'**/*.gif',
81+
'**/*.svg',
82+
'**/*.ico',
83+
'**/*.woff',
84+
'**/*.woff2',
85+
'**/*.ttf',
86+
'**/*.eot',
87+
'!**/*.stories.tsx',
88+
'!**/*.stories.ts',
89+
'!**/*-snapshot.tsx',
90+
'!.storybook/**/*',
91+
'!storybook-static/**/*',
92+
'!**/__mocks__/**/*',
93+
'!**/__snapshots__/**/*',
94+
],
95+
buildDirectory: 'build',
96+
},
97+
'pwa-kit-v3': {
98+
ssrOnly: ['ssr.js', 'ssr.js.map', 'node_modules/**/*.*'],
99+
ssrShared: ['static/ico/favicon.ico', 'static/robots.txt', '**/*.js', '**/*.js.map', '**/*.json'],
100+
buildDirectory: 'build',
101+
},
102+
default: {
103+
ssrOnly: ['ssr.js', 'ssr.mjs', 'server/**/*'],
104+
ssrShared: ['static/**/*', 'client/**/*'],
105+
buildDirectory: 'build',
106+
},
107+
};
108+
109+
/**
110+
* Returns MRT bundle defaults for the given project types.
111+
* For hybrid projects (multiple types detected), prefers storefront-next over pwa-kit-v3.
112+
*
113+
* @param projectTypes - Detected project types from workspace discovery
114+
* @returns Defaults for ssrOnly, ssrShared, and buildDirectory
115+
*/
116+
function getDefaultsForProjectTypes(projectTypes: ProjectType[]): MrtDefaults {
117+
if (projectTypes.includes('storefront-next')) return MRT_DEFAULTS['storefront-next'];
118+
if (projectTypes.includes('pwa-kit-v3')) return MRT_DEFAULTS['pwa-kit-v3'];
119+
return MRT_DEFAULTS.default;
120+
}
121+
24122
/**
25123
* Input type for mrt_bundle_push tool.
26124
*/
@@ -43,6 +141,8 @@ interface MrtBundlePushInput {
43141
interface MrtToolInjections {
44142
/** Mock pushBundle function for testing */
45143
pushBundle?: (options: PushOptions, auth: AuthStrategy) => Promise<PushResult>;
144+
/** Mock detectWorkspaceType function for testing */
145+
detectWorkspaceType?: (path: string) => Promise<{projectTypes: ProjectType[]}>;
46146
}
47147

48148
/**
@@ -59,6 +159,7 @@ interface MrtToolInjections {
59159
*/
60160
function createMrtBundlePushTool(loadServices: () => Services, injections?: MrtToolInjections): McpTool {
61161
const pushBundleFn = injections?.pushBundle || pushBundle;
162+
const detectWorkspaceTypeFn = injections?.detectWorkspaceType ?? detectWorkspaceType;
62163
return createToolAdapter<MrtBundlePushInput, PushResult>(
63164
{
64165
name: 'mrt_bundle_push',
@@ -69,16 +170,25 @@ function createMrtBundlePushTool(loadServices: () => Services, injections?: MrtT
69170
// MRT operations use ApiKeyStrategy from SFCC_MRT_API_KEY or ~/.mobify
70171
requiresMrtAuth: true,
71172
inputSchema: {
72-
buildDirectory: z.string().optional().describe('Path to build directory (default: ./build)'),
173+
buildDirectory: z
174+
.string()
175+
.optional()
176+
.describe(
177+
'Path to build directory. Defaults vary by project type: Storefront Next, PWA Kit v3, or generic (./build).',
178+
),
73179
message: z.string().optional().describe('Deployment message'),
74180
ssrOnly: z
75181
.string()
76182
.optional()
77-
.describe('Glob patterns for server-only files, comma-separated (default: ssr.js,ssr.mjs,server/**/*)'),
183+
.describe(
184+
'Glob patterns for server-only files (comma-separated or JSON array). Defaults vary by project type: Storefront Next, PWA Kit v3, or generic.',
185+
),
78186
ssrShared: z
79187
.string()
80188
.optional()
81-
.describe('Glob patterns for shared files, comma-separated (default: static/**/*,client/**/*)'),
189+
.describe(
190+
'Glob patterns for shared files (comma-separated or JSON array). Defaults vary by project type: Storefront Next, PWA Kit v3, or generic.',
191+
),
82192
deploy: z
83193
.boolean()
84194
.optional()
@@ -111,10 +221,16 @@ function createMrtBundlePushTool(loadServices: () => Services, injections?: MrtT
111221
// Get origin from --cloud-origin flag or mrtOrigin config (optional)
112222
const origin = context.mrtConfig?.origin;
113223

114-
// Parse comma-separated glob patterns (same as CLI defaults)
115-
const ssrOnly = (args.ssrOnly || 'ssr.js,ssr.mjs,server/**/*').split(',').map((s) => s.trim());
116-
const ssrShared = (args.ssrShared || 'static/**/*,client/**/*').split(',').map((s) => s.trim());
117-
const buildDirectory = context.services.resolveWithProjectDirectory(args.buildDirectory || 'build');
224+
// Detect project type and get project-type-aware defaults
225+
const projectDir = context.services.resolveWithProjectDirectory();
226+
const {projectTypes} = await detectWorkspaceTypeFn(projectDir);
227+
const defaults = getDefaultsForProjectTypes(projectTypes);
228+
229+
const ssrOnly = args.ssrOnly ? parseGlobPatterns(args.ssrOnly) : defaults.ssrOnly;
230+
const ssrShared = args.ssrShared ? parseGlobPatterns(args.ssrShared) : defaults.ssrShared;
231+
const buildDirectory = context.services.resolveWithProjectDirectory(
232+
args.buildDirectory ?? defaults.buildDirectory,
233+
);
118234

119235
// Log all computed variables before pushing bundle
120236
const logger = getLogger();
@@ -125,6 +241,7 @@ function createMrtBundlePushTool(loadServices: () => Services, injections?: MrtT
125241
origin,
126242
buildDirectory,
127243
message: args.message,
244+
projectTypes,
128245
ssrOnly,
129246
ssrShared,
130247
},

0 commit comments

Comments
 (0)