Skip to main content
Glama
yonaka15
by yonaka15
README.md
[![MseeP.ai Security Assessment Badge](https://mseep.net/pr/yonaka15-mcp-pyodide-badge.png)](https://mseep.ai/app/yonaka15-mcp-pyodide)

# 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.

<a href="https://glama.ai/mcp/servers/pxls43joly">
  <img width="380" height="200" src="https://glama.ai/mcp/servers/pxls43joly/badge" alt="mcp-pyodide MCP server" />
</a>

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

```bash
npm install mcp-pyodide
```

## Usage

### As a Server

```typescript
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):

```bash
mcp-pyodide
```

Start in SSE mode:

```bash
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:

```typescript
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

```bash
# 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.

TDQS

B3.4/5.0

Scored across 5 tools

Disambiguation4/5

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).

Naming Consistency5/5

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.

Tool Count4/5

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.

Completeness3/5

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

ActivityInactive
ResponsivenessUnresponsive