2323 *
2424 * ## Flags
2525 *
26+ * ### MCP-Specific Flags
2627 * | Flag | Short | Description |
2728 * |------|-------|-------------|
2829 * | `--toolsets` | `-s` | Comma-separated toolsets to enable (case-insensitive) |
2930 * | `--tools` | `-t` | Comma-separated individual tools to enable (case-insensitive) |
3031 * | `--allow-non-ga-tools` | | Enable experimental/non-GA tools |
31- * | `--dw-json` | | Path to dw.json (optional, auto-discovered if not provided) |
32+ *
33+ * ### Global Flags (inherited from BaseCommand)
34+ * | Flag | Short | Description |
35+ * |------|-------|-------------|
36+ * | `--config` | | Path to dw.json config file (auto-discovered if not provided) |
37+ * | `--instance` | `-i` | Instance name from configuration file |
38+ * | `--log-level` | | Set logging verbosity (trace, debug, info, warn, error, silent) |
39+ * | `--debug` | `-D` | Enable debug logging |
40+ * | `--json` | | Output logs as JSON lines |
41+ * | `--lang` | `-L` | Language for messages |
3242 *
3343 * ## Configuration Priority
3444 *
3545 * 1. Environment variables (SFCC_*) - highest priority, override dw.json
36- * 2. dw.json file (explicit path via --dw-json , or auto-discovered)
46+ * 2. dw.json file (explicit path via --config , or auto-discovered)
3747 * 3. Auto-discovery (searches upward from cwd)
3848 *
3949 * ## Toolset Validation
6171 * b2c-dx-mcp -s SCAPI -t cartridge_deploy
6272 * ```
6373 *
64- * @example Specify dw.json location
74+ * @example Specify config file location
75+ * ```bash
76+ * b2c-dx-mcp -s all --config /path/to/dw.json
77+ * ```
78+ *
79+ * @example Enable debug logging
6580 * ```bash
66- * b2c-dx-mcp -s all --dw-json /path/to/dw.json
81+ * b2c-dx-mcp -s all -D
6782 * ```
6883 */
6984
70- import { Command , Flags } from "@oclif/core" ;
85+ import { Flags } from "@oclif/core" ;
86+ import { BaseCommand } from "@salesforce/b2c-tooling-sdk/cli" ;
7187import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js" ;
7288import { B2CDxMcpServer } from "../server.js" ;
7389import { Services } from "../services.js" ;
@@ -78,12 +94,15 @@ import { TOOLSETS, type StartupFlags } from "../utils/index.js";
7894 * oclif Command that starts the B2C DX MCP server.
7995 *
8096 * Uses oclif's single-command strategy - this IS the CLI, not a subcommand.
81- * Inherits from oclif's Command class which provides:
97+ * Extends BaseCommand from @salesforce/b2c-tooling-sdk which provides:
98+ * - Global flags for config, logging, and debugging
99+ * - Structured pino logging via `this.logger`
100+ * - Automatic dw.json loading via `this.resolvedConfig`
82101 * - `this.config` - package.json metadata and standard config paths
83- * - `this.parse()` - type-safe flag parsing
84- * - `this.error()` - formatted error output
85102 */
86- export default class McpServerCommand extends Command {
103+ export default class McpServerCommand extends BaseCommand <
104+ typeof McpServerCommand
105+ > {
87106 static description =
88107 "Salesforce B2C Commerce Cloud Developer Experience MCP Server - Expose B2C Commerce Developer Experience tools to AI assistants" ;
89108
@@ -92,7 +111,8 @@ export default class McpServerCommand extends Command {
92111 "<%= config.bin %> <%= command.id %> --toolsets STOREFRONTNEXT,MRT" ,
93112 "<%= config.bin %> <%= command.id %> --tools sfnext_deploy,mrt_bundle_push" ,
94113 "<%= config.bin %> <%= command.id %> --toolsets STOREFRONTNEXT --tools sfnext_deploy" ,
95- "<%= config.bin %> <%= command.id %> --toolsets MRT --dw-json /path/to/dw.json" ,
114+ "<%= config.bin %> <%= command.id %> --toolsets MRT --config /path/to/dw.json" ,
115+ "<%= config.bin %> <%= command.id %> --toolsets all --debug" ,
96116 ] ;
97117
98118 static flags = {
@@ -116,20 +136,13 @@ export default class McpServerCommand extends Command {
116136 env : "SFCC_ALLOW_NON_GA_TOOLS" ,
117137 default : false ,
118138 } ) ,
119-
120- // Configuration
121- "dw-json" : Flags . string ( {
122- description :
123- "Path to dw.json (optional, auto-discovered if not provided)" ,
124- env : "SFCC_DW_JSON" ,
125- } ) ,
126139 } ;
127140
128141 /**
129142 * Main entry point - starts the MCP server.
130143 *
131144 * Execution flow:
132- * 1. Parse flags using oclif (with case normalization)
145+ * 1. BaseCommand.init() parses flags and loads config
133146 * 2. Filter and validate toolsets (invalid ones are skipped with warning)
134147 * 3. Create B2CDxMcpServer instance
135148 * 4. Create Services for dependency injection (config, file system access)
@@ -140,26 +153,30 @@ export default class McpServerCommand extends Command {
140153 * @throws Never throws - invalid toolsets are filtered, not rejected
141154 *
142155 * @remarks
156+ * BaseCommand provides:
157+ * - `this.flags` - Parsed flags including global flags (config, debug, log-level, etc.)
158+ * - `this.resolvedConfig` - Loaded dw.json configuration
159+ * - `this.logger` - Structured pino logger
160+ *
143161 * oclif provides standard config paths via `this.config`:
144162 * - `this.config.configDir` - User config (~/.config/b2c-dx-mcp)
145163 * - `this.config.dataDir` - User data (~/.local/share/b2c-dx-mcp)
146164 * - `this.config.cacheDir` - Cache (~/.cache/b2c-dx-mcp)
147165 * These can be exposed to Services if needed for features like telemetry or caching.
148166 */
149167 async run ( ) : Promise < void > {
150- const { flags } = await this . parse ( McpServerCommand ) ;
151-
168+ // Flags are already parsed by BaseCommand.init()
152169 // Parse toolsets and tools from comma-separated strings
153170 // Note: toolsets are uppercased, tools are lowercased by their parse functions
154171 const startupFlags : StartupFlags = {
155- toolsets : flags . toolsets
156- ? flags . toolsets . split ( "," ) . map ( ( s ) => s . trim ( ) )
172+ toolsets : this . flags . toolsets
173+ ? this . flags . toolsets . split ( "," ) . map ( ( s ) => s . trim ( ) )
157174 : undefined ,
158- tools : flags . tools
159- ? flags . tools . split ( "," ) . map ( ( s ) => s . trim ( ) )
175+ tools : this . flags . tools
176+ ? this . flags . tools . split ( "," ) . map ( ( s ) => s . trim ( ) )
160177 : undefined ,
161- allowNonGaTools : flags [ "allow-non-ga-tools" ] ,
162- dwJsonPath : flags [ "dw-json" ] ,
178+ allowNonGaTools : this . flags [ "allow-non-ga-tools" ] ,
179+ configPath : this . flags . config ,
163180 } ;
164181
165182 // TODO: Telemetry - Initialize telemetry unless disabled
@@ -191,8 +208,9 @@ export default class McpServerCommand extends Command {
191208 ) ;
192209
193210 // Create services for dependency injection
211+ // Pass the config path for tools that need to load configuration
194212 const services = new Services ( {
195- dwJsonPath : startupFlags . dwJsonPath ,
213+ configPath : this . flags . config ,
196214 } ) ;
197215
198216 // Register toolsets
@@ -202,11 +220,14 @@ export default class McpServerCommand extends Command {
202220 const transport = new StdioServerTransport ( ) ;
203221 await server . connect ( transport ) ;
204222
205- // Log startup message to stderr (not stdout, which is for MCP protocol)
206- console . error ( `✅ MCP Server v${ this . config . version } running on stdio` ) ;
207- console . error ( ` Available toolsets: ${ TOOLSETS . join ( ", " ) } ` ) ;
208- console . error (
209- ` Enabled: ${ ( startupFlags . toolsets ?? [ ] ) . join ( ", " ) || "(none specified)" } ` ,
223+ // Log startup message using the structured logger
224+ this . logger . info (
225+ { version : this . config . version , toolsets : TOOLSETS } ,
226+ "MCP Server running on stdio" ,
227+ ) ;
228+ this . logger . info (
229+ { enabled : startupFlags . toolsets ?? [ ] } ,
230+ "Enabled toolsets" ,
210231 ) ;
211232 }
212233}
0 commit comments