A Model Context Protocol (MCP) server for executing Python code and managing Python environments. This server allows Claude and other LLMs to run Python code, manage files, and work with Python packages.
Before using this MCP server, ensure you have:
git clone https://github.com/Timtech4u/python-mcp-server.git
cd python-mcp-server
npm install
npm run build
Open your Claude Desktop configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
Add the Python MCP server configuration:
{
"mcpServers": {
"python": {
"command": "node",
"args": [
"/absolute/path/to/python-mcp-server/dist/index.js"
],
"disabled": false,
"autoApprove": [
"execute_python_code",
"execute_python_file",
"check_python_version",
"list_python_files",
"read_python_file",
"write_python_file"
]
}
}
}
Replace /absolute/path/to/python-mcp-server
with the actual path where you cloned the repository.
Restart Claude Desktop.
Open your Cline MCP settings file:
~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json
%APPDATA%\Code\User\globalStorage\saoudrizwan.claude-dev\settings\cline_mcp_settings.json
Add the Python MCP server configuration:
{
"mcpServers": {
"python": {
"command": "node",
"args": [
"/absolute/path/to/python-mcp-server/dist/index.js"
],
"disabled": false,
"autoApprove": [
"execute_python_code",
"execute_python_file",
"check_python_version",
"list_python_files",
"read_python_file",
"write_python_file"
]
}
}
}
Replace /absolute/path/to/python-mcp-server
with the actual path where you cloned the repository.
Restart Cline or reload the window.
Once configured, you can ask Claude to run Python code in various ways. Here are some examples:
Can you run this Python code for me?
import random
numbers = [random.randint(1, 100) for _ in range(10)]
print(f"Random numbers: {numbers}")
print(f"Sum: {sum(numbers)}")
print(f"Average: {sum(numbers)/len(numbers)}")
Can you execute my Python file at /path/to/my_script.py?
Can you list all Python files in my /path/to/project directory?
Can you show me the contents of /path/to/my_script.py?
Can you create a Python file at /path/to/new_script.py with the following content?
def hello_world():
print("Hello, world!")
if __name__ == "__main__":
hello_world()
What version of Python do I have installed?
Executes Python code snippets.
Parameters:
code
(string, required): The Python code to executetimeout
(number, optional): Maximum execution time in seconds (default: 30)args
(array of strings, optional): Command line arguments to pass to the scriptworkingDir
(string, optional): Working directory for the script executionExecutes a Python file.
Parameters:
filePath
(string, required): Path to the Python file to executetimeout
(number, optional): Maximum execution time in seconds (default: 30)args
(array of strings, optional): Command line arguments to pass to the scriptworkingDir
(string, optional): Working directory for the script executionReturns information about the installed Python version.
Lists Python files in a directory.
Parameters:
dirPath
(string, optional): Directory path to list Python files from (default: current directory)recursive
(boolean, optional): Whether to search recursively (default: false)Reads the content of a Python file.
Parameters:
filePath
(string, required): Path to the Python file to readWrites content to a Python file.
Parameters:
filePath
(string, required): Path to the Python file to writecontent
(string, required): Content to write to the filecreateDirs
(boolean, optional): Create directories if they do not exist (default: true)If you see an error like "Python is not installed", make sure Python is installed and available in your system PATH.
If you encounter permission errors when reading or writing files, make sure the user running the MCP server has the necessary permissions.
The server has a default 30-second timeout for code execution. If your code takes longer than that, it will be terminated. You can increase the timeout by specifying the timeout
parameter.
MIT
{
"mcpServers": {
"python": {
"env": {},
"args": [
"/absolute/path/to/python-mcp-server/dist/index.js"
],
"command": "node"
}
}
}
Seamless access to top MCP servers powering the future of AI integration.