HM

hoangnb24/mcp-code-mode

Developer tools

このページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。 原文を見る

23 stars 6 forks 品質 49 トレンド 10

DSpy でコード実行 MCP Server のプロトタイプ実装。 「MCPによるコード実行」アーキテクチャは、モデルとコード生成で大きな言語モデルの強みを組み合わせています.

概要

DSpy でコード実行 MCP Server のプロトタイプ実装。 「MCP によるコード実行」アーキテクチャは、コード生成における大言語モデルの強みと、ツールの統合のためのモデルコンテキストプロトコルを組み合わせたものです。 外部MCPツールをシームレスに呼び出しながら、AIエージェントは分離したサンドボックスで実行するPythonコードを書くことができます。 環境ファイルのコピーと秘密の設定: mcp servers.json で MCP サーバーを構成する: デバッグ実行スクリプトを実行することで、セットアップを確認します。 このスクリプトは、MCP クライアントをシミュレートし、サーバーに接続し、エージェントとツールが正しく機能していることを確認するためにテストタスクを実行します。 スクリプトを実行する前に: 1. mcp servers.json でやりたい MCP サーバーを設定します。 2. エージェントがスクリプト/debug executor.py でタスク変数を編集することで実行したい特定のタスクを定義します。 デフォルトでは、サーバーと同じプロセスでコードを実行するシステム(LocalPythonExecutor)を使用します.

概要(AI 翻訳)

DSpy でコード実行 MCP Server のプロトタイプ実装。 「MCP によるコード実行」アーキテクチャは、コード生成における大言語モデルの強みと、ツールの統合のためのモデルコンテキストプロトコルを組み合わせたものです。 外部MCPツールをシームレスに呼び出しながら、AIエージェントは分離したサンドボックスで実行するPythonコードを書くことができます。

クイックスタート

##1. インストール Python 3.11 +とNode.js 20 +が必要です。

##2. 設定 環境ファイルのコピーと秘密の設定:

MCP サーバーを [mcp_servers.json に設定します。

##3. サーバーの実行 コード実行 MCP サーバーを起動します。

##4. 検証 デバッグ実行スクリプトを実行することで、セットアップを確認します。 このスクリプトは、MCP クライアントをシミュレートし、サーバーに接続し、エージェントとツールが正しく機能していることを確認するためにテストタスクを実行します。

スクリプトを実行する前に: 1。 [[mcp_servers.json]でやりたいMCPサーバーを設定します。 2. エージェントが[task]変数を[scripts/debug_executor.py]で編集することで実行したい特定のタスクを定義します。

開発コマンド

| コマンド | 説明 | お問い合わせ | [pytest | 全試験の実行 | | ラフチェック.

このページは 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:

  1. Configure the MCP servers you want to interact with in mcp_servers.json.
  2. Define the specific task you want the agent to perform by editing the task variable in scripts/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

┌─────────────────────────────────────────────────────────────┐
GitHub で README 全文を見る

インストール

npx -y @modelcontextprotocol/server-filesystem /your-working-folder
MCP 初心者?mcpskill.org のガイドから始めましょう →