The MCP Python Toolbox is a Model Context Protocol server that empowers AI assistants like Claude to perform Python development tasks. It provides a standardized interface for file operations, code analysis, project management, and code execution, enabling AI assistants to effectively work with Python code and projects.
git clone https://github.com/gianlucamazza/mcp_python_toolbox.git
cd mcp_python_toolbox
python -m venv .venv
source .venv/bin/activate # Linux/Mac
# or
.venv\Scripts\activate # Windows
pip install -e ".[dev]"
The simplest way to start the server is using the CLI:
# Start with current directory as workspace
python -m mcp_python_toolbox
# Or specify a workspace directory
python -m mcp_python_toolbox --workspace /path/to/your/project
Claude Desktop can automatically launch and manage the MCP Python Toolbox server:
"python-toolbox": {
"command": "/Users/username/path/to/mcp_python_toolbox/.venv/bin/python",
"args": [
"-m",
"mcp_python_toolbox",
"--workspace",
"/Users/username/path/to/workspace"
],
"env": {
"PYTHONPATH": "/Users/username/path/to/mcp_python_toolbox/src",
"PATH": "/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",
"VIRTUAL_ENV": "/Users/username/path/to/mcp_python_toolbox/.venv",
"PYTHONHOME": ""
}
}
You can also use the MCP Python Toolbox programmatically:
from mcp_python_toolbox import PythonToolboxServer
server = PythonToolboxServer(workspace_root="/path/to/your/project")
server.setup()
server.run()
from mcp_python_toolbox.core import FileOperations
file_ops = FileOperations(workspace_root="/path/to/project")
# Read file contents
content = file_ops.read_file("src/example.py")
# Read specific lines
lines = file_ops.read_file("src/example.py", start_line=10, end_line=20)
# Write to file
file_ops.write_file("output.txt", "Hello, World!")
# Append to file
file_ops.write_file("log.txt", "New entry\n", mode='a')
# List directory contents
contents = file_ops.list_directory("src")
for item in contents:
print(f"{item['name']} - {item['type']} - {item['size']} bytes")
from mcp_python_toolbox.core import CodeAnalyzer
analyzer = CodeAnalyzer(workspace_root="/path/to/project")
# Analyze Python file structure
analysis = analyzer.parse_python_file("src/example.py")
print(f"Found {len(analysis['functions'])} functions")
print(f"Found {len(analysis['classes'])} classes")
# Format code
formatted = analyzer.format_code(code, style='black')
# Lint code
issues = analyzer.lint_code("src/example.py")
for issue in issues:
print(f"Line {issue['line']}: {issue['message']}")
from mcp_python_toolbox.core import ProjectManager
pm = ProjectManager(workspace_root="/path/to/project")
# Create virtual environment
pm.create_virtual_environment()
# Install dependencies
pm.install_dependencies() # from requirements.txt or pyproject.toml
pm.install_dependencies("requirements-dev.txt") # from specific file
# Check for conflicts
conflicts = pm.check_dependency_conflicts()
if conflicts:
print("Found dependency conflicts:")
for conflict in conflicts:
print(f"{conflict['package']} requires {conflict['requires']}")
# Update packages
pm.update_package("requests") # to latest
pm.update_package("flask", version="2.0.0") # to specific version
from mcp_python_toolbox.core import CodeExecutor
executor = CodeExecutor(workspace_root="/path/to/project")
code = '''
def greet(name):
return f"Hello, {name}!"
print(greet("World"))
'''
result = executor.execute_code(code)
print(f"Output: {result['stdout']}")
print(f"Errors: {result['stderr']}")
print(f"Exit code: {result['exit_code']}")
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "python-toolbox" '{"command":"python","args":["-m","mcp_python_toolbox","--workspace","${workspaceRoot}"]}'
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-toolbox": {
"command": "python",
"args": [
"-m",
"mcp_python_toolbox",
"--workspace",
"${workspaceRoot}"
]
}
}
}
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-toolbox": {
"command": "python",
"args": [
"-m",
"mcp_python_toolbox",
"--workspace",
"${workspaceRoot}"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect