python-runner
Execute Python code via subprocess with timeout and error handling, returning stdout, stderr, and exit code.
README
Python MCP Server
An MCP (Model Context Protocol) server that exposes a run_script tool for executing Python code via subprocess.
Installation
uv sync
Usage
Run the server
uv run python server.py
Claude Desktop / Claude Code
claude mcp add --transport stdio --scope user python-runner -- uvx --from git+https://github.com/Drahoxx/python-mcp python-mcp
Or for a local installation:
claude mcp add --transport stdio --scope user python-runner -- uv run --directory /path/to/python-mcp python-mcp
OpenCode
Add to ~/.config/opencode/opencode.json:
{
"mcpServers": {
"python-runner": {
"command": "uvx",
"args": ["--from", "git+https://github.com/Drahoxx/python-mcp", "python-mcp"]
}
}
}
Or for a local installation:
{
"mcpServers": {
"python-runner": {
"command": "uv",
"args": ["run", "--directory", "/path/to/python-mcp", "python-mcp"]
}
}
}
Generic MCP Client
Add to your MCP client configuration:
{
"mcpServers": {
"python-runner": {
"command": "uv",
"args": ["run", "--directory", "/path/to/python-mcp", "python", "server.py"]
}
}
}
Tool: run_script
Execute Python code and return the result.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
code |
str |
required | Python code to execute |
timeout |
int |
30 |
Execution timeout in seconds |
Response
Returns a JSON string with:
| Field | Type | Description |
|---|---|---|
success |
bool |
Whether execution succeeded (exit code 0) |
stdout |
str |
Captured standard output |
stderr |
str |
Captured standard error |
error |
str | null |
Error message/traceback if failed |
return_code |
int |
Process exit code (-1 for timeout) |
Examples
Successful execution:
run_script('print("hello")')
# {"success": true, "stdout": "hello\n", "stderr": "", "error": null, "return_code": 0}
Syntax error:
run_script('print(')
# {"success": false, "stdout": "", "stderr": "...", "error": "SyntaxError...", "return_code": 1}
Runtime error:
run_script('1/0')
# {"success": false, "stdout": "", "stderr": "...", "error": "ZeroDivisionError...", "return_code": 1}
Timeout:
run_script('import time; time.sleep(60)', timeout=2)
# {"success": false, "stdout": "", "stderr": "", "error": "Execution timed out after 2 seconds", "return_code": -1}
Development
Run tests
uv run pytest
Run tests with coverage
uv run pytest --cov=server
Recommended Servers
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.
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.
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.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
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.
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.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
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.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.