Skip to content

Commit bd85dc6

Browse files
authored
@W-20591366 Add Tool Adapter Layer for MCP Tools (#29)
1 parent e7ef085 commit bd85dc6

File tree

20 files changed

+2036
-278
lines changed

20 files changed

+2036
-278
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@
99
"import=tsx"
1010
]
1111
}
12-

packages/b2c-dx-mcp/README.md

Lines changed: 208 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,26 @@ 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+
#### MRT Flags (inherited from MrtCommand)
26+
27+
| Flag | Env Variable | Description |
28+
|------|--------------|-------------|
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 |
44+
2545
#### Global Flags (inherited from SDK)
2646

2747
| Flag | Description |
@@ -48,6 +68,23 @@ Since the package is not yet published to npm, see the [Development](#developmen
4868
// Explicit config file path
4969
"args": ["--toolsets", "all", "--config", "/path/to/dw.json"]
5070

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" }
80+
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
85+
"args": ["--toolsets", "MRT"],
86+
"env": { "SFCC_MRT_API_KEY": "your-api-key", "SFCC_MRT_PROJECT": "my-project", "SFCC_MRT_ENVIRONMENT": "staging" }
87+
5188
// Enable experimental tools (required for placeholder tools)
5289
"args": ["--toolsets", "all", "--allow-non-ga-tools"]
5390

@@ -204,13 +241,20 @@ Configure your IDE to use the local MCP server. Add this to your IDE's MCP confi
204241
{
205242
"mcpServers": {
206243
"b2c-dx-local": {
207-
"command": "node",
208-
"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+
]
209249
}
210250
}
211251
}
212252
```
213253

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+
214258
> **Note:** Restart the MCP server in your IDE to pick up code changes.
215259
216260
#### 3. JSON-RPC via stdin
@@ -229,30 +273,176 @@ echo '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"cartridge_
229273

230274
> **Note:** Configuration is not currently required as all tools are placeholder implementations. This section will be relevant once tools are fully implemented.
231275
232-
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.
276+
Different tools require different types of configuration:
277+
278+
| Tool Type | Configuration Required |
279+
|-----------|----------------------|
280+
| **MRT tools** (e.g., `mrt_bundle_push`) | API key + project |
281+
| **B2C instance tools** (e.g., `cartridge_deploy`) | dw.json or instance flags |
282+
| **Local tools** (e.g., scaffolding) | None |
283+
284+
#### MRT Configuration
285+
286+
MRT tools require an **API key** and **project**. The **environment** is optional (for deployments).
287+
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` ||
293+
294+
> Priority: Flag > Env variable > `~/.mobify` file
295+
296+
**Example:**
297+
298+
```json
299+
{
300+
"mcpServers": {
301+
"b2c-dx": {
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+
]
309+
}
310+
}
311+
}
312+
```
313+
314+
Or use environment variables instead of flags:
315+
316+
```json
317+
{
318+
"mcpServers": {
319+
"b2c-dx": {
320+
"command": "/path/to/packages/b2c-dx-mcp/bin/dev.js",
321+
"args": ["--toolsets", "MRT"],
322+
"env": {
323+
"SFCC_MRT_API_KEY": "your-api-key",
324+
"SFCC_MRT_PROJECT": "my-project",
325+
"SFCC_MRT_ENVIRONMENT": "staging"
326+
}
327+
}
328+
}
329+
}
330+
```
331+
332+
> **Note:** Make sure the script is executable: `chmod +x /path/to/packages/b2c-dx-mcp/bin/dev.js`
333+
334+
#### Environment-Specific Config
335+
336+
If you have a `~/.mobify` file from the `b2c` CLI, the MCP server will use it as a fallback for API key:
337+
338+
```json
339+
{
340+
"api_key": "your-api-key"
341+
}
342+
```
343+
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 |
362+
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.
233364
234365
**Priority order** (highest to lowest):
235366

236-
1. Environment variables (`SFCC_*`) — includes `.env` file if present (shell env vars override `.env`)
237-
2. `dw.json` file (auto-discovered or via `--config`)
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)
238370

239-
#### Option 1: Environment Variables
371+
**Option A: Flags with Basic auth (for WebDAV tools like cartridge_deploy)**
372+
373+
```json
374+
{
375+
"mcpServers": {
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+
]
384+
}
385+
}
386+
}
387+
```
240388

241-
Set environment variables directly or create a `.env` file in your project root:
389+
**Option B: Flags with OAuth (for OCAPI/SCAPI tools, or WebDAV fallback)**
242390

243-
```bash
244-
# .env file or shell exports
245-
SFCC_HOSTNAME="your-sandbox.demandware.net"
246-
SFCC_USERNAME="your.username"
247-
SFCC_PASSWORD="your-access-key"
248-
SFCC_CLIENT_ID="your-client-id"
249-
SFCC_CLIENT_SECRET="your-client-secret"
250-
SFCC_CODE_VERSION="version1"
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+
}
251405
```
252406

253-
#### Option 2: dw.json File
407+
**Option C: Environment variables (all credentials)**
408+
409+
```json
410+
{
411+
"mcpServers": {
412+
"b2c-dx": {
413+
"command": "/path/to/packages/b2c-dx-mcp/bin/dev.js",
414+
"args": ["--toolsets", "CARTRIDGES"],
415+
"env": {
416+
"SFCC_SERVER": "your-sandbox.demandware.net",
417+
"SFCC_USERNAME": "your.username",
418+
"SFCC_PASSWORD": "your-access-key",
419+
"SFCC_CLIENT_ID": "your-client-id",
420+
"SFCC_CLIENT_SECRET": "your-client-secret",
421+
"SFCC_CODE_VERSION": "version1"
422+
}
423+
}
424+
}
425+
}
426+
```
427+
428+
**Option D: dw.json with explicit path**
429+
430+
```json
431+
{
432+
"mcpServers": {
433+
"b2c-dx": {
434+
"command": "/path/to/packages/b2c-dx-mcp/bin/dev.js",
435+
"args": ["--toolsets", "CARTRIDGES", "--config", "/path/to/dw.json"]
436+
}
437+
}
438+
}
439+
```
440+
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.
254444

255-
Create a `dw.json` file in your project root (auto-discovered by searching upward from 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.
256446
257447
```json
258448
{
@@ -265,7 +455,7 @@ Create a `dw.json` file in your project root (auto-discovered by searching upwar
265455
}
266456
```
267457

268-
> **Note:** Environment variables take precedence over `dw.json` values.
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).
269459
270460
## License
271461

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

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

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

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

100644100755
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
* - Uses compiled JavaScript from dist/
1414
* - Loads .env file if present for local configuration
1515
*
16-
* Run directly: ./bin/run.js mcp --toolsets all
17-
* Or with node: node bin/run.js mcp --toolsets all
1816
*/
1917

2018
// Load .env file if present (Node.js native support)

0 commit comments

Comments
 (0)