返回市场
达顿纳-MCP-解释器

达顿纳-MCP-解释器

作者:nibzard18 星标更新:2025-03-25

项目介绍

Daytona MCP 解释器

一个提供在临时 Daytoa 沙箱中执行 Python 代码能力的模型上下文协议服务器。

Daytona MCP 服务器在 Claude Desktop 中

概述

Daytona MCP 解释器使像 Claude 这样的AI助手能够在安全隔离的环境中执行 Python 代码和 shell 命令。它实现了模型上下文协议(MCP)标准,提供了以下工具:

  • 在沙箱环境中执行 Python 代码
  • 执行 shell 命令
  • 文件管理(上传/下载)
  • 克隆 Git 仓库
  • 为运行中的服务器生成网页预览

所有执行都在临时的 Daytona 工作区中进行,这些工作区在使用后会自动清理。

安装

  1. 如果尚未安装,请安装 uv:
curl -LsSf https://astral.sh/uv/install.sh | sh
  1. 创建并激活虚拟环境。

如果你已有现有环境,请先停用并删除它:

deactivate
rm -rf .venv

创建并激活新的虚拟环境:

uv venv
source .venv/bin/activate

(在 Windows 上:.venv\Scripts\activate

  1. 安装依赖项:
uv add "mcp[cli]" pydantic python-dotenv "daytona-sdk>=0.10.5"

注意:此项目需要 daytona-sdk 版本 0.10.5 或更高。早期版本具有不兼容的 FileSystem API。

环境变量

配置这些环境变量以确保正常操作:

  • MCP_DAYTONA_API_KEY:Daytona 认证所需的 API 密钥
  • MCP_DAYTONA_SERVER_URL:服务器 URL(默认:https://app.daytona.io/api)
  • MCP_DAYTONA_TIMEOUT:请求超时时间(秒,默认:180.0)
  • MCP_DAYTONA_TARGET:目标区域(默认:eu)
  • MCP_VERIFY_SSL:启用 SSL 验证(默认:false)

开发

直接运行服务器:

uv run src/daytona_mcp_interpreter/server.py

或者如果 uv 不在你的路径中:

/Users/USER/.local/bin/uv run ~LOCATION/daytona-mcp-interpreter/src/daytona_mcp_interpreter/server.py

使用 MCP Inspector 测试服务器:

npx @modelcontextprotocol/inspector \
  uv \
  --directory . \
  run \
  src/daytona_mcp_interpreter/server.py

查看日志:

tail -f /tmp/daytona-interpreter.log

与 Claude Desktop 的集成

观看演示视频

  1. 在 Claude Desktop(或其他兼容 MCP 的客户端)中配置:

在 MacOS 上,编辑:~/Library/Application Support/Claude/claude_desktop_config.json 在 Windows 上,编辑:%APPDATA%\Claude\claude_desktop_config.json

{
    "mcpServers": {
        "daytona-interpreter": {
            "command": "/Users/USER/.local/bin/uv",
            "args": [
                "--directory",
                "/Users/USER/dev/daytona-mcp-interpreter",
                "run",
                "src/daytona_mcp_interpreter/server.py"
            ],
            "env": {
                "PYTHONUNBUFFERED": "1",
                "MCP_DAYTONA_API_KEY": "api_key",
                "MCP_DAYTONA_SERVER_URL": "api_server_url",
                "MCP_DAYTONA_TIMEOUT": "30.0",
                "MCP_VERIFY_SSL": "false",
                "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
            }
        }
    }
}
  1. 重启 Claude Desktop
  2. Daytona Python 解释器工具将在 Claude 中可用

可用工具

Shell 执行

在 Daytona 工作区中执行 shell 命令。

# 示例:列出文件
ls -la

# 示例:安装一个包
pip install pandas

文件下载

从 Daytona 工作区下载文件,智能处理大文件。

基本用法:

file_download(file_path="/path/to/file.txt")

高级用法:

# 设置自定义文件大小限制
file_download(file_path="/path/to/large_file.csv", max_size_mb=10.0)

# 下载大文件的部分内容
file_download(file_path="/path/to/large_file.csv", download_option="download_partial", chunk_size_kb=200)

# 将大文件转换为文本
file_download(file_path="/path/to/large_file.pdf", download_option="convert_to_text")

# 在下载前压缩文件
file_download(file_path="/path/to/large_file.bin", download_option="compress_file")

# 强制下载,无视大小
file_download(file_path="/path/to/large_file.zip", download_option="force_download")

文件上传

将文件上传到 Daytona 工作区。支持文本和二进制文件。

基本用法:

# 上传一个文本文件
file_upload(file_path="/workspace/example.txt", content="Hello, World!")

高级用法:

# 使用特定路径上传一个文本文件
file_upload(
    file_path="/workspace/data/config.json",
    content='{"setting": "value", "enabled": true}'
)

# 使用 base64 编码上传一个二进制文件
import base64
with open("local_image.png", "rb") as f:
    base64_content = base64.b64encode(f.read()).decode('utf-8')

file_upload(
    file_path="/workspace/images/uploaded.png",
    content=base64_content,
    encoding="base64"
)

# 上传时不覆盖已存在的文件
file_upload(
    file_path="/workspace/important.txt",
    content="New content",
    overwrite=False
)

Git 克隆

克隆 Git 仓库到 Daytona 工作区,用于分析和代码执行。

基本用法:

git_clone(repo_url="https://github.com/username/repository.git")

高级用法:

# 克隆特定分支
git_clone(
    repo_url="https://github.com/username/repository.git",
    branch="develop"
)

# 克隆到特定目录,并带有完整历史记录
git_clone(
    repo_url="https://github.com/username/repository.git",
    target_path="my_project",
    depth=0  # 0 表示完整历史记录
)

# 支持 Git LFS 的仓库克隆,适用于有大文件的仓库
git_clone(
    repo_url="https://github.com/username/large-files-repo.git",
    lfs=True
)

网页预览

为运行在 Daytona 工作区内的网络服务器生成预览 URL。

基本用法:

# 为运行在 3000 端口上的网络服务器生成预览链接
web_preview(port=3000)

高级用法:

# 生成带有描述性名称的预览链接
web_preview(
    port=8080,
    description="React Development Server"
)

# 生成链接,不检查服务器是否正在运行
web_preview(
    port=5000,
    check_server=False
)

示例:

# 首先使用 shell 运行一个简单的 web 服务器
shell_exec(command="python -m http.server 8000 &")

# 然后为该服务器生成预览链接
web_preview(port=8000, description="Python HTTP Server")

<a href="https://glama.ai/mcp/servers/hj7jlxkxpk"><img width="380" height="200" src="https://gips0.baidu.com/it/u=1887990228,1259353844&fm=3081&app=3081&f=PNG?w=760&h=400" alt="Daytona Python 解释器 MCP 服务器" /></a> smithery 徽章