Provides tools for executing Python code in a safe environment, installing packages with pip, saving and running Python files, and returning specific variable values from executed code with error handling support.
mcp-run-python-code
Python interpreter, MCP server, no API key, free. Get results from running Python code.
Overview
This MCP server provides tools for running Python code, installing packages, and executing Python files. It can be easily integrated with MCP clients, including Claude and other LLM applications supporting the MCP protocol.
Features
- Execute Python code in a safe environment
- Install Python packages using pip
- Save Python code to files and run them
- Run existing Python files
- Return specific variable values from executed code
- Error handling and debugging support
Installation
From pip
You can install the MCP Run Python Code Server using uv
:
Or using pip:
From source
Usage
Python Demo
Running as a standalone MCP server
Run the server with the stdio transport:
or
or
Then, you can use the server with any MCP client that supports stdio transport.
Integrating with Cursor
To add the weather MCP server to Cursor, add stdio MCP with command:
Tools available
run_python_code
- Execute Python code and optionally return a variable valuesave_to_file_and_run
- Save Python code to a file and execute itpip_install_package
- Install Python packages using piprun_python_file
- Run an existing Python file and optionally return a variable value
Examples
Example 1: Basic Code Execution
Example 2: Run python File
Example 3: Data Processing
Contact
- Issues and suggestions:
- Email: xuming624@qq.com
- WeChat: Add me (WeChat ID: xuming624) with the message: "Name-Company-NLP" to join our NLP discussion group.
License
This project is licensed under The Apache License 2.0 and can be used freely for commercial purposes.
Please include a link to the mcp-run-python-code
project and the license in your product description.
Contribute
We welcome contributions to improve this project! Before submitting a pull request, please:
- Add appropriate unit tests in the
tests
directory - Run
python -m pytest
to ensure all tests pass - Submit your PR with clear descriptions of the changes
Acknowledgements
- Built with MCP Python SDK
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
Enables execution of Python code in a safe environment, including running scripts, installing packages, and retrieving variable values. Supports file operations and package management through pip.
Related MCP Servers
- AsecurityFlicenseAqualityEnables browser automation using Python scripts, offering operations like taking webpage screenshots, retrieving HTML content, and executing JavaScript.Last updated -418Python
- -securityFlicense-qualityProvides an interactive Python REPL environment that maintains persistent session state, allowing users to execute Python code and access session history.Last updated -56Python
- -securityAlicense-qualityAn interactive Python code execution environment that allows users and LLMs to safely execute Python code and install packages in isolated Docker containers.Last updated -20PythonApache 2.0
- -securityAlicense-qualityAn interactive Python code execution tool that allows users and LLMs to safely execute Python code and install packages in isolated Docker containers.Last updated -20PythonApache 2.0