Add script debugger MCP tools, CLI REPL, and RPC mode#395
Conversation
- Add 13 MCP debug tools (debug_start_session, debug_set_breakpoints, debug_wait_for_stop, debug_get_stack, debug_get_variables, debug_evaluate, debug_continue, debug_step_over/into/out, debug_end_session, debug_list_sessions, debug_capture_at_breakpoint) to CARTRIDGES, SCAPI, and STOREFRONTNEXT toolsets - Add ServerContext for persistent server-scoped state across MCP tool invocations (debug sessions, future log watches) - Add DebugSessionRegistry with TTL cleanup and multi-session support - Add `b2c debug cli` command with interactive REPL and --rpc mode for JSONL-over-stdio headless/agent integration - Add resolveBreakpointPath utility in SDK for flexible path normalization (server paths, local paths, cartridge-prefixed paths) - Add debug command docs and b2c-debug agent skill
Group debug tools on a single Diagnostics page instead of individual pages. Add Diagnostics sub-heading under MCP Tools in the sidebar for future tools like log tailing.
Organize into Cartridges, SCAPI, PWA Kit, Storefront Next, and Diagnostics sub-groups.
Make it explicit in tool descriptions and docs that these tools block until a breakpoint is hit or timeout expires, and that the caller must trigger a request externally while waiting.
1. capture_at_breakpoint: add trigger_url parameter so the tool can fire the HTTP request itself after arming the breakpoint, avoiding the blocking coordination problem with LLM tool-calling. 2. set_breakpoints: surface warnings when a path cannot be round-trip mapped back to a local file. Set verified=false for unmapped paths instead of silently accepting them. 3. Tool descriptions: steer toward the non-blocking workflow (set_breakpoints → trigger → list_sessions → inspect) rather than leading with blocking tools. 4. list_sessions: include active breakpoints with resolved server paths so agents can inspect what's armed on the server. 5. start_session: return cartridge_mappings (name → local path) so agents can verify cartridge discovery and path mapping.
Absolute local paths like /Users/.../app_mysite/cartridge/controllers/Loyalty.js start with / and were returned as-is (treated as server paths) before the source mapper had a chance to map them. Now the source mapper runs first — if it matches, the local path is correctly converted to a server path. The / passthrough only applies if the mapper doesn't match.
The new debug tools have no unit tests yet (they require mocking the DebugSessionManager and SDAPI). Excluding from coverage until tests are added to avoid blocking the draft PR.
Tests cover DebugSessionRegistry (register, duplicate rejection, get, destroy, halt waiter cleanup) and tool handlers (list_sessions, end_session, continue, get_stack, evaluate). Diagnostics tools excluded from coverage threshold until full coverage is added.
patricksullivansf
left a comment
There was a problem hiding this comment.
fun stuff
probably needs a type check before merging as it seems it has an unfinished refactor.
the docs might benefit from a round of global consistency and cross linking.
i see lots of new to me MCP patterns that are worth looking into more carefully.
| {text: 'sfnext_add_page_designer_decorator', link: '/mcp/tools/sfnext-add-page-designer-decorator'}, | ||
| {text: 'sfnext_configure_theme', link: '/mcp/tools/sfnext-configure-theme'}, | ||
| { | ||
| text: 'Cartridges', |
There was a problem hiding this comment.
no strong opinion, but given that the same tool shows up in different auto-detected configurations will this grouping by names that mirror toolset names cause more confusion?
There was a problem hiding this comment.
maybe. I was going for the primary toolset of the tools for the tertiary organization here. I do think we will need more doc refactor here
There was a problem hiding this comment.
given this is a stateful mcp tool we should probably include explicit how to stop and recover from a broken debugging session (which i assume is kill and restart your MCP server?). For example, if the agent context gets flushed it won't remember anything about the active debug session and maybe that's an issue?
There was a problem hiding this comment.
It is an issue but that's the point of the list_sessions tool. We also have the benefit that the SDAPI only supports 1 connection so a new debug session WILL overwrite the older.
Covers all 13 debug tool handlers including set_breakpoints (path mapping + warnings), get_variables (scope filtering, object_path, truncation), wait_for_stop (immediate halt, timeout, waiter resolution), capture_at_breakpoint (full orchestration, trigger_url, eval errors, timeout), start_session (real fixture cartridge + stubbed manager), and all step_* variants. Registry tests cover idle cleanup and disconnect error swallowing. Coverage is now 99.81% statements/lines, 94.65% branches, 98.94% functions — meeting all thresholds without excluding diagnostics.
…pdates Tier 1 cleanup based on PR review feedback (patricksullivansf, yhsieh1) and self-review. DRY: - Extract shared projection helpers to SDK (projections.ts): truncateValue, isPrimitiveType, projectFrame, projectVariable, projectBreakpoint, projectThreadLocation, plus exported types MappedFrame/MappedVariable/MappedBreakpoint/MappedLocation. Used by both MCP debug tools and CLI RPC mode — eliminates 5+ copies of the same projection code and the MAX_VALUE_LENGTH/PRIMITIVE_TYPES constants. - Add getSessionEntry/getRegistry helpers to session-registry. Replace the 4-line "registry not available" + getSessionOrThrow boilerplate in 11 tools. - Move halt-waiter promise pattern into DebugSessionRegistry.waitForHalt. Used by debug_wait_for_stop and debug_capture_at_breakpoint instead of duplicating the promise/timer/cleanup logic. - Replace step-action switch with a lookup map. API: - DebugSessionRegistry.registerSession now takes an options object (yhsieh1 nit) instead of 5 positional parameters. Docs: - Add "Recovery from broken or orphaned sessions" section to docs/mcp/tools/diagnostics.md (patricksullivansf concern). - Link to main authentication and configuration guides. - Add JSDoc to ServerContext explaining stdio-per-client isolation vs shared transport caveats (patricksullivansf concern). Tool descriptions (yhsieh1 audit): - Drop user-facing prose, sharpen for agent consumption. - debug_start_session: explicitly mention SFRA controllers, custom API scripts, hooks, jobs as use cases. - debug_end_session: IMPORTANT call-out to always end sessions. Coverage stays at 99.81% statements/lines, 94.81% branches, 98.93% functions — all above thresholds.
Match the cartridge-deploy.md pattern: structured Required block, Configuration priority line, link to ../configuration (MCP config) and ../../guide/authentication#webdav-access (main auth guide with WebDAV anchor).
# Conflicts: # docs/cli/debug.md
|
@patricksullivansf @yhsieh1 thanks for the review. got to most things and coverage should be at |
Summary
b2c debug cli— interactive REPL for terminal-based debugging with--rpcflag for JSONL-over-stdio headless/agent integrationresolveBreakpointPath— SDK utility that normalizes file paths for breakpoints (server paths, local paths, cartridge-name-prefixed paths)debugger use case
debugger use case alt

sidebar refactor

Test plan
test-rpc-debug.shend-to-end via JSONL stdin/stdout