Fire in da houseTop Tip:Paying $100+ per month for Perplexity, MidJourney, Runway, ChatGPT and other tools is crazy - get all your AI tools in one site starting at $15 per month with Galaxy AI Fire in da houseCheck it out free

mcp-pyodide

MCP.Pizza Chef: yonaka15

mcp-pyodide is a robust MCP server implementation that allows Large Language Models to execute Python code via the Pyodide runtime. Written in TypeScript, it supports both stdio and SSE transport modes, providing flexible integration options. Available as a command-line tool, it enables seamless Python execution within MCP workflows, enhancing model capabilities with real-time code execution.

Use This MCP server To

Execute Python scripts within LLM-driven workflows Run real-time Python code for data analysis in MCP environments Integrate Python computation into AI-assisted development tools Enable dynamic Python code evaluation for interactive agents Support scientific computing tasks in MCP-enabled applications Provide Python runtime for AI models without external dependencies

README

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.

mcp-pyodide MCP server

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

Installation

npm install mcp-pyodide

Usage

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-pyodide

Start in SSE mode:

mcp-pyodide --sse

SSE Mode

When running in SSE mode, the server provides the following endpoints:

  • SSE Connection: http://localhost:3020/sse
  • Message 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.json

Dependencies

  • @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 support
  • cors: 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 build

Scripts

  • npm run build: Compile TypeScript and set execution permissions
  • npm start: Run server in stdio mode
  • npm 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

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -am 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. 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.

mcp-pyodide FAQ

How do I install mcp-pyodide?
Install it via npm using 'npm install mcp-pyodide'.
What transport modes does mcp-pyodide support?
It supports both stdio and Server-Sent Events (SSE) transport modes.
Can mcp-pyodide run as a standalone server?
Yes, it can be started as a standalone server using the provided runServer function or CLI tool.
Is mcp-pyodide compatible with multiple LLM providers?
Yes, it is MCP-compliant and works with models from OpenAI, Anthropic, Claude, Gemini, and others.
What programming language is mcp-pyodide implemented in?
It is implemented in TypeScript for robustness and maintainability.
Can I use mcp-pyodide to execute Python code interactively?
Yes, it enables real-time Python code execution within MCP workflows.
Does mcp-pyodide require a Python environment installed locally?
No, it uses Pyodide, which runs Python in the browser or Node.js environment without local Python installation.
How do I start mcp-pyodide in SSE mode?
Use the CLI command 'mcp-pyodide --...' with appropriate SSE flags as documented.