Skip to main content
Glama
yzfly

MCP Python Interpreter

by yzfly

list_python_environments

Discover available Python environments including system Python and conda environments to manage and select appropriate interpreters for code execution.

Instructions

List all available Python environments (system Python and conda environments).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The primary handler function for the 'list_python_environments' tool. Decorated with @mcp.tool(), it calls get_python_environments() to retrieve the list of environments and formats them into a human-readable string output.
    @mcp.tool()
    def list_python_environments() -> str:
        """List all available Python environments (system Python and conda environments)."""
        environments = get_python_environments()
        
        if not environments:
            return "No Python environments found."
        
        result = "Available Python Environments:\n\n"
        for env in environments:
            result += f"- Name: {env['name']}\n"
            result += f"  Path: {env['path']}\n"
            result += f"  Version: Python {env['version']}\n\n"
        
        return result
  • Supporting helper function get_python_environments() that discovers available Python environments (system, default, and conda) by running subprocess commands to gather paths and versions.
    def get_python_environments() -> List[Dict[str, str]]:
        """Get all available Python environments."""
        environments = []
        
        if DEFAULT_PYTHON_PATH != sys.executable:
            try:
                result = subprocess.run(
                    [DEFAULT_PYTHON_PATH, "-c", "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}')"],
                    capture_output=True, text=True, check=True, timeout=10,
                    stdin=subprocess.DEVNULL,
                    creationflags=subprocess.CREATE_NO_WINDOW if sys.platform == "win32" else 0
                )
                version = result.stdout.strip()
                
                environments.append({
                    "name": "default",
                    "path": DEFAULT_PYTHON_PATH,
                    "version": version
                })
            except Exception as e:
                print(f"Error getting version for custom Python path: {e}", file=sys.stderr)
        
        environments.append({
            "name": "system",
            "path": sys.executable,
            "version": f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}"
        })
        
        # Try conda environments
        try:
            result = subprocess.run(
                ["conda", "info", "--envs", "--json"],
                capture_output=True, text=True, check=False, timeout=10,
                stdin=subprocess.DEVNULL,
                creationflags=subprocess.CREATE_NO_WINDOW if sys.platform == "win32" else 0
            )
            
            if result.returncode == 0:
                conda_info = json.loads(result.stdout)
                for env in conda_info.get("envs", []):
                    env_name = os.path.basename(env)
                    if env_name == "base":
                        env_name = "conda-base"
                    
                    python_path = os.path.join(env, "bin", "python")
                    if not os.path.exists(python_path):
                        python_path = os.path.join(env, "python.exe")
                    
                    if os.path.exists(python_path):
                        try:
                            version_result = subprocess.run(
                                [python_path, "-c", "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}')"],
                                capture_output=True, text=True, check=True, timeout=10,
                                stdin=subprocess.DEVNULL,
                                creationflags=subprocess.CREATE_NO_WINDOW if sys.platform == "win32" else 0
                            )
                            version = version_result.stdout.strip()
                            
                            environments.append({
                                "name": env_name,
                                "path": python_path,
                                "version": version
                            })
                        except Exception:
                            pass
        except Exception as e:
            print(f"Error getting conda environments: {e}", file=sys.stderr)
        
        return environments
  • The @mcp.tool() decorator on the handler function serves as the tool registration in the MCP framework.
    @mcp.tool()
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states what the tool does but doesn't describe behavioral traits such as whether it requires specific permissions, how it handles errors, what the output format looks like, or if there are any rate limits. This leaves significant gaps for a tool that interacts with system environments.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose without any wasted words. It directly states the action and scope, making it easy to parse and understand quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has 0 parameters, 100% schema coverage, and an output schema exists, the description is minimally adequate. However, as a tool that lists system-level resources with no annotations, it should ideally provide more context about output structure or usage constraints to be fully complete for an AI agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has 0 parameters, and schema description coverage is 100%, so no parameter documentation is needed. The description appropriately doesn't discuss parameters, earning a baseline score of 4 for not adding unnecessary information.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('List') and resource ('Python environments'), specifying both system Python and conda environments. It distinguishes from some siblings like list_directory or list_sessions by focusing on Python environments specifically, though it doesn't explicitly differentiate from all potential alternatives.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites, context for usage, or compare with siblings like list_installed_packages or list_sessions, leaving the agent to infer usage scenarios independently.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/yzfly/mcp-python-interpreter'

If you have feedback or need assistance with the MCP directory API, please join our Discord server