YM

yonaka15/mcp-pyodide

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

19 stars 6 forks 质量 53 趋势 22MIT

Pyodide服务器用于"模式上下文协议"(MCP)的实施.

概览

Pyodide服务器用于"模式上下文协议"(MCP)的实施. 这个服务器可以让大语言模型(LLMs)通过MCP接口执行Python代码. - Python 使用 Pyodide 的 LLMS 代码执行能力 - MCP 兼容服务器执行 - 支持 stdio 和 SSE 传输模式 - 以 TypeScript 书写的 Rbust 执行 - 作为命令行工具可用 在SSE模式下运行时,服务器提供以下端点: - SSE 连接 : http://localhost:3020/sse - 消息处理器 : http://localhost:3020/messages - @ modelcontextprotocol/ sdk: MCP SDK (^ 1. 4. 0) - pyodide: Python 运行时环境 (^ 0. 27.1) - arktype: 类型验证库 (^ 2. 0.1) - 表达式: SSE支持的Web框架 - cors: SSE支持的 CORS 中间软件 - 节点.

概述(AI 翻译)

Pyodide服务器用于"模式上下文协议"(MCP)的实施. 这个服务器可以让大语言模型(LLMs)通过MCP接口执行Python代码.

□ 特性

  • 使用 Pyodide 的 LLMS 的 Python 代码执行能力
  • 符合MCP的服务器执行
  • 支持Stdio和SSE两种运输方式
  • 用类型脚本书写的有力执行
  • 作为命令行工具可用

□ 安装

□ 使用量

作为服务器

作为命令行工具

以 stdio 模式启动( 默认) :

以 SSE 模式开始 :

SSE 模式

在SSE模式下运行时,服务器提供以下端点:

  • SSE 连接: http://localhost:3020/sse
  • 信件处理器:http://localhost:3020/messages

示例客户端连接 :

□ 项目结构

□ 依赖性

  • [[T2]:MCP SDK(^ 1.4.0)
  • [[T3]: Python运行时环境(^0.27.1)
  • [[T4]:类型验证库(^2.0.1)
  • [[T5]: SSE 支持的网络框架
  • [[T6]:用于SSE支持的CORS中间软件

□ 发展

所需经费

  • 节点.js 18或以上
  • 9岁或以上

QQ 设置

脚本

  • [[T7]: 编译类型脚本并设定执行权限

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 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.

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 

# 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')
在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →