mcp-pyodide
The mcp-pyodide server enables Large Language Models (LLMs) to execute Python code and interact with mounted directories via the Model Context Protocol (MCP).
Capabilities include:
Execute Python scripts with output capture and automatic saving of generated images
Dynamically install Python packages using Pyodide
Manage and inspect mounted directories and their contents
Read image files from mounted directories
Operate using either stdio or Server-Sent Events (SSE) transport
Available as both a command-line tool and TypeScript library
Used as the web framework for SSE (Server-Sent Events) support, providing endpoints for SSE connection and message handling
The server runs on Node.js, requiring version 18 or higher for development
Used for package management and running scripts for the MCP server
Enables Large Language Models (LLMs) to execute Python code through Pyodide, a Python runtime environment that runs in JavaScript
The MCP server implementation is robustly written in TypeScript
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mcp-pyodide calculate the factorial of 7 using Python"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
mcp-pyodide
A Pyodide server implementation for the Model Context Protocol (MCP). This server enables Large Language Models (LLMs) to execute Python code through the MCP interface.
Features
Python code execution capability for LLMs using Pyodide
MCP compliant server implementation
Support for both stdio and SSE transport modes
Robust implementation written in TypeScript
Available as a command-line tool
Related MCP server: Sandbox MCP
Installation
npm install mcp-pyodideUsage
As a Server
import { runServer } from "mcp-pyodide";
// Start the server
runServer().catch((error: unknown) => {
console.error("Error starting server:", error);
process.exit(1);
});As a Command-line Tool
Start in stdio mode (default):
mcp-pyodideStart in SSE mode:
mcp-pyodide --sseSSE Mode
When running in SSE mode, the server provides the following endpoints:
SSE Connection:
http://localhost:3020/sseMessage Handler:
http://localhost:3020/messages
Example client connection:
const eventSource = new EventSource("http://localhost:3020/sse");
eventSource.onmessage = (event) => {
console.log("Received:", JSON.parse(event.data));
};Project Structure
mcp-pyodide/
├── src/
│ ├── formatters/ # Data formatting handlers
│ ├── handlers/ # Request handlers
│ ├── lib/ # Library code
│ ├── tools/ # Utility tools
│ ├── utils/ # Utility functions
│ └── index.ts # Main entry point
├── build/ # Build artifacts
├── pyodide-packages/ # Pyodide-related packages
└── package.jsonDependencies
@modelcontextprotocol/sdk: MCP SDK (^1.4.0)pyodide: Python runtime environment (^0.27.1)arktype: Type validation library (^2.0.1)express: Web framework for SSE supportcors: CORS middleware for SSE support
Development
Requirements
Node.js 18 or higher
npm 9 or higher
Setup
# Clone the repository
git clone <repository-url>
# Install dependencies
npm install
# Build
npm run buildScripts
npm run build: Compile TypeScript and set execution permissionsnpm start: Run server in stdio modenpm run start:sse: Run server in SSE mode
Environment Variables
PYODIDE_CACHE_DIR: Directory for Pyodide cache (default: "./cache")PYODIDE_DATA_DIR: Directory for mounted data (default: "./data")PORT: Port for SSE server (default: 3020)
License
MIT
Contributing
Fork the repository
Create a feature branch (
git checkout -b feature/amazing-feature)Commit your changes (
git commit -am 'Add some amazing feature')Push to the branch (
git push origin feature/amazing-feature)Create a Pull Request
Important Notes
This project is under development, and the API may change
Thoroughly test before using in production
Exercise caution when executing untrusted code for security reasons
When using SSE mode, ensure proper CORS configuration if needed
Support
Please use the Issue tracker for problems and questions.
Available Tools
5 toolspyodide_executeA
Execute Python code using Pyodide with output capture. When generating images, they will be automatically saved to the output directory instead of being displayed. Images can be accessed from the saved file paths that will be included in the output.
Inputs: code (required), timeout.
pyodide_get-mount-pointsB
List mounted directories
Inputs: no named parameters.
pyodide_install-packagesC
Install Python packages using Pyodide. Multiple packages can be specified using space-separated format.
Inputs: package (required).
pyodide_list-mounted-directoryB
List contents of a mounted directory
Inputs: mountName (required).
pyodide_read-imageC
Read an image from a mounted directory
Inputs: mountName (required), imagePath (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 5 tools
Most tools have distinct purposes: execute code, list mount points, install packages, list directory contents, and read images. However, pyodide_get-mount-points and pyodide_list-mounted-directory could cause minor confusion as both relate to directory listing, but their scopes differ (mount points vs. specific directory contents).
All tools follow a consistent pyodide_verb-noun naming pattern with hyphens for multi-word verbs or nouns. This uniformity makes the tool set predictable and easy to understand, with no mixing of conventions.
With 5 tools, the count is reasonable for a Pyodide execution server, covering core operations like code execution, package management, and file handling. It might benefit from additional tools for writing files or managing environments, but it's well-scoped for basic functionality.
The tools cover key areas such as code execution, package installation, and file reading/listing, but there are notable gaps. For example, there's no tool for writing or saving files (beyond automatic image saving), deleting files, or managing Python environments more comprehensively, which could limit agent workflows.
Maintenance
Related MCP Connectors
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
Model Context Protocol server for the Apideck Unified API. Connect any MCP-compatible agent framework to 100+ accounting systems, HRIS platforms, file storage providers, and more through one integration. More information https://www.apideck.com/mcp-server
MCP server for AI dialogue using various LLM models via AceDataCloud
Related MCP Servers
- AlicenseAqualityBmaintenanceA Model Context Protocol server that allows LLMs to interact with Python environments, execute code, and manage files within a specified working directory.10784 PyPI104MIT
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol (MCP) server that enables LLMs to run ANY code safely in isolated Docker containers.124MIT
- AlicenseBqualityDmaintenanceA secure Model Context Protocol server that allows AI assistants and LLM applications to safely execute Python and JavaScript code snippets in containerized environments.2206MIT
- AlicenseAqualityDmaintenanceA production-grade MCP server providing a persistent Python REPL with multi-session support, sandboxing, and timeout protection, enabling LLM agents to execute Python code across multiple turns with variables that persist between calls.1231 PyPI1MIT