sessions_state
Retrieve the current state of a debug session to inspect variables, breakpoints, and execution status during Python debugging.
Instructions
Get the current state of a debug session
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | The debug session ID |
Implementation Reference
- src/mcp_debug_tool/server.py:443-497 (handler)The primary handler function for the 'sessions_state' MCP tool. It validates the sessionId argument, retrieves the session state asynchronously from SessionManager, serializes it to JSON, and returns it as TextContent. Handles errors like missing sessionId, session not found, and general exceptions.async def _handle_sessions_state(self, arguments: dict) -> list[TextContent]: """ Handler for sessions_state tool. Gets the current state of a debug session. """ try: session_id = arguments.get("sessionId") if not session_id: return [ TextContent( type="text", text=json.dumps({ "error": { "type": "ValueError", "message": "sessionId is required", } }), ) ] state = await self.session_manager.get_state_async(session_id) result = state.model_dump() return [ TextContent( type="text", text=json.dumps(result), ) ] except KeyError as e: return [ TextContent( type="text", text=json.dumps({ "error": { "type": "SessionNotFound", "message": str(e), } }), ) ] except Exception as e: logger.exception("Error getting session state") return [ TextContent( type="text", text=json.dumps({ "error": { "type": type(e).__name__, "message": str(e), } }), ) ]
- src/mcp_debug_tool/server.py:134-147 (schema)Input schema definition for the sessions_state tool, specifying that a 'sessionId' string is required.Tool( name="sessions_state", description="Get the current state of a debug session", inputSchema={ "type": "object", "properties": { "sessionId": { "type": "string", "description": "The debug session ID", }, }, "required": ["sessionId"], }, ),
- src/mcp_debug_tool/server.py:216-217 (registration)Tool dispatch registration in the call_tool handler, routing 'sessions_state' calls to the specific handler method.elif name == "sessions_state": return await self._handle_sessions_state(arguments)
- Core helper method in SessionManager that retrieves the DebugSession by ID and converts it to a SessionStateResponse using the session's to_state_response() method. This is called via the async wrapper from the tool handler.def get_state(self, session_id: str) -> SessionStateResponse: """ Get current session state. Args: session_id: Session ID Returns: Current state response """ session = self.get_session(session_id) return session.to_state_response()