99 *
1010 * This toolset provides MCP tools for Managed Runtime operations.
1111 *
12- * > ⚠️ **PLACEHOLDER - ACTIVE DEVELOPMENT**
13- * > This tool is a placeholder implementation that returns mock responses.
14- * > Actual implementation is coming soon. Use `--allow-non-ga-tools` flag to enable.
15- *
1612 * @module tools/mrt
1713 */
1814
1915import { z } from 'zod' ;
2016import type { McpTool } from '../../utils/index.js' ;
2117import type { Services } from '../../services.js' ;
2218import { createToolAdapter , jsonResult } from '../adapter.js' ;
19+ import { pushBundle } from '@salesforce/b2c-tooling-sdk/operations/mrt' ;
20+ import type { PushResult , PushOptions } from '@salesforce/b2c-tooling-sdk/operations/mrt' ;
21+ import type { AuthStrategy } from '@salesforce/b2c-tooling-sdk/auth' ;
2322import { getLogger } from '@salesforce/b2c-tooling-sdk/logging' ;
2423
2524/**
@@ -37,14 +36,11 @@ interface MrtBundlePushInput {
3736}
3837
3938/**
40- * Output type for mrt_bundle_push tool .
39+ * Optional dependency injections for testing .
4140 */
42- interface MrtBundlePushOutput {
43- tool : string ;
44- status : string ;
45- message : string ;
46- input : MrtBundlePushInput ;
47- timestamp : string ;
41+ interface MrtToolInjections {
42+ /** Mock pushBundle function for testing */
43+ pushBundle ?: ( options : PushOptions , auth : AuthStrategy ) => Promise < PushResult > ;
4844}
4945
5046/**
@@ -56,14 +52,16 @@ interface MrtBundlePushOutput {
5652 * Shared across MRT, PWAV3, and STOREFRONTNEXT toolsets.
5753 *
5854 * @param services - MCP services
55+ * @param injections - Optional dependency injections for testing
5956 * @returns The mrt_bundle_push tool
6057 */
61- function createMrtBundlePushTool ( services : Services ) : McpTool {
62- return createToolAdapter < MrtBundlePushInput , MrtBundlePushOutput > (
58+ function createMrtBundlePushTool ( services : Services , injections ?: MrtToolInjections ) : McpTool {
59+ const pushBundleFn = injections ?. pushBundle || pushBundle ;
60+ return createToolAdapter < MrtBundlePushInput , PushResult > (
6361 {
6462 name : 'mrt_bundle_push' ,
6563 description :
66- '[PLACEHOLDER] Bundle a pre-built PWA Kit project and push to Managed Runtime. Optionally deploy to a target environment.' ,
64+ 'Bundle a pre-built PWA Kit project and push to Managed Runtime. Optionally deploy to a target environment.' ,
6765 toolsets : [ 'MRT' , 'PWAV3' , 'STOREFRONTNEXT' ] ,
6866 isGA : false ,
6967 // MRT operations use ApiKeyStrategy from SFCC_MRT_API_KEY or ~/.mobify
@@ -92,39 +90,45 @@ function createMrtBundlePushTool(services: Services): McpTool {
9290 // Get environment from --environment flag (optional)
9391 const environment = context . mrtConfig ?. environment ;
9492
95- // Placeholder implementation
96- const timestamp = new Date ( ) . toISOString ( ) ;
93+ // Get origin from --cloud-origin flag or mrtOrigin config (optional)
94+ const origin = context . mrtConfig ?. origin ;
95+
96+ // Parse comma-separated glob patterns (same as CLI defaults)
97+ const ssrOnly = ( args . ssrOnly || 'ssr.js,ssr.mjs,server/**/*' ) . split ( ',' ) . map ( ( s ) => s . trim ( ) ) ;
98+ const ssrShared = ( args . ssrShared || 'static/**/*,client/**/*' ) . split ( ',' ) . map ( ( s ) => s . trim ( ) ) ;
99+ const buildDirectory = args . buildDirectory || './build' ;
97100
98- // TODO: Remove this log when implementing
101+ // Log all computed variables before pushing bundle
99102 const logger = getLogger ( ) ;
100- logger . debug ( { mrtConfig : context . mrtConfig , project, environment} , 'mrt_bundle_push context' ) ;
103+ logger . debug (
104+ {
105+ project,
106+ environment,
107+ origin,
108+ buildDirectory,
109+ message : args . message ,
110+ ssrOnly,
111+ ssrShared,
112+ } ,
113+ '[MRT] Pushing bundle with computed options' ,
114+ ) ;
101115
102- // TODO: When implementing, use context.mrtConfig.auth:
103- //
104- // import { pushBundle } from '@salesforce/b2c-tooling-sdk/operations/mrt';
105- //
106- // // Parse comma-separated glob patterns (same as CLI defaults)
107- // const ssrOnly = (args.ssrOnly || 'ssr.js,ssr.mjs,server/**/*').split(',').map(s => s.trim());
108- // const ssrShared = (args.ssrShared || 'static/**/*,client/**/*').split(',').map(s => s.trim());
109- //
110- // const result = await pushBundle({
111- // project,
112- // buildDirectory: args.buildDirectory || './build',
113- // ssrOnly, // files that run only on SSR server (never sent to browser)
114- // ssrShared, // files served from CDN and also available to SSR
115- // message: args.message,
116- // environment,
117- // }, context.mrtConfig!.auth);
118- // return result;
116+ // Push bundle to MRT
117+ // Note: auth is guaranteed to be present by the adapter when requiresMrtAuth is true
118+ const result = await pushBundleFn (
119+ {
120+ projectSlug : project ,
121+ buildDirectory,
122+ ssrOnly, // files that run only on SSR server (never sent to browser)
123+ ssrShared, // files served from CDN and also available to SSR
124+ message : args . message ,
125+ target : environment ,
126+ origin, // MRT API origin URL (optional, defaults to https://cloud.mobify.com)
127+ } ,
128+ context . mrtConfig ! . auth ! ,
129+ ) ;
119130
120- return {
121- tool : 'mrt_bundle_push' ,
122- status : 'placeholder' ,
123- message :
124- "This is a placeholder implementation for 'mrt_bundle_push'. The actual implementation is coming soon." ,
125- input : { ...args , project, environment} ,
126- timestamp,
127- } ;
131+ return result ;
128132 } ,
129133 formatOutput : ( output ) => jsonResult ( output ) ,
130134 } ,
@@ -136,8 +140,9 @@ function createMrtBundlePushTool(services: Services): McpTool {
136140 * Creates all tools for the MRT toolset.
137141 *
138142 * @param services - MCP services
143+ * @param injections - Optional dependency injections for testing
139144 * @returns Array of MCP tools
140145 */
141- export function createMrtTools ( services : Services ) : McpTool [ ] {
142- return [ createMrtBundlePushTool ( services ) ] ;
146+ export function createMrtTools ( services : Services , injections ?: MrtToolInjections ) : McpTool [ ] {
147+ return [ createMrtBundlePushTool ( services , injections ) ] ;
143148}
0 commit comments