
hoangnb24/mcp-code-mode
Developer tools이 페이지는 AI로 자동 번역되었습니다. 기술적인 세부 사항은 원문을 확인하세요. 원문 보기
DSpy를 가진 코드 실행 MCP Server에 대한 프로토 타입 구현. MCP의 "Code Execution with MCP" 아키텍처는 모델과 코드 생성에 큰 언어 모델의 강점을 결합 ...
개요
DSpy를 가진 코드 실행 MCP Server에 대한 프로토 타입 구현. MCP와의 "Code Execution with MCP" 아키텍처는 도구 통합을위한 모델 Context Protocol과 함께 큰 언어 모델의 강점을 결합합니다. 이 시스템은 AI 에이전트가 외부 MCP 도구를 완벽하게 호출하면서 격리 샌드박스에서 실행되는 Python 코드를 작성할 수 있습니다. 예제 환경 파일을 복사하고 비밀을 구성: mcp servers.json에서 MCP 서버를 구성: debug executor 스크립트를 실행하여 설정 확인. 이 스크립트는 MCP 클라이언트를 시뮬레이션하고 서버에 연결하고 에이전트와 도구를 올바르게 작동하도록 테스트 작업을 실행합니다. 스크립트를 실행하기 전에: 1. mcp servers.json과 상호 작용하고 싶은 MCP 서버를 구성합니다. 2. 스크립트/debug executor.py에서 작업 변수를 편집하여 수행 할 특정 작업을 정의합니다. 기본적으로, 시스템은 서버와 같은 프로세스에서 코드를 실행하는 (LocalPythonExecutor)를 사용합니다.
개요(AI 번역)
DSpy를 가진 코드 실행 MCP Server에 대한 프로토 타입 구현. MCP와의 “Code Execution with MCP” 아키텍처는 도구 통합을위한 모델 Context Protocol과 함께 큰 언어 모델의 강점을 결합합니다. 이 시스템은 AI 에이전트가 외부 MCP 도구를 완벽하게 호출하면서 격리 샌드박스에서 실행되는 Python 코드를 작성할 수 있습니다.
빠른 시작
##1. 설치 Python 3.11+ 및 Node.js 20+를 요구합니다.
##2. 구성 예제 환경 파일을 복사하고 비밀을 구성:
MCP 서버 구성 mcp_servers.json:
##3. 서버 실행 코드 실행 MCP 서버 시작:
##4. 인증 debug executor 스크립트를 실행하여 설정 확인. 이 스크립트는 MCP 클라이언트를 시뮬레이션하고 서버에 연결하고 에이전트와 도구를 올바르게 작동하도록 테스트 작업을 실행합니다.
스크립트를 실행하기 전에:
- MCP 서버를 구성하면
mcp_servers.json]에서 상호 작용할 수 있습니다. task]scripts/debug_executor.py]]를 편집하여 수행 할 특정 작업을 정의합니다.
개발 명령
| 명령 | 설명 |
|---|---|
| [T4] | 시험 실시 |
| 'ruff 체크. |
이 페이지는 AI로 자동 번역되었습니다. 기술적인 세부 사항은 원문을 확인하세요.
README
원문 README의 일부입니다. 원문 보기.
MCP Code Mode
Prototype implementation for the Code Execution MCP Server with DSpy. The “Code Execution with MCP” architecture combines the strengths of Large Language Models at code generation with the Model Context Protocol for tool integration. This system enables an AI agent to write Python code that runs in an isolated sandbox while seamlessly calling external MCP tools.
Quick Start
1. Installation
Requires Python 3.11+ and Node.js 20+.
# Create virtual environment
python3.11 -m venv .venv
source .venv/bin/activate
# Install dependencies
pip install -e .[dev]
# Install Node.js dependencies for reference servers
npm install -g npm@latest
2. Configuration
Copy the example environment file and configure secrets:
cp .env.example .env
Configure your MCP servers in mcp_servers.json:
{
"servers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/your-working-folder"],
"description": "Local file system operations"
}
}
}
3. Running the Server
Launch the Code Execution MCP server:
python -m mcp_code_mode.executor_server
4. Verification
Verify your setup by running the debug executor script. This script simulates an MCP client, connects to the server, and runs a test task to ensure the agent and tools are working correctly.
Before running the script:
- Configure the MCP servers you want to interact with in
mcp_servers.json. - Define the specific task you want the agent to perform by editing the
taskvariable inscripts/debug_executor.py.
python scripts/debug_executor.py
Development Commands
| Command | Description |
|---|---|
pytest |
Run all tests |
ruff check . |
Lint the codebase |
black . |
Format the codebase |
mypy src |
Type check the source |
python scripts/test_dspy_sandbox.py |
Sanity check the sandbox |
python scripts/debug_executor.py |
Integration test with mock client |
Execution Environment & Guardrails
By default, the system uses a Local Python Executor (LocalPythonExecutor) which runs code in the same process as the server. This is necessary because the strict Pyodide sandbox has limitations with network I/O, preventing it from calling back to other MCP tools in some environments.
Guardrails
Even with the local executor, the system enforces policies before code execution:
- Limits: 8k characters / 400 lines max.
- Imports: Allowlist only (
json,math,re,datetime, etc.). - Tokens: Disallows potentially dangerous tokens (
subprocess,exec,eval).
Violations return a POLICY_VIOLATION error.
Note: You can force the use of the Pyodide sandbox by setting
MCP_EXECUTOR=pyodide, but this may break tool calls depending on your environment.
Architecture
Overview
┌─────────────────────────────────────────────────────────────┐
설치
npx -y @modelcontextprotocol/server-filesystem /your-working-folder