sessions_state
Retrieve the current state of a debug session to monitor execution status, breakpoints, and variable values 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)Main execution handler for the 'sessions_state' MCP tool. Extracts sessionId from arguments, fetches state from SessionManager, serializes to JSON, and returns as TextContent or appropriate error responses.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-148 (schema)JSON schema defining the input parameters for the 'sessions_state' tool: requires a 'sessionId' string.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"], }, ), Tool(
- src/mcp_debug_tool/server.py:216-217 (registration)Dispatch logic in the generic call_tool handler that routes 'sessions_state' calls to the specific _handle_sessions_state method.elif name == "sessions_state": return await self._handle_sessions_state(arguments)
- Async wrapper method in SessionManager that delegates to synchronous get_state, used by the tool handler.async def get_state_async(self, session_id: str) -> SessionStateResponse: """ Async wrapper for get_state. Runs the synchronous get_state in a thread pool to avoid blocking. """ return await asyncio.to_thread(self.get_state, session_id)
- Core method in SessionManager that retrieves the DebugSession by ID and returns its state as SessionStateResponse via to_state_response().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()