@salesforce/b2c-dx-mcp 1.9.3 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -167,6 +167,16 @@ export declare class Services {
167
167
  * Get OS platform information.
168
168
  */
169
169
  getPlatform(): NodeJS.Platform;
170
+ /**
171
+ * Get the resolved configuration (values, sources, warnings).
172
+ *
173
+ * Exposed for the `config_inspect` tool so agents can see the effective,
174
+ * source-attributed configuration the server resolved. Callers displaying
175
+ * these values must redact secrets (see `redactConfigValues`).
176
+ *
177
+ * @returns The resolved B2C configuration
178
+ */
179
+ getResolvedConfig(): ResolvedB2CConfig;
170
180
  /**
171
181
  * Get SCAPI Schemas client for discovering available SCAPI APIs.
172
182
  * Requires shortCode, tenantId, and OAuth credentials to be configured.
@@ -230,16 +240,48 @@ export declare class Services {
230
240
  * @returns Absolute path
231
241
  */
232
242
  resolvePath(...segments: string[]): string;
243
+ /**
244
+ * Resolve the effective project directory for a tool call, reporting which
245
+ * source it came from.
246
+ *
247
+ * MCP clients disagree on the working directory a stdio server is spawned
248
+ * with (Claude Code / Cursor often use the user's home directory rather than
249
+ * the open project — see https://agent-plugins.org/plugin-authors/mcp-servers),
250
+ * so the resolved value is deliberately explicit. Precedence:
251
+ *
252
+ * 1. `override` — a per-call `projectDirectory` tool argument (highest)
253
+ * 2. `projectDirectory` from `--project-directory` / `SFCC_PROJECT_DIRECTORY`
254
+ * 3. `process.cwd()` (fallback; unreliable across clients)
255
+ *
256
+ * Tools should surface the returned `{path, source}` in their output so the
257
+ * agent can see which directory was used when it did not pass one explicitly.
258
+ *
259
+ * The `override` and configured values are returned as-supplied (not
260
+ * re-resolved against cwd); callers pass absolute paths, and `path.resolve`
261
+ * would otherwise drive-prefix a POSIX-style path on Windows.
262
+ *
263
+ * @param override - Optional explicit project directory from a tool argument
264
+ * @returns The project directory and the source it was resolved from
265
+ */
266
+ resolveProjectDirectory(override?: string): {
267
+ path: string;
268
+ source: 'argument' | 'config' | 'cwd';
269
+ };
233
270
  /**
234
271
  * Resolve a path relative to the project directory.
235
272
  * If path is not supplied, returns the project directory.
236
273
  * If path is absolute, returns it as-is.
237
274
  * If path is relative, resolves it relative to the project directory.
238
275
  *
276
+ * An optional explicit project-directory override (typically a per-call
277
+ * `projectDirectory` tool argument) takes precedence over the configured
278
+ * project directory and cwd — see {@link Services.resolveProjectDirectory}.
279
+ *
239
280
  * @param pathArg - Optional path to resolve
281
+ * @param projectDirectoryOverride - Optional explicit project directory to resolve against
240
282
  * @returns Resolved absolute path
241
283
  */
242
- resolveWithProjectDirectory(pathArg?: string): string;
284
+ resolveWithProjectDirectory(pathArg?: string, projectDirectoryOverride?: string): string;
243
285
  /**
244
286
  * Get file or directory stats.
245
287
  *
package/dist/services.js CHANGED
@@ -206,6 +206,18 @@ export class Services {
206
206
  getPlatform() {
207
207
  return os.platform();
208
208
  }
209
+ /**
210
+ * Get the resolved configuration (values, sources, warnings).
211
+ *
212
+ * Exposed for the `config_inspect` tool so agents can see the effective,
213
+ * source-attributed configuration the server resolved. Callers displaying
214
+ * these values must redact secrets (see `redactConfigValues`).
215
+ *
216
+ * @returns The resolved B2C configuration
217
+ */
218
+ getResolvedConfig() {
219
+ return this.resolvedConfig;
220
+ }
209
221
  /**
210
222
  * Get SCAPI Schemas client for discovering available SCAPI APIs.
211
223
  * Requires shortCode, tenantId, and OAuth credentials to be configured.
@@ -302,17 +314,55 @@ export class Services {
302
314
  resolvePath(...segments) {
303
315
  return path.resolve(...segments);
304
316
  }
317
+ /**
318
+ * Resolve the effective project directory for a tool call, reporting which
319
+ * source it came from.
320
+ *
321
+ * MCP clients disagree on the working directory a stdio server is spawned
322
+ * with (Claude Code / Cursor often use the user's home directory rather than
323
+ * the open project — see https://agent-plugins.org/plugin-authors/mcp-servers),
324
+ * so the resolved value is deliberately explicit. Precedence:
325
+ *
326
+ * 1. `override` — a per-call `projectDirectory` tool argument (highest)
327
+ * 2. `projectDirectory` from `--project-directory` / `SFCC_PROJECT_DIRECTORY`
328
+ * 3. `process.cwd()` (fallback; unreliable across clients)
329
+ *
330
+ * Tools should surface the returned `{path, source}` in their output so the
331
+ * agent can see which directory was used when it did not pass one explicitly.
332
+ *
333
+ * The `override` and configured values are returned as-supplied (not
334
+ * re-resolved against cwd); callers pass absolute paths, and `path.resolve`
335
+ * would otherwise drive-prefix a POSIX-style path on Windows.
336
+ *
337
+ * @param override - Optional explicit project directory from a tool argument
338
+ * @returns The project directory and the source it was resolved from
339
+ */
340
+ resolveProjectDirectory(override) {
341
+ if (override) {
342
+ return { path: override, source: 'argument' };
343
+ }
344
+ const configured = this.resolvedConfig.values.projectDirectory;
345
+ if (configured) {
346
+ return { path: configured, source: 'config' };
347
+ }
348
+ return { path: process.cwd(), source: 'cwd' };
349
+ }
305
350
  /**
306
351
  * Resolve a path relative to the project directory.
307
352
  * If path is not supplied, returns the project directory.
308
353
  * If path is absolute, returns it as-is.
309
354
  * If path is relative, resolves it relative to the project directory.
310
355
  *
356
+ * An optional explicit project-directory override (typically a per-call
357
+ * `projectDirectory` tool argument) takes precedence over the configured
358
+ * project directory and cwd — see {@link Services.resolveProjectDirectory}.
359
+ *
311
360
  * @param pathArg - Optional path to resolve
361
+ * @param projectDirectoryOverride - Optional explicit project directory to resolve against
312
362
  * @returns Resolved absolute path
313
363
  */
314
- resolveWithProjectDirectory(pathArg) {
315
- const projectDir = this.resolvedConfig.values.projectDirectory ?? process.cwd();
364
+ resolveWithProjectDirectory(pathArg, projectDirectoryOverride) {
365
+ const projectDir = this.resolveProjectDirectory(projectDirectoryOverride).path;
316
366
  if (!pathArg) {
317
367
  return projectDir;
318
368
  }
@@ -106,6 +106,7 @@ function createCartridgeDeployTool(loadServices, injections) {
106
106
  const result = await findAndDeployCartridgesFn(instance, directory, options);
107
107
  return {
108
108
  ...result,
109
+ resolvedDirectory: directory,
109
110
  postInstructions: CARTRIDGE_PATH_REMINDER,
110
111
  };
111
112
  }
@@ -0,0 +1,12 @@
1
+ import type { McpTool } from '../../utils/index.js';
2
+ import type { Services } from '../../services.js';
3
+ /**
4
+ * Creates the `config_inspect` tool — the MCP equivalent of the CLI
5
+ * `b2c setup inspect` command. Reports the resolved configuration (with secrets
6
+ * redacted by default), the sources that contributed, and — importantly for
7
+ * agents — the effective project directory and how it was resolved.
8
+ *
9
+ * @param loadServices - Function that loads configuration and returns Services instance
10
+ * @returns The config_inspect MCP tool
11
+ */
12
+ export declare function createConfigInspectTool(loadServices: () => Promise<Services> | Services): McpTool;
@@ -0,0 +1,47 @@
1
+ /*
2
+ * Copyright (c) 2025, Salesforce, Inc.
3
+ * SPDX-License-Identifier: Apache-2
4
+ * For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
5
+ */
6
+ import { z } from 'zod';
7
+ import { redactConfigValues } from '@salesforce/b2c-tooling-sdk/config';
8
+ import { createToolAdapter, jsonResult } from '../adapter.js';
9
+ /**
10
+ * Creates the `config_inspect` tool — the MCP equivalent of the CLI
11
+ * `b2c setup inspect` command. Reports the resolved configuration (with secrets
12
+ * redacted by default), the sources that contributed, and — importantly for
13
+ * agents — the effective project directory and how it was resolved.
14
+ *
15
+ * @param loadServices - Function that loads configuration and returns Services instance
16
+ * @returns The config_inspect MCP tool
17
+ */
18
+ export function createConfigInspectTool(loadServices) {
19
+ return createToolAdapter({
20
+ name: 'config_inspect',
21
+ description: 'Inspect the resolved B2C Commerce configuration the MCP server is using — instance hostname, auth, SCAPI, MRT, and other settings — along with which source (dw.json, environment variables, flags) provided each value. ' +
22
+ 'Secrets (passwords, client secrets, API keys) are redacted by default. ' +
23
+ 'The output includes the effective projectDirectory and how it was resolved (explicit --project-directory / SFCC_PROJECT_DIRECTORY vs. the process working directory), which is useful for diagnosing why the server targets the wrong instance or cannot find a project. ' +
24
+ 'Use this first when configuration seems wrong, auth is failing, or the server appears to be operating in the wrong directory.',
25
+ toolsets: ['DIAGNOSTICS'],
26
+ isGA: true,
27
+ requiresInstance: false,
28
+ inputSchema: {
29
+ unmask: z
30
+ .boolean()
31
+ .optional()
32
+ .describe('Show sensitive values (passwords, secrets, API keys) unmasked. Defaults to false — secrets are redacted. Only set this when the user explicitly needs the raw secret values.'),
33
+ },
34
+ async execute(args, { services }) {
35
+ const resolved = services.getResolvedConfig();
36
+ const projectDirectory = services.resolveProjectDirectory();
37
+ return {
38
+ config: redactConfigValues(resolved.values, { unmask: args.unmask ?? false }),
39
+ projectDirectory,
40
+ sources: resolved.sources,
41
+ warnings: resolved.warnings.length > 0 ? resolved.warnings.map((w) => w.message) : undefined,
42
+ };
43
+ },
44
+ formatOutput: (output) => jsonResult(output),
45
+ }, loadServices);
46
+ }
47
+ //# sourceMappingURL=config-inspect.js.map
@@ -3,6 +3,7 @@
3
3
  * SPDX-License-Identifier: Apache-2
4
4
  * For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
5
5
  */
6
+ import { createConfigInspectTool } from './config-inspect.js';
6
7
  import { createDebugListSessionsTool } from './debug-list-sessions.js';
7
8
  import { createDebugStartSessionTool } from './debug-start-session.js';
8
9
  import { createDebugEndSessionTool } from './debug-end-session.js';
@@ -26,6 +27,7 @@ import { createMrtLogsWatchStopTool } from './mrt-logs-watch-stop.js';
26
27
  import { createMrtLogsWatchListTool } from './mrt-logs-watch-list.js';
27
28
  export function createDiagnosticsTools(loadServices, serverContext, injections) {
28
29
  return [
30
+ createConfigInspectTool(loadServices),
29
31
  createDebugListSessionsTool(loadServices, serverContext),
30
32
  createDebugStartSessionTool(loadServices, serverContext),
31
33
  createDebugEndSessionTool(loadServices, serverContext),
@@ -252,6 +252,7 @@
252
252
  "options": [
253
253
  "client-credentials",
254
254
  "jwt",
255
+ "user",
255
256
  "implicit",
256
257
  "basic",
257
258
  "api-key"
@@ -259,7 +260,7 @@
259
260
  "type": "option"
260
261
  },
261
262
  "user-auth": {
262
- "description": "Use browser-based user authentication (implicit OAuth flow)",
263
+ "description": "Use browser-based user authentication (Authorization Code + PKCE flow)",
263
264
  "exclusive": [
264
265
  "auth-methods"
265
266
  ],
@@ -428,5 +429,5 @@
428
429
  "enableJsonFlag": false
429
430
  }
430
431
  },
431
- "version": "1.9.3"
432
+ "version": "1.10.0"
432
433
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@salesforce/b2c-dx-mcp",
3
3
  "description": "MCP server for B2C Commerce developer experience tools",
4
- "version": "1.9.3",
4
+ "version": "1.10.0",
5
5
  "author": "Salesforce",
6
6
  "license": "Apache-2.0",
7
7
  "repository": "SalesforceCommerceCloud/b2c-developer-tooling",
@@ -80,7 +80,7 @@
80
80
  "yaml": "2.9.0",
81
81
  "postcss": "8.5.15",
82
82
  "zod": "3.25.76",
83
- "@salesforce/b2c-tooling-sdk": "1.21.3"
83
+ "@salesforce/b2c-tooling-sdk": "1.22.0"
84
84
  },
85
85
  "devDependencies": {
86
86
  "@eslint/compat": "^1",