Skip to main content
Glama
yzfly

MCP Python Interpreter

by yzfly

run_python_code

Execute Python code with flexible execution modes including inline for speed and subprocess for isolation. Use to run Python scripts, test code snippets, or maintain session state across executions.

Instructions

Execute Python code with flexible execution modes.

Args:
    code: Python code to execute
    execution_mode: Execution mode - "inline" (default, fast, in-process) or "subprocess" (isolated)
    session_id: Session ID for inline mode to maintain state across executions
    environment: Python environment name (only for subprocess mode)
    save_as: Optional filename to save the code before execution
    timeout: Maximum execution time in seconds (only enforced for subprocess mode)

Returns:
    Execution result with output

Execution modes:
- "inline" (default): Executes code in the current process. Fast and reliable,
  maintains session state. Use for most code execution tasks.
- "subprocess": Executes code in a separate Python process. Use when you need
  environment isolation or a different Python environment.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYes
execution_modeNoinline
session_idNodefault
environmentNosystem
save_asNo
timeoutNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes
Behavior4/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 effectively describes key traits: execution modes with their characteristics (speed, isolation, state persistence), timeout enforcement specifics, and session state maintenance. However, it doesn't mention security implications, error handling, or resource limits.

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

Conciseness4/5

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

The description is well-structured with clear sections (Args, Returns, Execution modes) and front-loaded purpose. Most sentences earn their place by providing essential information, though the execution mode explanations could be slightly more concise.

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

Completeness4/5

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

Given the tool's complexity (code execution with multiple modes), no annotations, and an output schema (which handles return values), the description is largely complete. It covers parameters, execution behavior, and usage guidelines well, though could benefit from mentioning security considerations or error scenarios.

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

Parameters5/5

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

Schema description coverage is 0%, so the description must fully compensate. It provides detailed semantics for all 6 parameters: explains what each parameter does, clarifies which parameters apply to which execution modes, and provides default values and constraints. This adds significant value beyond the bare schema.

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

Purpose5/5

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

The description clearly states the tool's purpose with a specific verb ('Execute') and resource ('Python code'), distinguishing it from siblings like 'run_python_file' (which executes files) and 'clear_session' (which manages sessions). It specifies flexible execution modes, making the scope explicit.

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

Usage Guidelines5/5

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

The description provides explicit guidance on when to use each execution mode: 'inline' for most tasks (fast, maintains state) and 'subprocess' for environment isolation or different Python environments. It also distinguishes from siblings by focusing on code execution rather than file operations or session management.

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