Skip to content

Commit 00bdd8e

Browse files
committed
refactor and use MrtCommand and InstanceCommand baseFlags
1 parent 80558eb commit 00bdd8e

12 files changed

Lines changed: 408 additions & 275 deletions

File tree

packages/b2c-dx-mcp/.mocharc.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,3 @@
99
"import=tsx"
1010
]
1111
}
12-
13-

packages/b2c-dx-mcp/README.md

Lines changed: 129 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,25 @@ Since the package is not yet published to npm, see the [Development](#developmen
2222
| `--tools` | Comma-separated individual tools to enable (case-insensitive) |
2323
| `--allow-non-ga-tools` | Enable experimental (non-GA) tools |
2424

25-
#### Auth Flags
25+
#### MRT Flags (inherited from MrtCommand)
2626

2727
| Flag | Env Variable | Description |
2828
|------|--------------|-------------|
29-
| `--mrt-api-key` | `SFCC_MRT_API_KEY` | MRT API key for Managed Runtime operations |
30-
| `--mrt-cloud-origin` | `SFCC_MRT_CLOUD_ORIGIN` | MRT cloud origin URL (default: https://cloud.mobify.com). See [Environment-Specific Config Files](#environment-specific-config-files) |
29+
| `--api-key` | `SFCC_MRT_API_KEY` | MRT API key for Managed Runtime operations |
30+
| `--project` | `SFCC_MRT_PROJECT` | MRT project slug (required for MRT tools) |
31+
| `--environment` | `SFCC_MRT_ENVIRONMENT` | MRT environment (e.g., staging, production) |
32+
| `--cloud-origin` | `SFCC_MRT_CLOUD_ORIGIN` | MRT cloud origin URL (default: https://cloud.mobify.com). See [Environment-Specific Config](#environment-specific-config) |
33+
34+
#### B2C Instance Flags (inherited from InstanceCommand)
35+
36+
| Flag | Env Variable | Description |
37+
|------|--------------|-------------|
38+
| `--server` | `SFCC_SERVER` | B2C instance hostname |
39+
| `--code-version` | `SFCC_CODE_VERSION` | Code version for deployments |
40+
| `--username` | `SFCC_USERNAME` | Username for Basic auth (WebDAV) |
41+
| `--password` | `SFCC_PASSWORD` | Password/access key for Basic auth |
42+
| `--client-id` | `SFCC_CLIENT_ID` | OAuth client ID |
43+
| `--client-secret` | `SFCC_CLIENT_SECRET` | OAuth client secret |
3144

3245
#### Global Flags (inherited from SDK)
3346

@@ -55,12 +68,22 @@ Since the package is not yet published to npm, see the [Development](#developmen
5568
// Explicit config file path
5669
"args": ["--toolsets", "all", "--config", "/path/to/dw.json"]
5770

58-
// MRT tools with API key
59-
"args": ["--toolsets", "MRT", "--mrt-api-key", "your-api-key"]
71+
// B2C instance tools with Basic auth (preferred for WebDAV tools like cartridge_deploy)
72+
"args": ["--toolsets", "CARTRIDGES", "--server", "your-sandbox.demandware.net", "--username", "your.username", "--password", "your-access-key"]
73+
74+
// B2C instance tools with OAuth (for OCAPI/SCAPI tools, or WebDAV fallback)
75+
"args": ["--toolsets", "SCAPI", "--server", "your-sandbox.demandware.net", "--client-id", "your-client-id", "--client-secret", "your-client-secret"]
76+
77+
// B2C instance tools with env vars (Basic auth)
78+
"args": ["--toolsets", "CARTRIDGES"],
79+
"env": { "SFCC_SERVER": "your-sandbox.demandware.net", "SFCC_USERNAME": "your.username", "SFCC_PASSWORD": "your-access-key" }
6080

61-
// Or use environment variable in mcp.json
81+
// MRT tools with project, environment, and API key
82+
"args": ["--toolsets", "MRT", "--project", "my-project", "--environment", "staging", "--api-key", "your-api-key"]
83+
84+
// Or use environment variables in mcp.json
6285
"args": ["--toolsets", "MRT"],
63-
"env": { "SFCC_MRT_API_KEY": "your-api-key" }
86+
"env": { "SFCC_MRT_API_KEY": "your-api-key", "SFCC_MRT_PROJECT": "my-project", "SFCC_MRT_ENVIRONMENT": "staging" }
6487

6588
// Enable experimental tools (required for placeholder tools)
6689
"args": ["--toolsets", "all", "--allow-non-ga-tools"]
@@ -218,13 +241,20 @@ Configure your IDE to use the local MCP server. Add this to your IDE's MCP confi
218241
{
219242
"mcpServers": {
220243
"b2c-dx-local": {
221-
"command": "node",
222-
"args": ["--conditions", "development", "/full/path/to/packages/b2c-dx-mcp/bin/dev.js", "--toolsets", "all", "--allow-non-ga-tools"]
244+
"command": "/full/path/to/packages/b2c-dx-mcp/bin/dev.js",
245+
"args": [
246+
"--toolsets", "all",
247+
"--allow-non-ga-tools"
248+
]
223249
}
224250
}
225251
}
226252
```
227253

254+
> **Note:** Make sure the script is executable: `chmod +x /full/path/to/packages/b2c-dx-mcp/bin/dev.js`
255+
>
256+
> The script's shebang (`#!/usr/bin/env -S node --conditions development`) handles Node.js setup automatically.
257+
228258
> **Note:** Restart the MCP server in your IDE to pick up code changes.
229259
230260
#### 3. JSON-RPC via stdin
@@ -247,103 +277,143 @@ Different tools require different types of configuration:
247277

248278
| Tool Type | Configuration Required |
249279
|-----------|----------------------|
250-
| **MRT tools** (e.g., `mrt_bundle_push`) | MRT API key |
251-
| **B2C instance tools** (e.g., `cartridge_deploy`, SCAPI) | dw.json config |
280+
| **MRT tools** (e.g., `mrt_bundle_push`) | API key + project |
281+
| **B2C instance tools** (e.g., `cartridge_deploy`) | dw.json or instance flags |
252282
| **Local tools** (e.g., scaffolding) | None |
253283

254-
#### MRT API Key
284+
#### MRT Configuration
255285

256-
MRT (Managed Runtime) operations require an API key from the [Runtime Admin](https://runtime.commercecloud.com/) dashboard.
286+
MRT tools require an **API key** and **project**. The **environment** is optional (for deployments).
257287

258-
**Priority order** (highest to lowest):
288+
| Setting | Flag | Env Variable | Fallback |
289+
|---------|------|--------------|----------|
290+
| API key | `--api-key` | `SFCC_MRT_API_KEY` | `~/.mobify` |
291+
| Project | `--project` | `SFCC_MRT_PROJECT` ||
292+
| Environment | `--environment` | `SFCC_MRT_ENVIRONMENT` ||
259293

260-
1. `--mrt-api-key` flag
261-
2. `SFCC_MRT_API_KEY` environment variable
262-
3. `~/.mobify` config file (or `~/.mobify--[hostname]` if `--mrt-cloud-origin` is set)
294+
> Priority: Flag > Env variable > `~/.mobify` file
263295
264-
**Option A: Flag or environment variable**
296+
**Example:**
265297

266298
```json
267-
// mcp.json - using flag
268299
{
269300
"mcpServers": {
270301
"b2c-dx": {
271-
"command": "b2c-dx-mcp",
272-
"args": ["--toolsets", "MRT", "--mrt-api-key", "your-api-key"]
302+
"command": "/path/to/packages/b2c-dx-mcp/bin/dev.js",
303+
"args": [
304+
"--toolsets", "MRT",
305+
"--project", "my-project",
306+
"--environment", "staging",
307+
"--api-key", "your-api-key"
308+
]
273309
}
274310
}
275311
}
312+
```
313+
314+
Or use environment variables instead of flags:
276315

277-
// mcp.json - using env var
316+
```json
278317
{
279318
"mcpServers": {
280319
"b2c-dx": {
281-
"command": "b2c-dx-mcp",
320+
"command": "/path/to/packages/b2c-dx-mcp/bin/dev.js",
282321
"args": ["--toolsets", "MRT"],
283322
"env": {
284-
"SFCC_MRT_API_KEY": "your-api-key"
323+
"SFCC_MRT_API_KEY": "your-api-key",
324+
"SFCC_MRT_PROJECT": "my-project",
325+
"SFCC_MRT_ENVIRONMENT": "staging"
285326
}
286327
}
287328
}
288329
}
289330
```
290331

291-
**Option B: ~/.mobify file (legacy)**
332+
> **Note:** Make sure the script is executable: `chmod +x /path/to/packages/b2c-dx-mcp/bin/dev.js`
333+
334+
#### Environment-Specific Config
292335

293-
If you already use the `b2c` CLI for MRT operations, you may have a `~/.mobify` file configured:
336+
If you have a `~/.mobify` file from the `b2c` CLI, the MCP server will use it as a fallback for API key:
294337

295338
```json
296339
{
297-
"username": "your.email@example.com",
298340
"api_key": "your-api-key"
299341
}
300342
```
301343

302-
The MCP server will automatically use this file as a fallback if no flag or environment variable is set.
344+
For non-production environments, use `--cloud-origin` to select an environment-specific config file:
345+
346+
| `--cloud-origin` | Config File |
347+
|------------------|-------------|
348+
| (not set) | `~/.mobify` |
349+
| `https://cloud-staging.mobify.com` | `~/.mobify--cloud-staging.mobify.com` |
350+
| `https://cloud-dev.mobify.com` | `~/.mobify--cloud-dev.mobify.com` |
351+
352+
#### B2C Instance Config (dw.json)
353+
354+
Tools that interact with B2C Commerce instances (e.g., `cartridge_deploy`, SCAPI tools) require instance credentials.
355+
356+
**Authentication Methods:**
357+
358+
| Method | Credentials | Used By |
359+
|--------|-------------|---------|
360+
| **Basic auth** | `--username` + `--password` | WebDAV tools (`cartridge_deploy`) |
361+
| **OAuth** | `--client-id` + `--client-secret` | OCAPI tools, SCAPI tools |
303362

304-
##### Environment-Specific Config Files
363+
> **Recommendation:** Use Basic auth (username/password) for WebDAV tools like `cartridge_deploy`. OAuth credentials (client-id/client-secret) are required for OCAPI/SCAPI tools. If you need both WebDAV and OCAPI tools, configure all four credentials.
305364
306-
When using `~/.mobify` config files (i.e., no `--mrt-api-key` flag or `SFCC_MRT_API_KEY` env var), you can use `--mrt-cloud-origin` to select an environment-specific config file:
365+
**Priority order** (highest to lowest):
366+
367+
1. Flags (`--server`, `--username`, `--password`, `--client-id`, `--client-secret`)
368+
2. Environment variables (`SFCC_*`)
369+
3. `dw.json` file (via `--config` flag or auto-discovery)
370+
371+
**Option A: Flags with Basic auth (for WebDAV tools like cartridge_deploy)**
307372

308373
```json
309-
// mcp.json - uses ~/.mobify--cloud-staging.mobify.com for API key
310374
{
311375
"mcpServers": {
312-
"b2c-dx-staging": {
313-
"command": "b2c-dx-mcp",
314-
"args": ["--toolsets", "MRT", "--mrt-cloud-origin", "https://cloud-staging.mobify.com"]
376+
"b2c-dx": {
377+
"command": "/path/to/packages/b2c-dx-mcp/bin/dev.js",
378+
"args": [
379+
"--toolsets", "CARTRIDGES",
380+
"--server", "your-sandbox.demandware.net",
381+
"--username", "your.username",
382+
"--password", "your-access-key"
383+
]
315384
}
316385
}
317386
}
318387
```
319388

320-
| Cloud Origin | Config File |
321-
|--------------|-------------|
322-
| (default) | `~/.mobify` |
323-
| `https://cloud-staging.mobify.com` | `~/.mobify--cloud-staging.mobify.com` |
324-
| `https://cloud-dev.mobify.com` | `~/.mobify--cloud-dev.mobify.com` |
325-
326-
> **Note:** `--mrt-cloud-origin` is only relevant when the API key is resolved from a config file. If `--mrt-api-key` or `SFCC_MRT_API_KEY` is provided, this flag is ignored.
327-
328-
#### B2C Instance Config (dw.json)
329-
330-
Tools that interact with B2C Commerce instances (e.g., `cartridge_deploy`, SCAPI tools) require instance credentials.
331-
332-
**Priority order** (highest to lowest):
389+
**Option B: Flags with OAuth (for OCAPI/SCAPI tools, or WebDAV fallback)**
333390

334-
1. Environment variables (`SFCC_*`)
335-
2. `dw.json` file (via `--config` flag or auto-discovery)
391+
```json
392+
{
393+
"mcpServers": {
394+
"b2c-dx": {
395+
"command": "/path/to/packages/b2c-dx-mcp/bin/dev.js",
396+
"args": [
397+
"--toolsets", "SCAPI",
398+
"--server", "your-sandbox.demandware.net",
399+
"--client-id", "your-client-id",
400+
"--client-secret", "your-client-secret"
401+
]
402+
}
403+
}
404+
}
405+
```
336406

337-
**Option A: Environment variables**
407+
**Option C: Environment variables (all credentials)**
338408

339409
```json
340410
{
341411
"mcpServers": {
342412
"b2c-dx": {
343-
"command": "b2c-dx-mcp",
413+
"command": "/path/to/packages/b2c-dx-mcp/bin/dev.js",
344414
"args": ["--toolsets", "CARTRIDGES"],
345415
"env": {
346-
"SFCC_HOSTNAME": "your-sandbox.demandware.net",
416+
"SFCC_SERVER": "your-sandbox.demandware.net",
347417
"SFCC_USERNAME": "your.username",
348418
"SFCC_PASSWORD": "your-access-key",
349419
"SFCC_CLIENT_ID": "your-client-id",
@@ -355,22 +425,24 @@ Tools that interact with B2C Commerce instances (e.g., `cartridge_deploy`, SCAPI
355425
}
356426
```
357427

358-
**Option B: dw.json with explicit path**
428+
**Option D: dw.json with explicit path**
359429

360430
```json
361431
{
362432
"mcpServers": {
363433
"b2c-dx": {
364-
"command": "b2c-dx-mcp",
434+
"command": "/path/to/packages/b2c-dx-mcp/bin/dev.js",
365435
"args": ["--toolsets", "CARTRIDGES", "--config", "/path/to/dw.json"]
366436
}
367437
}
368438
}
369439
```
370440

371-
**Option C: dw.json with auto-discovery**
441+
**Option E: dw.json with auto-discovery**
442+
443+
When `--config` is not provided, the MCP server searches upward from `~/` for a `dw.json` file.
372444

373-
Create a `dw.json` file in your project root. The MCP server will auto-discover it by searching upward from the current working directory:
445+
> **Note:** Auto-discovery starts from the home directory, so it won't find project-level `dw.json` files. Use `--config` with an explicit path instead.
374446
375447
```json
376448
{
@@ -383,7 +455,7 @@ Create a `dw.json` file in your project root. The MCP server will auto-discover
383455
}
384456
```
385457

386-
> **Note:** Environment variables override values from `dw.json`. You can use env vars to override specific fields (e.g., secrets) while using dw.json for other settings.
458+
> **Note:** Flags override environment variables, and environment variables override `dw.json`. You can mix sources (e.g., secrets via env vars, other settings via dw.json).
387459
388460
## License
389461

packages/b2c-dx-mcp/bin/run.cmd

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
@echo off
22

33
node "%~dp0\run" %*
4-
5-

0 commit comments

Comments
 (0)