Install AI Tools

B2C Commerce tools, documentation, and skills for your assistant.

Claude

Install the plugin Recommended

bash
claude plugin marketplace add SalesforceCommerceCloud/b2c-developer-tooling
claude plugin install b2c-dx-mcp@b2c-developer-tooling --scope project

Start a new Claude Code session in your project. Use --scope user instead for all projects.

Manual MCP setup

From your project directory:

bash
claude mcp add --transport stdio --scope project b2c-dx-mcp -- npx -y @salesforce/b2c-dx-mcp@latest

Start a new session. Use --scope user instead for all projects. See Claude Code MCP setup.

Claude Desktop setup

Codex

Install the plugin Recommended

bash
codex plugin marketplace add SalesforceCommerceCloud/b2c-developer-tooling
codex plugin add b2c-dx-mcp@b2c-developer-tooling

Start a new Codex session in your project. This setup also works with the Codex IDE extension and the ChatGPT Work desktop app.

Manual MCP setup
bash
codex mcp add b2c-dx-mcp -- npx -y @salesforce/b2c-dx-mcp@latest

Or add this to ~/.codex/config.toml (or $CODEX_HOME/config.toml if customized):

toml
[mcp_servers.b2c-dx-mcp]
command = "npx"
args = ["-y", "@salesforce/b2c-dx-mcp@latest"]

Start a new session. See Codex MCP configuration.

ChatGPT online setup

VS Code

Install the plugin Recommended

  1. Open the Command Palette (Cmd/Ctrl+Shift+P) and run Chat: Install Plugin from Source.
  2. Enter SalesforceCommerceCloud/b2c-developer-tooling.
  3. Select b2c-dx-mcp and follow the installation prompts.
  4. Start a new chat in GitHub Copilot.
Manual MCP setup

Add this to .vscode/mcp.json in your workspace:

json
{
  "servers": {
    "b2c-dx-mcp": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "@salesforce/b2c-dx-mcp@latest"]
    }
  }
}

See VS Code MCP setup.

Copilot CLI setup

Cursor

Reload the MCP server in Cursor after installation.

Manual MCP setup

Add this to .cursor/mcp.json in your project:

json
{
  "mcpServers": {
    "b2c-dx-mcp": {
      "command": "npx",
      "args": ["-y", "@salesforce/b2c-dx-mcp@latest"]
    }
  }
}

For all projects, use ~/.cursor/mcp.json instead.

See Cursor's MCP documentation.

OpenCode

Add this to opencode.json in your project:

json
{
  "mcp": {
    "b2c-dx-mcp": {
      "type": "local",
      "command": ["npx", "-y", "@salesforce/b2c-dx-mcp@latest"],
      "enabled": true
    }
  }
}

Restart OpenCode. For all projects, use ~/.config/opencode/opencode.json. See OpenCode MCP setup.

Gemini

From your project directory, run:

bash
gemini mcp add --scope project b2c-dx-mcp -- npx -y @salesforce/b2c-dx-mcp@latest

Start a new Gemini CLI session. Use --scope user instead for all projects. See Gemini CLI MCP setup.

No separate skills plugins needed.

Other clients and manual setup →
Skip to content
View as Markdown
View as Markdown

@salesforce/b2c-tooling-sdk / operations/metrics / resolveMetricsWindow

Function: resolveMetricsWindow()

resolveMetricsWindow(input, now): ResolvedMetricsWindow

Defined in: packages/b2c-tooling-sdk/src/operations/metrics/index.ts:330

Resolves from/to/window inputs into the concrete bounds to send to the Metrics API. This is the shared resolver for the CLI metrics get command and the MCP metrics_get tool, so both share identical, tested semantics.

The resolver always produces an explicit from+to pair. The Metrics API pairs a request that omits to with its own now and enforces a 24-hour maximum window, so an open-ended from older than 24 hours always fails; to make the behavior predictable, any bound the caller leaves open is filled from the 24-hour default window (see METRICS_DEFAULT_WINDOW_MS) rather than relying on the server's implicit end.

The window duration makes fixed-width lookbacks easy without hand-computing a second timestamp — e.g. "a 1-hour window starting 7 days ago" is {from: '7d', window: '1h'}. Resolution rules:

  • from + to — used as given; window must NOT also be set. An explicit range wider than the 24-hour maximum is still sent as-is, leaving the API to return its own error.
  • from + windowto = from + window.
  • to + windowfrom = to - window.
  • window only — the last window: to = now, from = now - window.
  • from only — a 24-hour window forward from from: to = min(from + 24h, now).
  • to only — a 24-hour window back from to: from = to - 24h.
  • nothing — the last 24 hours: to = now, from = now - 24h.

Bounds filled from the 24-hour default (the last three rules) set ResolvedMetricsWindow.defaultedWindow. Validation is structural (over-specification and from after to). Additionally, a from that lands at or beyond the 30-day retention floor is clamped forward to now - 30 days + margin (see METRICS_RETENTION_SAFETY_MARGIN_MS) so requests like --from 30d are not rejected by the server's own slightly-later clock; the clamp is applied before deriving the companion bound so the window width is preserved, only ever moves from toward now, and is reported via ResolvedMetricsWindow.clampedFrom.

Parameters

input

MetricsWindowInput = {}

The raw from/to/window inputs

now

Date = ...

Reference time for relative bounds, default/window modes, and the retention clamp (defaults to the current time; injectable for deterministic tests)

Returns

ResolvedMetricsWindow

The resolved bounds plus ISO/epoch-second echoes and clamp/default flags

Throws

TypeError if a bound or the window string is unparseable

Throws

RangeError if all three are supplied, or the resolved from is after to

Example

typescript
// A 1-hour window starting 7 days ago:
const w = resolveMetricsWindow({from: '7d', window: '1h'});
await getScapiMetrics(client, tenantId, {from: w.from, to: w.to});