list_variables
View all variables currently defined in the Python REPL session to track and manage your workspace.
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-222 (handler)Handler implementation for the 'list_variables' tool. It filters and lists variables from the global namespace, excluding builtins and private variables, formatting them for output.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 for the 'list_variables' tool, which requires no parameters.inputSchema={ "type": "object", "properties": {}, },