Skip to main content
Glama

MCP Code Executor

MIT License
186
  • Linux
  • Apple

MCP 코드 실행기

MCP 코드 실행기는 LLM이 지정된 Python 환경 내에서 Python 코드를 실행할 수 있도록 하는 MCP 서버입니다. 이를 통해 LLM은 환경에 정의된 라이브러리 및 종속성에 접근하여 코드를 실행할 수 있습니다. 또한 토큰 제한을 초과할 수 있는 대규모 코드 블록을 처리하기 위한 증분 코드 생성을 지원합니다.

특징

  • LLM 프롬프트에서 Python 코드 실행
  • 토큰 제한을 극복하기 위한 증분 코드 생성 지원
  • 지정된 환경(Conda, virtualenv 또는 UV virtualenv) 내에서 코드 실행
  • 필요할 때 종속성을 설치하세요
  • 패키지가 이미 설치되어 있는지 확인하세요
  • 런타임에 환경을 동적으로 구성합니다.
  • 구성 가능한 코드 저장 디렉토리

필수 조건

  • Node.js가 설치됨
  • 다음 중 하나:
    • 원하는 Conda 환경이 생성된 Conda가 설치됨
    • 파이썬 가상환경
    • UV 가상 환경

설정

  1. 이 저장소를 복제하세요:

지엑스피1

  1. 프로젝트 디렉토리로 이동합니다.
cd mcp_code_executor
  1. Node.js 종속성을 설치하세요.
npm install
  1. 프로젝트를 빌드하세요:
npm run build

구성

MCP 코드 실행기 서버를 구성하려면 MCP 서버 구성 파일에 다음을 추가하세요.

Node.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" } } } }

Docker 사용

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

참고: Dockerfile은 venv-uv 환경 유형에서만 테스트되었습니다. 다른 환경 유형에는 추가 구성이 필요할 수 있습니다.

환경 변수

필수 변수
  • CODE_STORAGE_DIR : 생성된 코드가 저장될 디렉토리
환경 유형(설정 하나 선택)
  • Conda의 경우:
    • ENV_TYPE : conda 로 설정
    • CONDA_ENV_NAME : 사용할 Conda 환경의 이름
  • 표준 가상 환경의 경우:
    • ENV_TYPE : venv 로 설정
    • VENV_PATH : virtualenv 디렉토리 경로
  • UV Virtualenv의 경우:
    • ENV_TYPE : venv-uv 로 설정
    • UV_VENV_PATH : UV virtualenv 디렉토리 경로

사용 가능한 도구

MCP 코드 실행기는 LLM에 다음과 같은 도구를 제공합니다.

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 코드 파일에 내용을 추가합니다. 이 기능을 사용하면 initialize_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 파일을 실행합니다. 이 단계는 initialize_code_file 및 append_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 코드 실행기를 구성하면 지정된 CODE_STORAGE_DIR 에 파일을 생성하고 구성된 환경 내에서 실행하여 LLM이 Python 코드를 실행할 수 있습니다.

LLM은 프롬프트에서 이 MCP 서버를 참조하여 코드를 생성하고 실행할 수 있습니다.

대용량 코드 블록 처리

LLM 토큰 제한을 초과할 수 있는 더 큰 코드 블록의 경우 증분 코드 생성 방식을 사용하세요.

  1. initialize_code_file 사용하여 기본 구조로 파일을 초기화합니다 .
  2. append_to_code_file 사용하여 후속 호출에 더 많은 코드를 추가합니다.
  3. 필요한 경우 read_code_file 사용하여 파일 내용을 확인하세요.
  4. execute_code_file 사용하여 전체 코드를 실행합니다.

이 접근 방식을 사용하면 LLM은 토큰 제한에 걸리지 않고 복잡하고 여러 부분으로 구성된 코드를 작성할 수 있습니다.

이전 버전과의 호환성

이 패키지는 이전 버전과의 하위 호환성을 유지합니다. Conda 환경만 지정한 이전 버전 사용자는 구성을 변경하지 않고도 계속 작업할 수 있습니다.

기여하다

기여를 환영합니다! 이슈를 개설하거나 풀 리퀘스트를 제출해 주세요.

특허

이 프로젝트는 MIT 라이선스에 따라 라이선스가 부여되었습니다.

Deploy Server
A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

local-only server

The server can only run on the client's local machine because it depends on local resources.

LLM이 지정된 Conda 환경에서 Python 코드를 실행할 수 있도록 하여 효율적인 코드 실행에 필요한 라이브러리와 종속성에 액세스할 수 있도록 합니다.

  1. 특징
    1. 필수 조건
      1. 설정
        1. 구성
          1. Node.js 사용하기
          2. Docker 사용
          3. 환경 변수
        2. 사용 가능한 도구
          1. 1. execute_code
          2. 2. install_dependencies
          3. 3. check_installed_packages
          4. 4. configure_environment
          5. 5. get_environment_config
          6. 6. initialize_code_file
          7. 7. append_to_code_file
          8. 8. execute_code_file
          9. 9. read_code_file
        3. 용법
          1. 대용량 코드 블록 처리
        4. 이전 버전과의 호환성
          1. 기여하다
            1. 특허

              Related MCP Servers

              • A
                security
                F
                license
                A
                quality
                A Model Context Protocol server that allows LLMs to interact with Python environments, execute code, and manage files within a specified working directory.
                Last updated -
                9
                66
                • Linux
                • Apple
              • -
                security
                A
                license
                -
                quality
                An interactive Python code execution environment that allows users and LLMs to safely execute Python code and install packages in isolated Docker containers.
                Last updated -
                25
                Apache 2.0
              • -
                security
                A
                license
                -
                quality
                An interactive Python code execution tool that allows users and LLMs to safely execute Python code and install packages in isolated Docker containers.
                Last updated -
                25
                Apache 2.0
              • A
                security
                F
                license
                A
                quality
                A Model Context Protocol server that allows LLMs to interact with Python environments, enabling code execution, file operations, package management, and development workflows.
                Last updated -
                9

              View all related MCP servers

              MCP directory API

              We provide all the information about MCP servers via our MCP API.

              curl -X GET 'https://glama.ai/api/mcp/v1/servers/bazinga012/mcp_code_executor'

              If you have feedback or need assistance with the MCP directory API, please join our Discord server