list_sessions
View all active Python REPL sessions to monitor and manage code execution environments within the MCP Python Interpreter.
Instructions
List all active REPL sessions.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- mcp_python_interpreter/server.py:886-898 (handler)The handler function for the 'list_sessions' tool. It iterates over the global _sessions dictionary and formats a string listing each session's ID, history length, and count of non-magic variables in its locals.@mcp.tool() def list_sessions() -> str: """List all active REPL sessions.""" if not _sessions: return "No active sessions." result = "Active REPL Sessions:\n\n" for session_id, session in _sessions.items(): result += f"- Session: {session_id}\n" result += f" History entries: {len(session.history)}\n" result += f" Variables: {len([k for k in session.locals.keys() if not k.startswith('__')])}\n\n" return result