list_variables
Retrieve and display all variables in the current Python REPL session for easy tracking and management of your workspace environment.
Instructions
List all variables in the current session
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/mcp_python/server.py:199-221 (handler)Handler implementation for the 'list_variables' tool. It filters the global namespace to exclude builtins and private variables, formats them as a list, and returns as text content.elif name == "list_variables": # Filter out builtins and private variables vars_dict = { k: repr(v) for k, v in self.global_namespace.items() if not k.startswith('_') and k != '__builtins__' } if not vars_dict: return [ types.TextContent( type="text", text="No variables in current session." ) ] # Format variables list var_list = "\n".join(f"{k} = {v}" for k, v in vars_dict.items()) return [ types.TextContent( type="text", text=f"Current session variables:\n\n{var_list}" ) ]
- src/mcp_python/server.py:51-58 (registration)Registration of the 'list_variables' tool in the list_tools handler, including its name, description, and empty input schema.types.Tool( name="list_variables", description="List all variables in the current session", inputSchema={ "type": "object", "properties": {}, }, ),
- src/mcp_python/server.py:54-57 (schema)Input schema definition for the 'list_variables' tool, which requires no parameters.inputSchema={ "type": "object", "properties": {}, },