Sponsored by Deepsite.site

Python Runner MCP Server

Created By
taiji19857 months ago
A MCP Server Of python runner
Content

Python Runner MCP Server

English | 中文

A Python code execution server based on the FastMCP framework, designed specifically for data science and machine learning workflows.

🚀 Features

  • Safe Python Code Execution: Execute Python code in isolated namespaces
  • Rich Data Science Libraries: Pre-installed with commonly used data science and machine learning packages
  • Real-time Output Capture: Capture standard output, error output, and return values
  • MCP Protocol Support: Fully compatible with Model Context Protocol
  • Easy to Use: Provides a simple and clean API interface

Use uvx to run the server directly without installation: [TODO ..... ]

# Run directly (no pre-installation required)
uvx python-runner

Configure in Claude Desktop

Add the following configuration to your Claude Desktop config file:

{
  "mcpServers": {
    "python-runner": {
      "command": "uvx",
      "args": ["python-runner"]
    }
  }
}

Config file locations:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json

Debug and Test

# Use MCP Inspector to debug the server
npx @modelcontextprotocol/inspector uvx python-runner

📦 Pre-installed Libraries

This project comes pre-installed with the following commonly used data science and machine learning libraries:

  • Data Processing: numpy, pandas, scipy
  • Machine Learning: scikit-learn
  • Data Visualization: matplotlib, seaborn, plotly
  • Scientific Computing: sympy
  • Image Processing: pillow
  • Network Analysis: networkx
  • Interactive Development: jupyter
  • HTTP Requests: requests

🛠️ Manual Installation (For Development)

Prerequisites

  • Python 3.12 or higher
  • uv package manager (recommended) or pip
# Clone the repository
git clone <repository-url>
cd python_runner

# Install dependencies
uv sync

Install with pip

# Clone the repository
git clone <repository-url>
cd python_runner

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate

# Install dependencies
pip install -e .

🚀 Usage

Using with Claude Desktop

After configuration, you can directly use Python code execution functionality in Claude Desktop:

Please help me execute this Python code:

import pandas as pd
import numpy as np

# Create sample data
data = pd.DataFrame({
    'sales': [100, 150, 200, 120, 180],
    'profit': [20, 30, 50, 25, 40]
})

print("Sales data statistics:")
print(data.describe())

Running as Standalone MCP Server

# Using uvx (recommended)
uvx python-runner

# Or run locally
python main.py

Direct API Call

from main import execute_python

# Execute simple Python code
result = execute_python("""
print("Hello, World!")
x = 1 + 2
print(f"Result: {x}")
""")

print(result)
# Output:
# {
#     'output': 'Hello, World!\nResult: 3\n',
#     'error': '',
#     'success': True
# }

Data Science Examples

# Data analysis example
code = """
import pandas as pd
import numpy as np

# Create sample data
data = pd.DataFrame({
    'x': np.random.randn(100),
    'y': np.random.randn(100)
})

print(f"Data shape: {data.shape}")
print(f"Statistical summary:\n{data.describe()}")
"""

result = execute_python(code)
print(result['output'])
# Machine learning example
code = """
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score

# Generate sample data
X, y = make_classification(n_samples=1000, n_features=20, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Train model
clf = RandomForestClassifier(random_state=42)
clf.fit(X_train, y_train)

# Predict and evaluate
y_pred = clf.predict(X_test)
accuracy = accuracy_score(y_test, y_pred)
print(f"Model accuracy: {accuracy:.4f}")
"""

result = execute_python(code)
print(result['output'])

📋 API Reference

execute_python(code: str) -> dict

Execute Python code and return the result.

Parameters:

  • code (str): Python code string to execute

Returns:

  • dict: Dictionary containing the following keys:
    • output (str): Standard output content
    • error (str): Error message (if any)
    • success (bool): Whether execution was successful

🔒 Security

  • Code executes in isolated namespaces
  • Captures and redirects standard output and error output
  • Provides detailed error tracking information

⚠️ Warning: This tool executes arbitrary Python code. Please ensure you use it in a trusted environment.

🤝 Contributing

Issues and Pull Requests are welcome!

  1. Fork this repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • FastMCP - Excellent MCP framework
  • All maintainers of the pre-installed open-source data science libraries

Made with ❤️ for the data science community

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
CursorThe AI Code Editor
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
WindsurfThe new purpose-built IDE to harness magic
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
DeepChatYour AI Partner on Desktop
Amap Maps高德地图官方 MCP Server
Playwright McpPlaywright MCP server
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
Serper MCP ServerA Serper MCP Server
ChatWiseThe second fastest AI chatbot™
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Tavily Mcp
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.