# @geobio/code\_execution\_server 中文文档

规范地址：https://npmcn.com/package/%40geobio/code_execution_server/

版本：0\.2\.1
npm 元数据更新时间：2025-07-02T21:32:20.951Z
中文译文更新时间：2026-11-16T04:18:59.618Z
软件包许可：未声明

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40geobio/code_execution_server
原文对照：https://npmcn.com/package/%40geobio/code_execution_server/?lang=original

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：39.7 kB，4 个文件
- 模块格式：ES Module
- TypeScript 类型：未声明
- 运行依赖：2 个
- 首次发布：2025-07-02T21:20:56.434Z
- 最新版本发布：2025-07-02T21:32:20.778Z
- 近 30 天下载量：3061（2026-10-16 至 2026-11-14，npm 官方下载统计）
- 已发布版本数：2（近 12 个月 0 个）

## 中文简介

执行代码

## 安装

```sh
npm install @geobio/code_execution_server
```

也可以使用：`pnpm add @geobio/code_execution_server`、`yarn add @geobio/code_execution_server`、`bun add @geobio/code_execution_server`

## README

# MCP 代码执行器

[![smithery badge](https://smithery.ai/badge/@bazinga012/mcp_code_executor)](https://smithery.ai/server/@bazinga012/mcp_code_executor)

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

[![Code Executor MCP server](https://glama.ai/mcp/servers/45ix8xode3/badge)](https://glama.ai/mcp/servers/45ix8xode3)

## 特征

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

## 先决条件

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

## 设置

1.  克隆此寄存器 :

```bash
git clone https://github.com/bazinga012/mcp_code_executor.git
```

2.  导航到项目目录 :

```bash
cd mcp_code_executor
```

3.  安装 Node.js 依赖性 :

```bash
npm install
```

4.  构建工程 :

```bash
npm run build
```

## 配置

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

### 使用节点.js

```json
{
  "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"
      }
    }
  }
}
```

### 使用嵌入器

```json
{
  "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 代码 。 最适合短代码片段 .

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

### 2\. 联合国. `install_dependencies`

在环境中安装 Python 包.

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

### 3个. `check_installed_packages`

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

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

### 4.四. `configure_environment`

动态地改变环境配置.

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

### 5 (韩语). `get_environment_config`

获得当前环境配置.

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

### 6\. 国家. `initialize_code_file`

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

```json
{
  "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 创建的文件中 .

```json
{
  "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 建立代码后, 将此作为最后一步 .

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

### 9\. 国家. `read_code_file`

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

```json
{
  "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 是什么？

执行代码

### 如何安装 @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 和提交记录判断。

