Skip to content
View as Markdown
View as Markdown

Diagnostics Tools

MCP tools for connecting to the B2C Commerce Script Debugger API (SDAPI), setting breakpoints, inspecting variables, and stepping through server-side code. These tools are available in the CARTRIDGES and SCAPI toolsets.

Authentication

Requires Basic Auth credentials only. OAuth is not supported by the SDAPI.

Required:

  • Basic Auth - hostname, username, and password (WebDAV access key) for a Business Manager user with the WebDAV_Manage_Customization permission.

Configuration priority: Flags → Environment variables → dw.json config file

The script debugger must also be enabled on the instance: Business Manager > Administration > Development Configuration > Script Debugger > Enable.

See Configuration for complete credential setup details including flags and environment variables. See Authentication Setup for WebDAV access key configuration instructions.

Recovery from broken or orphaned sessions

Debug sessions are stateful and live in the MCP server process. If the agent loses track of an active session (context flush, crash, restart), or breakpoints stop firing as expected:

  1. List active sessions — call debug_list_sessions (no args). It returns all sessions known to the server with their session_id, hostname, halted threads, and currently armed breakpoints.
  2. End orphaned sessions — call debug_end_session with the session_id to free the debugger slot on the instance.
  3. SDAPI single-client guarantee — the script debugger only supports one client per client_id per host. Calling debug_start_session with the same client_id against the same host implicitly takes over (replaces) any prior client. This is the safety net when a session is lost without a clean shutdown.
  4. Idle cleanup — sessions inactive for 30 minutes are automatically cleaned up by the server.
  5. Restart the MCP server — as a last resort, restarting the MCP server destroys all session state. The orphaned debugger slot on the instance will be freed by SDAPI's own 60-second halt-timeout or by the next debug_start_session with the same client ID.

Session Lifecycle

debug_start_session

Start a new script debugger session. Connects to the SDAPI, discovers cartridge mappings, and begins polling for halted threads.

Warning: Debug sessions can halt remote request threads on the instance. Use debug_end_session to cleanly disconnect when done.

ParameterTypeRequiredDefaultDescription
cartridge_directorystringNoProject directoryPath to directory containing cartridges
client_idstringNob2c-cliClient ID for the debugger API. Use a different ID for concurrent sessions on the same host.

Returns: session_id, hostname, discovered cartridges, and warnings.

debug_end_session

End a script debugger session. Disconnects from the SDAPI, stops polling, and cleans up resources.

ParameterTypeRequiredDefaultDescription
session_idstringYesSession ID from debug_start_session
clear_breakpointsbooleanNofalseDelete all breakpoints before disconnecting

debug_list_sessions

List all active debug sessions. Returns session IDs, connected hostnames, and any currently halted threads.

No parameters.


Breakpoints

debug_set_breakpoints

Set breakpoints in a debug session. Replaces all previously set breakpoints.

Accepts local file paths (mapped to server paths via cartridge discovery), cartridge-prefixed paths (e.g. app_storefront/cartridge/controllers/Cart.js), or server paths starting with /.

ParameterTypeRequiredDescription
session_idstringYesSession ID from debug_start_session
breakpointsarrayYesArray of {file, line, condition?} objects

Each breakpoint object:

FieldTypeRequiredDescription
filestringYesLocal file path, cartridge-prefixed path, or server script path
linenumberYesLine number
conditionstringNoConditional expression — breakpoint only triggers when true

Execution Control

debug_wait_for_stop

Wait for a thread to halt at a breakpoint or step. Returns immediately if a thread is already halted. Otherwise blocks until a halt occurs or the timeout expires — the user or an external process must trigger a request on the instance while this tool is waiting.

ParameterTypeRequiredDefaultDescription
session_idstringYesSession ID
timeout_msnumberNo30000Timeout in milliseconds (max 120000)

Returns: {halted, thread_id, location} or {halted: false, timed_out: true}.

debug_continue

Resume execution of a halted thread.

ParameterTypeRequiredDescription
session_idstringYesSession ID
thread_idnumberYesThread ID of the halted thread

debug_step_over

Step to the next line in the current function. Follow with debug_wait_for_stop.

ParameterTypeRequiredDescription
session_idstringYesSession ID
thread_idnumberYesThread ID

debug_step_into

Step into the function call on the current line. Follow with debug_wait_for_stop.

ParameterTypeRequiredDescription
session_idstringYesSession ID
thread_idnumberYesThread ID

debug_step_out

Step out of the current function, returning to the caller. Follow with debug_wait_for_stop.

ParameterTypeRequiredDescription
session_idstringYesSession ID
thread_idnumberYesThread ID

Inspection

debug_get_stack

Get the call stack for a halted thread. Returns stack frames with mapped local file paths and server script paths.

ParameterTypeRequiredDescription
session_idstringYesSession ID
thread_idnumberYesThread ID

debug_get_variables

Get variables for a stack frame in a halted thread.

ParameterTypeRequiredDefaultDescription
session_idstringYesSession ID
thread_idnumberYesThread ID
frame_indexnumberNo0Stack frame index (0 = top frame)
scopestringNoAll scopesFilter by local, closure, or global
object_pathstringNoDot-delimited path to drill into an object (e.g. request.httpParameters)

debug_evaluate

Evaluate an expression in the context of a halted thread and stack frame.

Warning: Expressions can have side effects (modify variables, call functions). Use with care.

ParameterTypeRequiredDefaultDescription
session_idstringYesSession ID
thread_idnumberYesThread ID
frame_indexnumberNo0Stack frame index
expressionstringYesJavaScript expression to evaluate

Higher-Level Tools

debug_capture_at_breakpoint

Set a breakpoint, wait for it to be hit, and capture a diagnostic snapshot — stack, variables, and optional expression results in a single call. Optionally resumes the thread after capture.

Important: This tool blocks until the breakpoint is hit or the timeout expires. The user or an external process must trigger a request on the instance while this tool is waiting.

ParameterTypeRequiredDefaultDescription
session_idstringYesSession ID
filestringYesFile path for the breakpoint
linenumberYesLine number
conditionstringNoConditional expression
expressionsstring[]NoExpressions to evaluate when hit
timeout_msnumberNo30000Timeout waiting for the breakpoint (max 120000)
auto_continuebooleanNofalseResume the thread after capturing

See Also

Released under the Apache-2.0 License.