](https://mseep.ai/app/yonaka15-mcp-pyodide)
彼得·麦克普
模型上下文协议(MCP)的Pyodide服务器实现。此服务器使大型语言模型(LLM)能够通过MCP接口执行Python代码。
特性
- 使用Pyodide的LLM的Python代码执行能力
- 符合MCP的服务器实现
- 支持stdio和SSE传输模式
- 用TypeScript编写的健壮实现
- 可用作命令行工具
安装
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);
});作为命令行工具
以stdio模式启动(默认):
mcp-pyodide以SSE模式启动:
mcp-pyodide --sseSSE模式
在SSE模式下运行时,服务器提供以下端点:
- SSE连接:
http://localhost:3020/sse - 消息处理程序:
http://localhost:3020/messages
客户端连接示例:
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运行时环境(^0.27.1)arktype:类型验证库(^2.0.1)express:支持SSE的Web框架cors:用于SSE支持的CORS中间件
发展
需求
- Node.js 18或更高版本
- npm 9或更高版本
设置
# Clone the repository
git clone
# Install dependencies
npm install
# Build
npm run build脚本
npm run build:编译TypeScript并设置执行权限npm start:在stdio模式下运行服务器npm run start:sse:以SSE模式运行服务器
环境变量
PYODIDE_CACHE_DIR:Pyodide缓存目录(默认:“./cache”)PYODIDE_DATA_DIR:装载数据的目录(默认:“./data”)PORT:SSE服务器的端口(默认值:3020)
许可证
麻省理工学院
贡献
- 分叉存储库
- 创建要素分支(
git checkout -b feature/amazing-feature) - 提交您的更改(
git commit -am 'Add some amazing feature') - 推到分支(
git push origin feature/amazing-feature) - 创建拉取请求
重要提示
- 该项目正在开发中,API可能会更改
- 在生产中使用前进行彻底测试
- 出于安全原因执行不受信任的代码时请谨慎
- 使用SSE模式时,如果需要,请确保正确的CORS配置
支持
请使用问题跟踪器解决问题。

