Install AI Tools

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

Claude

Using Claude Desktop? See Claude Desktop (Cowork) setup.

Install the plugin Recommended

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

Start a new Claude Code session. To install for the current project only, run it from your project directory with --scope project.

Manual MCP setup
bash
claude mcp add --transport stdio --scope user b2c-dx-mcp -- npx -y @salesforce/b2c-dx-mcp@latest

Start a new session. To configure the current project only, run it from your project directory with --scope project. See Claude Code MCP setup.

Codex/ChatGPT

Using the ChatGPT desktop app (ChatGPT Work)? See ChatGPT Work setup.

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. Codex plugins also work in ChatGPT Work.

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.

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

Run:

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

Start a new Gemini CLI session. To configure the current project only, run it from your project directory with --scope project. See Gemini CLI MCP setup.

No separate skills plugins needed.

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

b2c_tooling_sdk.operations.metrics ​

Metrics operations for B2C Commerce (Observability).

Mirrors src/operations/metrics/index.ts. Provides typed, high-level functions for retrieving operational time-series metrics from the SCAPI Observability Metrics API (observability/metrics/v1). Each metric category has its own function; all return the same metrics-data-response envelope (as raw JSON dict).

Categories:

get_metrics_by_category dispatches to the correct function by category name.

The Metrics API wire format is epoch seconds; these operations convert millisecond inputs to seconds on the way out and normalize response timestamps back to milliseconds on the way in.

Authentication requires OAuth client-credentials with the sfcc.metrics admin scope, attached automatically by create_metrics_client.

Classes ​

MetricsQueryOptions ​

python
class MetricsQueryOptions(MetricsTimeWindow)

Union of every option shape accepted by get_metrics_by_category.

Fields

NameTypeDefault
third_party_service_idstr | NoneNone
api_familystr | NoneNone
api_namestr | NoneNone
ocapi_categorystr | NoneNone
ocapi_apistr | NoneNone

MetricsTagContext ​

python
class MetricsTagContext

The request identity and applied filters used to derive authoritative tags.

realm/environment are parsed from tenant_id. The optional filter fields mirror the Metrics API's category filters; when a filter was sent, that dimension is known from the request and is stamped onto every series as an authoritative tag — rather than being (mis)parsed from a drilled-down series id.

Fields

NameTypeDefault
tenant_idstr
api_familystr | NoneNone
api_namestr | NoneNone
ocapi_categorystr | NoneNone
ocapi_apistr | NoneNone
third_party_service_idstr | NoneNone

MetricsTimeWindow ​

python
class MetricsTimeWindow

Time-window options common to every metrics operation.

Accepts either a datetime or a number of epoch milliseconds (the same unit as Date.now()) for both from_ and to. Both optional; when omitted the API applies its default window.

Fields

NameTypeDefault
from_datetime | int | float | NoneNone
todatetime | int | float | NoneNone

MetricsWindowInput ​

python
class MetricsWindowInput

Raw from/to/window inputs before resolution. Any subset may be provided.

Fields

NameTypeDefault
from_MetricsBoundInput | NoneNone
toMetricsBoundInput | NoneNone
windowint | str | NoneNone

OcapiMetricsOptions ​

python
class OcapiMetricsOptions(MetricsTimeWindow)

Options for get_ocapi_metrics: time window plus optional OCAPI filters.

Fields

NameTypeDefault
ocapi_categorystr | NoneNone
ocapi_apistr | NoneNone

ResolvedMetricsWindow ​

python
class ResolvedMetricsWindow

A resolved metrics window. Both from_ and to are always present.

Fields

NameType
from_datetime
todatetime
from_isostr
to_isostr
from_epoch_secondsint
to_epoch_secondsint
clamped_frombool
defaulted_windowbool

ScapiMetricsOptions ​

python
class ScapiMetricsOptions(MetricsTimeWindow)

Options for get_scapi_metrics: time window plus optional SCAPI filters.

Fields

NameTypeDefault
api_familystr | NoneNone
api_namestr | NoneNone

ThirdPartyMetricsOptions ​

python
class ThirdPartyMetricsOptions(MetricsTimeWindow)

Options for get_third_party_metrics: time window plus a service filter.

Fields

NameTypeDefault
third_party_service_idstr | NoneNone

Functions ​

enrich_metrics_tags ​

python
def enrich_metrics_tags(response: dict[str, Any], category: MetricCategory, context: MetricsTagContext) -> MetricsTaggedResponse

Enrich a metrics response by adding a structured tags map to every series.

Returns a new response (the input is not mutated). Walks every metric and series and attaches series["tags"] derived from the series id, the metric id, the category, and the request context. Existing fields (id, name, data) are preserved exactly, so the enriched response is a structural superset. The category must be supplied because a metrics response does not carry it (it is implied by the endpoint that produced the response).

get_controller_metrics ​

python
async def get_controller_metrics(client: MetricsClient, tenant_id: str, options: MetricsTimeWindow | None = None) -> dict[str, Any]

Retrieve controller/pipeline metrics for an organization.

Raises

  • RuntimeError — if the request fails.

get_ecdn_metrics ​

python
async def get_ecdn_metrics(client: MetricsClient, tenant_id: str, options: MetricsTimeWindow | None = None) -> dict[str, Any]

Retrieve embedded CDN (eCDN) metrics for an organization.

Raises

  • RuntimeError — if the request fails.

get_metrics_by_category ​

python
async def get_metrics_by_category(client: MetricsClient, tenant_id: str, category: MetricCategory, options: MetricsQueryOptions | None = None) -> dict[str, Any]

Retrieve metrics for a category by name, dispatching to the category-specific function.

Category-specific filters are applied only for the categories that support them and ignored otherwise.

Raises

  • RuntimeError — if the request fails.
  • ValueError — if the category is unknown.

get_mrt_metrics ​

python
async def get_mrt_metrics(client: MetricsClient, tenant_id: str, options: MetricsTimeWindow | None = None) -> dict[str, Any]

Retrieve Managed Runtime (MRT) metrics for an organization.

Raises

  • RuntimeError — if the request fails.

get_ocapi_metrics ​

python
async def get_ocapi_metrics(client: MetricsClient, tenant_id: str, options: OcapiMetricsOptions | None = None) -> dict[str, Any]

Retrieve OCAPI request metrics for an organization.

Raises

  • RuntimeError — if the request fails.

get_overall_metrics ​

python
async def get_overall_metrics(client: MetricsClient, tenant_id: str, options: MetricsTimeWindow | None = None) -> dict[str, Any]

Retrieve overall application metrics for an organization.

Raises

  • RuntimeError — if the request fails.

get_sales_metrics ​

python
async def get_sales_metrics(client: MetricsClient, tenant_id: str, options: MetricsTimeWindow | None = None) -> dict[str, Any]

Retrieve sales metrics for an organization.

Raises

  • RuntimeError — if the request fails.

get_scapi_hooks_metrics ​

python
async def get_scapi_hooks_metrics(client: MetricsClient, tenant_id: str, options: MetricsTimeWindow | None = None) -> dict[str, Any]

Retrieve SCAPI hook execution metrics for an organization.

Raises

  • RuntimeError — if the request fails.

get_scapi_metrics ​

python
async def get_scapi_metrics(client: MetricsClient, tenant_id: str, options: ScapiMetricsOptions | None = None) -> dict[str, Any]

Retrieve SCAPI request metrics for an organization.

Raises

  • RuntimeError — if the request fails.

get_third_party_metrics ​

python
async def get_third_party_metrics(client: MetricsClient, tenant_id: str, options: ThirdPartyMetricsOptions | None = None) -> dict[str, Any]

Retrieve third-party service call metrics for an organization.

Raises

  • RuntimeError — if the request fails.

parse_metrics_bound ​

python
def parse_metrics_bound(value: MetricsBoundInput, now: datetime | None = None) -> datetime

Parse a single metrics time bound (from or to) into a datetime.

Resolves a single bound in isolation; deriving the companion bound and applying the 24-hour default window is the job of resolve_metrics_window.

Parameters

NameTypeDescription
valueMetricsBoundInputThe bound: a datetime, epoch milliseconds, a relative duration (5m/1h/2d, relative to now), or an ISO 8601 timestamp.
nowdatetime | NoneReference time for relative durations (defaults to the current time; injectable for deterministic tests).

Raises

  • ValueError — if a string value is neither a valid relative duration nor a parseable ISO 8601 timestamp.

parse_series_tags ​

python
def parse_series_tags(*, category: MetricCategory, metric_id: str, series_id: str, context: MetricsTagContext) -> MetricSeriesTags

Extract the dimension tags for a single series id.

Combines three tiers, most-authoritative last:

  1. Request identity — realm/environment from the tenant id.
  2. String heuristics — category/metric-specific dimensions parsed from the packed id, or the raw remainder under series when no rule matches.
  3. Applied filters — any filter that was sent with the request (MetricsTagContext) is stamped last, overriding a heuristic guess.

The result is always a superset of the request context and never throws.

resolve_metrics_window ​

python
def resolve_metrics_window(input: MetricsWindowInput | None = None, now: datetime | None = None) -> ResolvedMetricsWindow

Resolve from/to/window inputs into concrete bounds for the Metrics API.

Always produces an explicit from_+to pair. Resolution rules:

  • from + to — used as given; window must NOT also be set.
  • from + window — to = from + window.
  • to + window — from = to - window.
  • window only — the last window: to = now, from = now - window.
  • from only — a 24-hour window forward: to = min(from + 24h, now).
  • to only — a 24-hour window back: from = to - 24h.
  • nothing — the last 24 hours.

A from at or beyond the 30-day retention floor is clamped forward to now - 30 days + margin so requests like --from 30d are not rejected by the server's slightly-later clock.

Parameters

NameTypeDescription
inputMetricsWindowInput | NoneThe raw from/to/window inputs.
nowdatetime | NoneReference time for relative bounds, default/window modes, and the retention clamp (defaults to the current time; injectable for tests).

Raises

  • ValueError — if a bound or the window string is unparseable, if all three are supplied, or if the resolved from is after to.

Attributes ​

METRICS_DEFAULT_WINDOW_MS ​

python
METRICS_DEFAULT_WINDOW_MS = 24 * 60 * 60 * 1000

METRICS_RETENTION_MS ​

python
METRICS_RETENTION_MS = 30 * 24 * 60 * 60 * 1000

METRICS_RETENTION_SAFETY_MARGIN_MS ​

python
METRICS_RETENTION_SAFETY_MARGIN_MS = 5 * 60 * 1000

METRIC_CATEGORIES ​

python
METRIC_CATEGORIES: tuple[str, ...] = ('overall', 'sales', 'ecdn', 'third-party', 'scapi', 'scapi-hooks', 'mrt', 'controller', 'ocapi')

MetricCategory ​

python
MetricCategory = Literal['overall', 'sales', 'ecdn', 'third-party', 'scapi', 'scapi-hooks', 'mrt', 'controller', 'ocapi']

MetricSeriesTags ​

python
MetricSeriesTags = dict[str, str]

MetricsBoundInput ​

python
MetricsBoundInput = datetime | int | float | str

MetricsTaggedResponse ​

python
MetricsTaggedResponse = dict[str, Any]