Skip to content
View as Markdown
View as Markdown

Script Debugger

MCP tools for connecting to the B2C Commerce Script Debugger API (SDAPI), setting breakpoints, inspecting variables, and stepping through server-side code. Part of the DIAGNOSTICS toolset (always enabled), and also 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 — either the account password or a WebDAV File Access and UX Studio access key — for a user with the WebDAV_Manage_Customization permission.

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

See Configuration for complete credential setup details including flags and environment variables. See Authentication Setup for 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. MCP-owned debugger identity — the MCP server assigns the debugger client identity internally; callers do not configure or track it.
  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 local session state. Any orphaned debugger slot on the instance is freed by SDAPI's own timeout.

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
projectDirectorystringNoServer project directory/cwdProject root used to load .env/dw.json and resolve relative paths. Overrides the server-level directory; run config_inspect to see the resolved paths.
configPathstringNoResolved from project contextPrimary dw.json-format configuration file. Relative paths resolve from projectDirectory; the shared default remains available.
instanceNamestringNoActive/default instanceNamed instance selected from the primary configuration first, then the shared default dw.json.
cartridgeDirectorystringNoprojectDirectoryCartridge discovery and source-mapping root only. Use when cartridges are outside the project root; relative paths resolve from project root.

Returns: session_id, hostname, discovered cartridges, resolution, and warnings. The session retains its resolution context; debug_list_sessions returns it for later follow-up calls.

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, any currently halted threads, and armed breakpoints.

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.