Pyodide
STDIO基于Pyodide的MCP Python代码执行服务器
基于Pyodide的MCP Python代码执行服务器
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.
npm install mcp-pyodide
import { runServer } from "mcp-pyodide"; // Start the server runServer().catch((error: unknown) => { console.error("Error starting server:", error); process.exit(1); });
Start in stdio mode (default):
mcp-pyodide
Start in SSE mode:
mcp-pyodide --sse
When running in SSE mode, the server provides the following endpoints:
http://localhost:3020/ssehttp://localhost:3020/messagesExample client connection:
const eventSource = new EventSource("http://localhost:3020/sse"); eventSource.onmessage = (event) => { console.log("Received:", JSON.parse(event.data)); };
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
@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# Clone the repository git clone <repository-url> # Install dependencies npm install # Build npm run build
npm run build: Compile TypeScript and set execution permissionsnpm start: Run server in stdio modenpm run start:sse: Run server in SSE modePYODIDE_CACHE_DIR: Directory for Pyodide cache (default: "./cache")PYODIDE_DATA_DIR: Directory for mounted data (default: "./data")PORT: Port for SSE server (default: 3020)MIT
git checkout -b feature/amazing-feature)git commit -am 'Add some amazing feature')git push origin feature/amazing-feature)Please use the Issue tracker for problems and questions.