@geobio/code_execution_server

中文文档
0.2.1发布于 2025/07/03ES Module近 30 天下载 3061

执行代码

中文使用文档
文档目录22 节
  1. 特征
  2. 先决条件
  3. 设置
  4. 配置
  5. 使用节点.js
  6. 使用嵌入器
  7. 环境变量
  8. 可用工具
  9. 1. 联合国. execute_code
  10. 2. 联合国. install_dependencies
  11. 3个. check_installed_packages
  12. 4.四. configure_environment
  13. 5 (韩语). get_environment_config
  14. 6. 国家. initialize_code_file
  15. 7. 联合国. append_to_code_file
  16. 8. 联合国. execute_code_file
  17. 9. 国家. read_code_file
  18. 使用量
  19. 处理大码块
  20. 后向兼容性
  21. 捐款
  22. 许可证

MCP 代码执行器

smithery badge

MCP代码执行器是允许LLMs在指定的Python环境中执行Python代码的MCP服务器. 这使得LLMS能够运行代码,可以访问环境定义的库和依赖. 它还支持处理可能超过符号限制的大型代码块的递增代码生成.

Code Executor MCP server

特征

  • 从 LLM 提示执行 Python 代码
  • 支持递增代码生成以克服符号限制
  • 在指定的环境中运行代码( Conda, virtualenv, 或 UV virtualenv)
  • 需要时安装依赖关系
  • 检查是否已安装软件包
  • 在运行时动态配置环境
  • 可配置代码存储目录

先决条件

  • 已安装节点.js
  • 以下是:
    • 安装了理想的 Conda 环境
    • Python 虚拟版本
    • UV 虚拟env

设置

  1. 克隆此寄存器 :
git clone https://github.com/bazinga012/mcp_code_executor.git
  1. 导航到项目目录 :
cd mcp_code_executor
  1. 安装 Node.js 依赖性 :
npm install
  1. 构建工程 :
npm run build

配置

要配置 MCP 代码执行器服务器, 请在您的 MCP 服务器配置文件中添加以下内容 :

使用节点.js

{
  "mcpServers": {
    "mcp-code-executor": {
      "command": "node",
      "args": [
        "/path/to/mcp_code_executor/build/index.js" 
      ],
      "env": {
        "CODE_STORAGE_DIR": "/path/to/code/storage",
        "ENV_TYPE": "conda",
        "CONDA_ENV_NAME": "your-conda-env"
      }
    }
  }
}

使用嵌入器

{
  "mcpServers": {
    "mcp-code-executor": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "mcp-code-executor"
      ]
    }
  }
}

说明: Dockerfile只用 vev-uv 环境类型进行了测试. 其他环境类型可能需要额外的配置.

环境变量

所需变量

  • CODE_STORAGE_DIR: 将存储生成代码的目录

环境类型( 选择一个设置)

  • 对于康达:

    • ENV_TYPE: 设定为 conda
    • CONDA_ENV_NAME: 要使用的 Conda 环境名称
  • 对于标准Virtualenv:

    • ENV_TYPE: 设定为 venv
    • VENV_PATH: 虚拟env 目录的路径
  • 对于紫外线Virtualenv:

    • ENV_TYPE: 设定为 venv-uv
    • UV_VENV_PATH: UV virtualenv 目录路径

可用工具

MCP代码执行器为LLMS提供了下列工具:

1. 联合国. execute_code

在配置的环境中执行 Python 代码 。 最适合短代码片段 .

{
  "name": "execute_code",
  "arguments": {
    "code": "import numpy as np\nprint(np.random.rand(3,3))",
    "filename": "matrix_gen"
  }
}

2. 联合国. install_dependencies

在环境中安装 Python 包.

{
  "name": "install_dependencies",
  "arguments": {
    "packages": ["numpy", "pandas", "matplotlib"]
  }
}

3个. check_installed_packages

检查是否已在环境中安装软件包 .

{
  "name": "check_installed_packages",
  "arguments": {
    "packages": ["numpy", "pandas", "non_existent_package"]
  }
}

4.四. configure_environment

动态地改变环境配置.

{
  "name": "configure_environment",
  "arguments": {
    "type": "conda",
    "conda_name": "new_env_name"
  }
}

5 (韩语). get_environment_config

获得当前环境配置.

{
  "name": "get_environment_config",
  "arguments": {}
}

6. 国家. initialize_code_file

创建带有初始内容的新 Python 文件。 将此作为可能超过符号限制的较长代码的第一步.

{
  "name": "initialize_code_file",
  "arguments": {
    "content": "def main():\n    print('Hello, world!')\n\nif __name__ == '__main__':\n    main()",
    "filename": "my_script"
  }
}

7. 联合国. append_to_code_file

将内容添加到已有的 Python 代码文件中 。 使用此选项将更多代码添加到以初始化 code file 创建的文件中 .

{
  "name": "append_to_code_file",
  "arguments": {
    "file_path": "/path/to/code/storage/my_script_abc123.py",
    "content": "\ndef another_function():\n    print('This was appended to the file')\n"
  }
}

8. 联合国. execute_code_file

执行已有的 Python 文件。 以初始化 code file 和 appind to code file 建立代码后, 将此作为最后一步 .

{
  "name": "execute_code_file",
  "arguments": {
    "file_path": "/path/to/code/storage/my_script_abc123.py"
  }
}

9. 国家. read_code_file

读取已存在的 Python 代码文件的内容。 在附加更多内容或执行之前, 使用此程序来验证文件的当前状态 .

{
  "name": "read_code_file",
  "arguments": {
    "file_path": "/path/to/code/storage/my_script_abc123.py"
  }
}

使用量

配置后, MCP 代码执行器将允许 LLMS 通过生成指定的文件执行 Python 代码 CODE_STORAGE_DIR 并在配置的环境中运行.

LLMS可以通过在它们的提示中引用这个MCP服务器来生成和执行代码.

处理大码块

对于可能超过LLM符号限制的较大代码块,使用递增代码生成方法:

  1. 初始化文件 使用 initialize_code_file
  2. 添加更多代码 使用 append_to_code_file
  3. 校验文件内容 如果需要使用的话 read_code_file
  4. 执行完整的代码 使用 execute_code_file

这种方法允许LLMs写出复杂的多段代码而不会跑入符号限制.

后向兼容性

这个软件包与更早的版本保持了后向相容性. 仅指定了Conda环境的前几个版本的用户将继续工作,其配置没有任何改变.

捐款

欢迎捐款! 请打开一个问题或提交拉动请求.

许可证

这个项目根据麻省理工学院的许可证获得许可.

版本与发布记录

@geobio/code_execution_server 共发布 2 个版本,首次发布于 2025/07/03;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.2.1latest2025/07/031.4 年前
0.2.02025/07/031.4 年前

关于 @geobio/code_execution_server 的常见问题

@geobio/code_execution_server 是什么?

执行代码

如何安装 @geobio/code_execution_server?

在项目目录运行 npm install @geobio/code_execution_server,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 mcp_code_execution_server,可以用 npx mcp_code_execution_server 直接运行。

@geobio/code_execution_server 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/geobio__code_execution_server 是否存在。

@geobio/code_execution_server 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@geobio/code_execution_server 可以商用吗?

@geobio/code_execution_server 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@geobio/code_execution_server 的下载量有多少?

根据 npm 官方下载统计,@geobio/code_execution_server 在 2026/10/16 – 2026/11/14 这 30 天内被下载 3,061 次,日均约 102 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@geobio/code_execution_server 还在维护吗?

最新版本 0.2.1 发布于 2025/07/03(1.4 年前);至今共发布 2 个版本,其中过去 12 个月发布了 0 个;首次发布于 2025/07/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。