Model Context Protocol (MCP) 的一个 Pyodide 服务器实现。此服务器使大型语言模型(LLMs)能够通过 MCP 接口执行 Python 代码。
<a href="https://glama.ai/mcp/servers/pxls43joly"> <img width="380" height="200" src="https://gips0.baidu.com/it/u=2844058269,2728969156&fm=3081&app=3081&f=PNG?w=760&h=400" alt="mcp-pyodide MCP 服务器" /> </a>npm install mcp-pyodide
import { runServer } from "mcp-pyodide";
// 启动服务器
runServer().catch((error: unknown) => {
console.error("启动服务器时出错:", error);
process.exit(1);
});
在 stdio 模式下启动(默认):
mcp-pyodide
在 SSE 模式下启动:
mcp-pyodide --sse
当以 SSE 模式运行时,服务器提供以下端点:
http://localhost:3020/ssehttp://localhost:3020/messages示例客户端连接:
const eventSource = new EventSource("http://localhost:3020/sse");
eventSource.onmessage = (event) => {
console.log("收到:", JSON.parse(event.data));
};
mcp-pyodide/
├── src/
│ ├── formatters/ # 数据格式化处理程序
│ ├── handlers/ # 请求处理程序
│ ├── lib/ # 库代码
│ ├── tools/ # 工具
│ ├── utils/ # 工具函数
│ └── index.ts # 主入口点
├── build/ # 构建产物
├── pyodide-packages/ # Pyodide 相关包
└── package.json
@modelcontextprotocol/sdk: MCP SDK (^1.4.0)pyodide: Python 运行环境 (^0.27.1)arktype: 类型验证库 (^2.0.1)express: 支持 SSE 的 Web 框架cors: 支持 SSE 的 CORS 中间件# 克隆仓库
git clone <repository-url>
# 安装依赖
npm install
# 构建
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)MIT
git checkout -b feature/amazing-feature)git commit -am '添加一些惊人的功能')git push origin feature/amazing-feature)请使用问题跟踪器报告问题和提出疑问。