UNPKG

@debugmcp/mcp-debugger

Version:

Run-time step-through debugging for LLM agents.

124 lines (98 loc) 3.73 kB
# Structured Logging Implementation Summary ## Overview Successfully implemented structured logging for the MCP Debugger to enable visualization of debugging activity. All debugging tools and state changes now emit structured JSON logs that can be parsed by a Terminal UI visualizer. ## Implementation Details ### 1. Logging Format Specification Created comprehensive documentation at `docs/logging-format-specification.md` that defines: - JSON schema for each log type - Field definitions and data types - Truncation rules for large values - Parsing guidelines for TUI implementation ### 2. Code Changes #### Server.ts - Added helper methods for sanitizing request data and getting session names - Implemented structured logging for all tool handlers: - `tool:call` - Logs when any MCP tool is invoked - `tool:response` - Logs successful tool completion - `tool:error` - Logs tool errors - `session:created` - Logs new session creation - `session:closed` - Logs session termination #### Session-manager.ts - Added structured logging for debug state changes: - `debug:state` with event types: paused, running, stopped - `debug:breakpoint` with event type: verified - Enhanced event handlers to emit structured logs #### Logger.ts - No changes needed - existing Winston logger already supports structured logging ### 3. Log Entry Types Implemented 1. **Tool Logs** - `tool:call` - Tool invocation with sanitized parameters - `tool:response` - Successful tool execution - `tool:error` - Tool execution failures 2. **Session Logs** - `session:created` - New debug session created - `session:closed` - Debug session terminated 3. **Debug State Logs** - `debug:state` - Debugger state changes (paused/running/stopped) 4. **Breakpoint Logs** - `debug:breakpoint` - Breakpoint lifecycle events (set/verified) 5. **Variable Logs** - `debug:variables` - Variable inspection with truncated values ### 4. Test Verification Created test script `tests/manual/verify-structured-logging.js` that confirms: - All log types are properly formatted - Numeric timestamps are included - Log structure matches specification - JSON parsing works correctly Test output shows SUCCESS with all expected log types present. ## Sample Log Entries ### Tool Call ```json { "level": "info", "message": "tool:call", "namespace": "debug-mcp:tools", "tool": "create_debug_session", "sessionId": undefined, "sessionName": undefined, "request": { "language": "python", "name": "Test Session" }, "timestamp": 1750579042980 } ``` ### Debug State Change ```json { "level": "info", "message": "debug:state", "namespace": "debug-mcp:state", "event": "paused", "sessionId": "test-session-123", "sessionName": "Test Session", "reason": "breakpoint", "location": { "file": "test.py", "line": 10, "function": "main" }, "threadId": 1, "timestamp": 1750579042984 } ``` ## Success Criteria Met ✅ All debugging tools log both request and response ✅ Debug state changes (paused/running/stopped) are logged ✅ Breakpoint events are logged with file and line info ✅ Variable inspections include the data retrieved ✅ All logs follow consistent JSON structure with timestamps ✅ Log entries include sessionId for correlation ✅ No sensitive information (passwords, tokens) in logs ✅ Test script confirms structured logs are created ## Next Steps The structured logging is now ready for: 1. TUI Visualizer implementation (Task 3) 2. Log watcher integration (Task 4) 3. Real-time debugging activity monitoring The logs are written to `logs/debug-mcp-server.log` in JSON format, one entry per line, making it easy to tail and parse for visualization.