MCP-Pyodide模型上下文协议服务器添加福利群:解决AI开发者的「MCP实战痛点」一个为模型上下文协议(MCP)实现的 Pyodide 服务器。该服务器使大型语言模型(LLMs)能够通过 MCP 接口执行 Python 代码。
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)请使用 Issue 跟踪器来报告问题和提问。