This MCP server provides an interactive Python REPL environment, allowing you to execute Python code in persistent sessions directly from Claude. The server maintains separate state for each session and captures outputs from your code execution.
The server requires Python and the UV package manager to be installed on your system.
To use the Python MCP server with Claude Desktop, you need to add configuration to your Claude desktop settings file. The location of this file depends on your operating system:
~/Library/Application\ Support/Claude/claude_desktop_config.json
%APPDATA%/Claude/claude_desktop_config.json
If you're using the published version of the server:
"mcpServers": {
"python_local": {
"command": "uvx",
"args": [
"python_local"
]
}
}
If you're using a development or unpublished version:
"mcpServers": {
"python_local": {
"command": "uv",
"args": [
"--directory",
"/path/to/python_local",
"run",
"python_local"
]
}
}
Make sure to replace /path/to/python_local
with the actual path to your python_local directory.
You can execute Python code by using the python_repl
tool. This tool requires two parameters:
code
: The Python code you want to executesession_id
: An identifier for your sessionThe server maintains separate state for each session, allowing you to run multiple independent Python environments.
The server provides access to your REPL session history through a custom URI scheme:
repl://
URITo execute a simple Python expression:
# Calculate a simple expression
result = 10 + 20
print(result)
To maintain state across multiple executions (in the same session):
# First execution
x = 5
y = 10
# Second execution (same session_id)
print(x + y) # Will output 15
To use Python libraries:
import math
import random
# Generate a random number and apply a math function
num = random.randint(1, 100)
print(f"Random number: {num}")
print(f"Square root: {math.sqrt(num)}")
You can maintain multiple independent Python environments by using different session_id
values:
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "python_local" '{"command":"uvx","args":["python_local"]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"python_local": {
"command": "uvx",
"args": [
"python_local"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"python_local": {
"command": "uvx",
"args": [
"python_local"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect