Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/b2c-dx-mcp/.mocharc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
]
}


150 changes: 134 additions & 16 deletions packages/b2c-dx-mcp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ Since the package is not yet published to npm, see the [Development](#developmen
| `--tools` | Comma-separated individual tools to enable (case-insensitive) |
| `--allow-non-ga-tools` | Enable experimental (non-GA) tools |

#### Auth Flags

| Flag | Env Variable | Description |
|------|--------------|-------------|
| `--mrt-api-key` | `SFCC_MRT_API_KEY` | MRT API key for Managed Runtime operations |
| `--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) |

#### Global Flags (inherited from SDK)

| Flag | Description |
Expand All @@ -48,6 +55,13 @@ Since the package is not yet published to npm, see the [Development](#developmen
// Explicit config file path
"args": ["--toolsets", "all", "--config", "/path/to/dw.json"]

// MRT tools with API key
"args": ["--toolsets", "MRT", "--mrt-api-key", "your-api-key"]

// Or use environment variable in mcp.json
"args": ["--toolsets", "MRT"],
"env": { "SFCC_MRT_API_KEY": "your-api-key" }

// Enable experimental tools (required for placeholder tools)
"args": ["--toolsets", "all", "--allow-non-ga-tools"]

Expand Down Expand Up @@ -229,30 +243,134 @@ echo '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"cartridge_

> **Note:** Configuration is not currently required as all tools are placeholder implementations. This section will be relevant once tools are fully implemented.

Tools that interact with B2C Commerce instances (e.g., MRT, SCAPI, cartridge deployment) require credentials, which can be provided via **environment variables**, a **`.env` file**, a **`dw.json` file**, or the **`--config`** flag. Local tools (e.g., scaffolding, development guidelines) work without configuration.
Different tools require different types of configuration:

| Tool Type | Configuration Required |
|-----------|----------------------|
| **MRT tools** (e.g., `mrt_bundle_push`) | MRT API key |
| **B2C instance tools** (e.g., `cartridge_deploy`, SCAPI) | dw.json config |
| **Local tools** (e.g., scaffolding) | None |

#### MRT API Key

MRT (Managed Runtime) operations require an API key from the [Runtime Admin](https://runtime.commercecloud.com/) dashboard.

**Priority order** (highest to lowest):

1. Environment variables (`SFCC_*`) — includes `.env` file if present (shell env vars override `.env`)
2. `dw.json` file (auto-discovered or via `--config`)
1. `--mrt-api-key` flag
2. `SFCC_MRT_API_KEY` environment variable
3. `~/.mobify` config file (or `~/.mobify--[hostname]` if `--mrt-cloud-origin` is set)

#### Option 1: Environment Variables
**Option A: Flag or environment variable**

Set environment variables directly or create a `.env` file in your project root:
```json
// mcp.json - using flag
{
"mcpServers": {
"b2c-dx": {
"command": "b2c-dx-mcp",
"args": ["--toolsets", "MRT", "--mrt-api-key", "your-api-key"]
}
}
}

```bash
# .env file or shell exports
SFCC_HOSTNAME="your-sandbox.demandware.net"
SFCC_USERNAME="your.username"
SFCC_PASSWORD="your-access-key"
SFCC_CLIENT_ID="your-client-id"
SFCC_CLIENT_SECRET="your-client-secret"
SFCC_CODE_VERSION="version1"
// mcp.json - using env var
{
"mcpServers": {
"b2c-dx": {
"command": "b2c-dx-mcp",
"args": ["--toolsets", "MRT"],
"env": {
"SFCC_MRT_API_KEY": "your-api-key"
}
}
}
}
```

**Option B: ~/.mobify file (legacy)**

If you already use the `b2c` CLI for MRT operations, you may have a `~/.mobify` file configured:

```json
{
"username": "your.email@example.com",
"api_key": "your-api-key"
}
```

The MCP server will automatically use this file as a fallback if no flag or environment variable is set.

##### Environment-Specific Config Files

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:

```json
// mcp.json - uses ~/.mobify--cloud-staging.mobify.com for API key
{
"mcpServers": {
"b2c-dx-staging": {
"command": "b2c-dx-mcp",
"args": ["--toolsets", "MRT", "--mrt-cloud-origin", "https://cloud-staging.mobify.com"]
}
}
}
```

| Cloud Origin | Config File |
|--------------|-------------|
| (default) | `~/.mobify` |
| `https://cloud-staging.mobify.com` | `~/.mobify--cloud-staging.mobify.com` |
| `https://cloud-dev.mobify.com` | `~/.mobify--cloud-dev.mobify.com` |

> **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.

#### B2C Instance Config (dw.json)

Tools that interact with B2C Commerce instances (e.g., `cartridge_deploy`, SCAPI tools) require instance credentials.

**Priority order** (highest to lowest):

1. Environment variables (`SFCC_*`)
2. `dw.json` file (via `--config` flag or auto-discovery)

**Option A: Environment variables**

```json
{
"mcpServers": {
"b2c-dx": {
"command": "b2c-dx-mcp",
"args": ["--toolsets", "CARTRIDGES"],
"env": {
"SFCC_HOSTNAME": "your-sandbox.demandware.net",
"SFCC_USERNAME": "your.username",
"SFCC_PASSWORD": "your-access-key",
"SFCC_CLIENT_ID": "your-client-id",
"SFCC_CLIENT_SECRET": "your-client-secret",
"SFCC_CODE_VERSION": "version1"
}
}
}
}
```

**Option B: dw.json with explicit path**

```json
{
"mcpServers": {
"b2c-dx": {
"command": "b2c-dx-mcp",
"args": ["--toolsets", "CARTRIDGES", "--config", "/path/to/dw.json"]
}
}
}
```

#### Option 2: dw.json File
**Option C: dw.json with auto-discovery**

Create a `dw.json` file in your project root (auto-discovered by searching upward from current working directory):
Create a `dw.json` file in your project root. The MCP server will auto-discover it by searching upward from the current working directory:

```json
{
Expand All @@ -265,7 +383,7 @@ Create a `dw.json` file in your project root (auto-discovered by searching upwar
}
```

> **Note:** Environment variables take precedence over `dw.json` values.
> **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.

## License

Expand Down
1 change: 1 addition & 0 deletions packages/b2c-dx-mcp/bin/run.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

node "%~dp0\run" %*


Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new line is added after pnpm build

2 changes: 0 additions & 2 deletions packages/b2c-dx-mcp/bin/run.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
* - Uses compiled JavaScript from dist/
* - Loads .env file if present for local configuration
*
* Run directly: ./bin/run.js mcp --toolsets all
* Or with node: node bin/run.js mcp --toolsets all
*/

// Load .env file if present (Node.js native support)
Expand Down
Loading
Loading