基于 MCP 的 RunPod Python 执行器

基于 MCP 的 RunPod Python 执行器

通过 MCP 协议在 RunPod 上执行 Python 代码,适用于 AI 助手的标准化接口。

快速入门指南

系统架构

AI 助手 → MCP 服务器 → RunPod API

部署步骤

1. 配置 RunPod Serverless

  • 安装 Docker 并注册 RunPod 账户。
  • 构建并推送 Docker 镜像:
    git clone https://github.com/yourusername/runpod-python-executor.git
    cd runpod-python-executor
    docker build -t yourusername/runpod-python-executor:latest .
    docker push yourusername/runpod-python-executor:latest
    
  • 在 RunPod 控制台部署服务,并获取 Endpoint ID。

2. 配置 MCP 服务器

  • 安装依赖:
    pip install mcp requests
    
  • 创建 runpod_mcp_server.py 文件,并配置环境变量:
    RUNPOD_API_KEY = "your_runpod_api_key"
    RUNPOD_ENDPOINT_ID = "your_endpoint_id"
    
  • 启动 MCP 服务器:
    uv run mcp
    

使用方法

通过 AI 助手发送 Python 代码至 MCP 服务器进行执行。

注意事项

  • 冷启动可能有延迟。
  • 每次运行环境独立,无持久化存储。