python-executor-mcp

python-executor-mcp

Enables coding agents to execute Python code, run script files, and install pip packages locally via MCP.

Category
Visit Server

README

python-executor-mcp

A local MCP (Model Context Protocol) server that lets your coding agents execute Python code and script files directly on your machine — with built-in package installation support.


Overview

This server exposes three tools to any MCP-compatible agent:

Tool Description
run_python_code Execute a string of Python code and return stdout/stderr
run_python_file Execute a .py file by absolute path, with optional CLI args
install_python_package Install a pip package into the server's virtual environment

All three tools return a dict with stdout, stderr, and returncode.


How It Works

Each MCP client (Claude Code, VS Code, Cursor, Antigravity) spawns a fresh instance of server.py on demand via stdio. They don't share a running process — but they all point at the same script on disk. This means:

  • You only maintain one codebase
  • Updates to server.py are picked up automatically on the next agent spawn
  • No daemon to manage, no ports to open

Prerequisites

  • Python 3.10 or later
  • pip available on your system
  • (Optional) Claude Code CLI installed, for auto-registration

Installation

Step 1 — Clone the repo

After downloading this folder, initialize it as a git repo and push it wherever you like:

cd python-executor-mcp
git init
git add .
git commit -m "Initial commit"

Step 2 — Run setup

chmod +x setup.sh
./setup.sh

This script will:

  1. Create a .venv virtual environment inside the project folder
  2. Install mcp and fastmcp into it
  3. Print the absolute paths you'll need for manual tool registration
  4. Automatically register the server with Claude Code at user scope (if claude is in your PATH)

Important: After running setup, note the two paths printed — you'll use them in the steps below.


Registering With Each Tool

Replace /ABSOLUTE/PATH/TO/python-executor-mcp with your actual path everywhere below.
Run pwd inside the project folder to get it.


Claude Code (Terminal)

If setup.sh detected Claude Code, this was done automatically. To verify:

claude mcp list

To register manually (user scope = available in all projects):

claude mcp add python-executor --scope user -- \
  /ABSOLUTE/PATH/TO/python-executor-mcp/.venv/bin/python \
  /ABSOLUTE/PATH/TO/python-executor-mcp/server.py

VS Code

Add the following to your user settings.json
(open it via Cmd+Shift+PPreferences: Open User Settings (JSON)):

"mcp": {
  "servers": {
    "python-executor": {
      "type": "stdio",
      "command": "/ABSOLUTE/PATH/TO/python-executor-mcp/.venv/bin/python",
      "args": ["/ABSOLUTE/PATH/TO/python-executor-mcp/server.py"]
    }
  }
}

A ready-to-edit example is in config-examples/vscode-settings.json.


Cursor

Edit (or create) ~/.cursor/mcp.json:

{
  "mcpServers": {
    "python-executor": {
      "command": "/ABSOLUTE/PATH/TO/python-executor-mcp/.venv/bin/python",
      "args": ["/ABSOLUTE/PATH/TO/python-executor-mcp/server.py"]
    }
  }
}

A ready-to-edit example is in config-examples/cursor-mcp.json.


Antigravity (and other MCP clients)

Most MCP-compatible tools use the same JSON shape. Look for a config file named mcp.json, mcp_servers.json, or a mcpServers key in the tool's main config, and add:

"python-executor": {
  "command": "/ABSOLUTE/PATH/TO/python-executor-mcp/.venv/bin/python",
  "args": ["/ABSOLUTE/PATH/TO/python-executor-mcp/server.py"]
}

A generic template is in config-examples/generic-mcp.json.


Updating the Server

Since all clients point to the same server.py, any change you make is picked up automatically:

# Edit server.py, then commit
git add server.py
git commit -m "Add new tool"

No re-registration needed.


Adding New Python Dependencies

Agents can install packages themselves at runtime using the install_python_package tool. To pre-install something permanently:

source .venv/bin/activate
pip install some-package
pip freeze > requirements.txt
deactivate

Then commit the updated requirements.txt.


Security Note

run_python_code and run_python_file execute arbitrary code with your user's full permissions — file system access, network calls, everything. This is intentional for a local dev tool.

If you want to sandbox execution (e.g. for untrusted agents), replace the subprocess.run call in _run() with a Docker invocation:

result = subprocess.run(
    ["docker", "run", "--rm", "--network", "none",
     "-v", f"{tmp_path}:/script.py:ro",
     "python:3.12-slim", "python", "/script.py"],
    capture_output=True, text=True, timeout=timeout
)

Project Structure

python-executor-mcp/
├── server.py               # The MCP server — all three tools live here
├── requirements.txt        # Python dependencies for the server itself
├── setup.sh                # One-time setup: creates .venv, installs deps, registers Claude Code
├── .gitignore              # Excludes .venv and cache files
├── README.md               # This file
└── config-examples/
    ├── cursor-mcp.json     # Paste into ~/.cursor/mcp.json
    ├── vscode-settings.json  # Paste into VS Code user settings.json
    └── generic-mcp.json    # Template for any other MCP-compatible tool

License

MIT — do whatever you want with it.

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured