### Conda Setup Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/configuration.md Example of setting up the environment for Conda. ```bash export CODE_STORAGE_DIR="/tmp/code_storage" export ENV_TYPE="conda" export CONDA_ENV_NAME="data_science" node build/index.js ``` -------------------------------- ### Package Installation Failure Example Response Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/errors.md An example of a JSON response when a package installation fails, including the environment type and the specific error message from the package manager. ```json { "status": "error", "env_type": "conda", "error": "PackageNotFoundError: Packages missing in current channels..." } ``` -------------------------------- ### Standard Virtualenv Setup Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/configuration.md Example of setting up the environment for a standard virtualenv. ```bash export CODE_STORAGE_DIR="/tmp/code_storage" export ENV_TYPE="venv" export VENV_PATH="/home/user/my_project_env" node build/index.js ``` -------------------------------- ### UV Virtualenv Setup Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/configuration.md Example of setting up the environment for UV virtualenv. ```bash export CODE_STORAGE_DIR="/tmp/code_storage" export ENV_TYPE="venv-uv" export UV_VENV_PATH="/home/user/.venv" node build/index.js ``` -------------------------------- ### Install Dependencies Tool Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/README.md Example JSON payload for the `install_dependencies` tool, used to install Python packages. ```json { "name": "install_dependencies", "arguments": { "packages": ["numpy", "pandas", "matplotlib"] } } ``` -------------------------------- ### Install Dependencies Request Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/README.md Example JSON payload for installing Python packages. ```json { "packages": ["numpy", "pandas", "matplotlib"] } ``` -------------------------------- ### Handling Installation Failures Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/dependency-management.md Example of handling potential installation failures, such as an unknown package. ```typescript const result = await installDependencies(["unknown-package-name"]); const response = JSON.parse(result.text); if (response.status === 'error') { // Package not found or other error console.error("Install error:", response.error); // Check package name spelling, availability } ``` -------------------------------- ### Installation with Specific Versions Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/dependency-management.md Example of installing packages with specific version requirements. ```typescript const packages = [ "numpy==1.24.0", "pandas>=1.5.0", "scikit-learn>=1.2.0" ]; const result = await installDependencies(packages); ``` -------------------------------- ### Response Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/endpoints.md An example of a successful response from the check_installed_packages tool. ```json { "status": "success", "env_type": "conda", "all_installed": false, "not_installed": ["non_existent_package"], "package_details": { "numpy": { "installed": true, "version": "1.24.0", "location": "/opt/conda/lib/python3.10/site-packages/numpy/__init__.py" }, "pandas": { "installed": true, "version": "1.5.3", "location": "/opt/conda/lib/python3.10/site-packages/pandas/__init__.py" }, "non_existent_package": { "installed": false, "error": "Package not found" } } } ``` -------------------------------- ### VENV_PATH Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/configuration.md Example of setting the VENV_PATH environment variable. ```bash export VENV_PATH="/home/user/venvs/my_project" ``` -------------------------------- ### Check Installed Packages Tool Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/README.md Example JSON payload for the `check_installed_packages` tool, used to verify if packages are installed. ```json { "name": "check_installed_packages", "arguments": { "packages": ["numpy", "pandas", "non_existent_package"] } } ``` -------------------------------- ### CODE_STORAGE_DIR Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/configuration.md Example of setting the CODE_STORAGE_DIR environment variable. ```bash export CODE_STORAGE_DIR="/tmp/code_storage" ``` -------------------------------- ### install_dependencies Response Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/endpoints.md Example successful response from the install_dependencies endpoint. ```json { "status": "success", "env_type": "conda", "installed_packages": ["numpy", "pandas", "matplotlib"], "output": "Solving environment: done\n...\nSuccessfully installed packages\n", "warnings": null } ``` -------------------------------- ### UV_VENV_PATH Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/configuration.md Example of setting the UV_VENV_PATH environment variable. ```bash export UV_VENV_PATH="/home/user/.venv" ``` -------------------------------- ### Example Usage Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/endpoints.md An example of a request payload for the check_installed_packages tool. ```json { "packages": ["numpy", "pandas", "non_existent_package"] } ``` -------------------------------- ### initialize_code_file Response Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/endpoints.md Example of a successful response from initialize_code_file. ```json { "status": "success", "message": "File initialized successfully", "file_path": "/code/storage/my_app_x9y8z7w6.py", "filename": "my_app_x9y8z7w6.py" } ``` -------------------------------- ### ENV_TYPE for Conda Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/configuration.md Example of setting ENV_TYPE to 'conda'. ```bash export ENV_TYPE="conda" ``` -------------------------------- ### ENV_TYPE for Virtualenv Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/configuration.md Example of setting ENV_TYPE to 'venv'. ```bash export ENV_TYPE="venv" ``` -------------------------------- ### Example Usage Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/dependency-management.md Example of how to use the installDependencies function and parse the result. ```typescript const result = await installDependencies(["numpy", "pandas", "matplotlib"]); const response = JSON.parse(result.text); if (response.status === 'success') { console.log("Installed packages:", response.installed_packages); console.log("Output:", response.output); } else { console.error("Installation failed:", response.error); } ``` -------------------------------- ### initialize_code_file Example Usage Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/endpoints.md Example of a request to initialize a Python file. ```json { "content": "def main():\n print('Hello, World!')\n\nif __name__ == '__main__':\n main()", "filename": "my_app" } ``` -------------------------------- ### Dynamic Tool Description Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/server-core.md Example of a tool description that includes the current environment type. ```string "Execute Python code in the environment. For short code snippets only." ``` -------------------------------- ### CONDA_ENV_NAME Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/configuration.md Example of setting the CONDA_ENV_NAME environment variable. ```bash export CONDA_ENV_NAME="my_ml_env" ``` -------------------------------- ### ENV_TYPE for UV Virtualenv Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/configuration.md Example of setting ENV_TYPE to 'venv-uv'. ```bash export ENV_TYPE="venv-uv" ``` -------------------------------- ### Get Environment Config Tool Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/README.md Example JSON payload for the `get_environment_config` tool, used to retrieve current environment settings. ```json { "name": "get_environment_config", "arguments": {} } ``` -------------------------------- ### Example Usage Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/dependency-management.md Demonstrates how to use the `checkPackageInstallation` function and process its results. ```typescript const result = await checkPackageInstallation([ "numpy", "pandas", "non_existent_package" ]); const response = JSON.parse(result.text); console.log("Environment:", response.env_type); console.log("All installed:", response.all_installed); console.log("Missing packages:", response.not_ तरीके); // Check individual package details for (const [pkg, info] of Object.entries(response.package_details)) { if (info.installed) { console.log(`${pkg} version: ${info.version}`); } } ``` -------------------------------- ### Conditional Installation Pattern Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/dependency-management.md Shows a pattern for checking installed packages and then conditionally installing any missing ones. ```typescript // Check if packages are installed const checkResult = await checkPackageInstallation(["numpy", "pandas"]); const checkResponse = JSON.parse(checkResult.text); // Install only missing packages if (!checkResponse.all_installed) { const missing = checkResponse.not_installed; const installResult = await installDependencies(missing); const installResponse = JSON.parse(installResult.text); if (installResponse.status === 'success') { console.log("Missing packages installed"); } } ``` -------------------------------- ### Example Tool Schema Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/server-core.md An example of an MCP JSON Schema for the 'execute_code' tool. ```json { "name": "execute_code", "description": "Execute Python code in the conda environment...", "inputSchema": { "type": "object", "properties": { "code": { "type": "string", "description": "Python code to execute" }, "filename": { "type": "string", "description": "Optional: Name of the file to save the code..." } }, "required": ["code"] } } ``` -------------------------------- ### configure_environment Response Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/endpoints.md Example of a successful response after configuring a conda environment. ```json { "status": "success", "message": "Environment configuration updated", "previous": { "type": "conda", "conda_name": "base" }, "current": { "type": "conda", "conda_name": "my_ml_env" } } ``` -------------------------------- ### get_environment_config Response Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/endpoints.md Example of a successful response showing the current environment configuration. ```json { "status": "success", "config": { "type": "conda", "conda_name": "my_ml_env" } } ``` -------------------------------- ### Data Analysis Workflow Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/architecture.md An example workflow for performing data analysis using the MCP Code Executor, including package checking, installation, and code execution. ```python 1. Check packages: check_installed_packages(["pandas", "numpy"]) 2. Install if needed: install_dependencies(missing_packages) 3. Execute code: execute_code(analysis_code) 4. Return results to LLM ``` -------------------------------- ### read_code_file Response Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/endpoints.md Example successful response from the read_code_file endpoint. ```json { "status": "success", "content": "def main():\n print('Hello, World!')\n\nif __name__ == '__main__':\n main()\n\ndef helper_function():\n return 42\n\nprint(helper_function())", "file_path": "/code/storage/my_app_x9y8z7w6.py" } ``` -------------------------------- ### checkPackageInstallation Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/dependency-management.md Checks if specified packages are installed in the environment. It returns a JSON string indicating the installation status and any packages that are not installed. ```typescript const result = await checkPackageInstallation(["torch"]); const response = JSON.parse(result.text); if (response.status === 'error') { console.error("Check failed:", response.error); // Environment might be broken } else if (!response.all_installed) { console.log("Need to install:", response.not_installed); } ``` -------------------------------- ### execute_code Response Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/endpoints.md Example of a successful response from execute_code. ```json { "status": "success", "output": "pi = 3.141592653589793\nsqrt(2) = 1.4142135623730951\n", "file_path": "/code/storage/math_example_a1b2c3d4.py", "generated_filename": "math_example_a1b2c3d4.py" } ``` -------------------------------- ### Install Node.js Dependencies Source: https://github.com/bazinga012/mcp_code_executor/blob/master/README.md Installs the necessary Node.js dependencies for the project. ```bash npm install ``` -------------------------------- ### execute_code_file Response Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/endpoints.md Example of a successful response from the execute_code_file tool. ```json { "status": "success", "output": "42\n", "file_path": "/code/storage/my_app_x9y8z7w6.py" } ``` -------------------------------- ### Example Usage of initializeCodeFile Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/code-execution.md An example demonstrating how to use the initializeCodeFile function and process its response. ```typescript const result = await initializeCodeFile( "import numpy as np\n" + "data = np.array([1, 2, 3])\n" + "print(data.mean())", "stats_analysis" ); const response = JSON.parse(result.text); if (response.status === 'success') { const filePath = response.file_path; // Use filePath with appendToCodeFile or executeCodeFromFile } ``` -------------------------------- ### MCP Client Request Example (tools/list) Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/server-core.md An example of a JSON-RPC 2.0 message sent by an MCP Client to request a list of available tools. ```json { "jsonrpc": "2.0", "id": , "method": "tools/list" } ``` -------------------------------- ### configure_environment Example Usage Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/endpoints.md Example JSON payload for configuring a conda environment. ```json { "type": "conda", "conda_name": "my_ml_env" } ``` -------------------------------- ### MCP Server Response Example (tools/list) Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/server-core.md An example of a JSON-RPC 2.0 response from the MCP Server after a tools/list request. ```json { "jsonrpc": "2.0", "id": , "result": { "tools": [...] } } ``` -------------------------------- ### MCP Server Response Example (tools/call) Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/server-core.md An example of a JSON-RPC 2.0 response from the MCP Server after a tools/call request, showing tool output. ```json { "jsonrpc": "2.0", "id": , "result": { "content": [{ "type": "text", "text": "{\"status\": \"success\", \"output\": \"hello\\n\"}", "isError": false }] } } ``` -------------------------------- ### execute_code Example Usage Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/endpoints.md Example of a request to execute Python code. ```json { "code": "import math\nprint(f'pi = {math.pi}')\nprint(f'sqrt(2) = {math.sqrt(2)}')", "filename": "math_example" } ``` -------------------------------- ### execute_code_file Example Usage Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/endpoints.md Example of a request payload for the execute_code_file tool. ```json { "file_path": "/code/storage/my_app_x9y8z7w6.py" } ``` -------------------------------- ### append_to_code_file Response Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/endpoints.md Example of a successful response from the append_to_code_file tool. ```json { "status": "success", "message": "Content appended successfully", "file_path": "/code/storage/my_app_x9y8z7w6.py" } ``` -------------------------------- ### MCP Client Configuration (Claude, Cline, etc.) Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/configuration.md Example of adding MCP client configuration to the settings file. ```json { "mcpServers": { "code-executor": { "command": "node", "args": ["/path/to/mcp_code_executor/build/index.js"], "env": { "CODE_STORAGE_DIR": "/tmp/code_storage", "ENV_TYPE": "conda", "CONDA_ENV_NAME": "my_ml_env" } } } } ``` -------------------------------- ### read_code_file example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/README.md Example of how to use the `read_code_file` function, showing the expected JSON argument structure. ```json { "name": "read_code_file", "arguments": { "file_path": "/path/to/code/storage/my_script_abc123.py" } } ``` -------------------------------- ### Configure Environment Tool Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/README.md Example JSON payload for the `configure_environment` tool, used to dynamically change environment settings. ```json { "name": "configure_environment", "arguments": { "type": "conda", "conda_name": "new_env_name" } } ``` -------------------------------- ### readCodeFile Example Usage Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/code-execution.md Example of how to use readCodeFile to retrieve and parse file content. ```typescript const result = await readCodeFile(filePath); const response = JSON.parse(result.text); if (response.status === 'success') { console.log("Current file content:"); console.log(response.content); } ``` -------------------------------- ### Server Startup Function Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/server-core.md The main function for starting the MCP Server, setting up logging, and initializing the transport layer. ```typescript async function main() { console.error(`Info: Starting MCP Server with ${ENV_CONFIG.type} environment`); console.error(`Info: Code storage directory: ${CODE_STORAGE_DIR}`); const transport = new StdioServerTransport(); await server.connect(transport); } main().catch((error) => { console.error("Server error:", error); process.exit(1); }); ``` -------------------------------- ### Example of Internal Usage Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/environment-config.md An example demonstrating how getPlatformSpecificCommand is used within the executeCode function, including the expected output for a Unix environment with Conda. ```typescript // In executeCode function const pythonCmd = platform() === 'win32' ? `python -u "${filePath}"` : `python3 -u "${filePath}"`; const { command, options } = getPlatformSpecificCommand(pythonCmd); // Result on Unix with conda: // command: "source $(conda info --base)/etc/profile.d/conda.sh && conda activate my_env && python3 -u \"/path/to/file.py\"" // options: { shell: '/bin/bash' } const { stdout, stderr } = await execAsync(command, { cwd: CODE_STORAGE_DIR, env: { ...process.env, PYTHONUNBUFFERED: '1' }, ...options }); ``` -------------------------------- ### Environment Switching Workflow Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/architecture.md An example workflow for switching environments using the MCP Code Executor, including checking the current environment, switching, verifying, and executing code. ```python 1. Check current: get_environment_config() 2. Switch: configure_environment(new_config) 3. Verify: get_environment_config() 4. Execute: execute_code() with new environment ``` -------------------------------- ### Initialize Code File Tool Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/README.md Example JSON payload for the `initialize_code_file` tool, used to create a new Python file for incremental code generation. ```json { "name": "initialize_code_file", "arguments": { "content": "def main():\n print('Hello, world!')\n\nif __name__ == '__main__':\n main()", "filename": "my_script" } } ``` -------------------------------- ### MCP Client Request Example (tools/call) Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/server-core.md An example of a JSON-RPC 2.0 message sent by an MCP Client to call a tool, specifically 'execute_code'. ```json { "jsonrpc": "2.0", "id": , "method": "tools/call", "params": { "name": "execute_code", "arguments": { "code": "print('hello')" } } } ``` -------------------------------- ### Server Capabilities Declaration Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/server-core.md An example of how the server declares its capabilities, specifically indicating support for tools but not resources or prompts. ```typescript { capabilities: { tools: {} } } ``` -------------------------------- ### append_to_code_file Example Usage Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/endpoints.md Example of a request payload for the append_to_code_file tool. ```json { "file_path": "/code/storage/my_app_x9y8z7w6.py", "content": "\ndef helper_function():\n return 42\n\nprint(helper_function())" } ``` -------------------------------- ### Code Generation Workflow Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/architecture.md An example workflow for code generation using the MCP Code Executor, demonstrating initialization, appending code, verification, and execution. ```python 1. Initialize: initialize_code_file(skeleton_code) 2. Build: append_to_code_file(part1) 3. Continue: append_to_code_file(part2) 4. Verify: read_code_file() to check syntax 5. Execute: execute_code_file() 6. Return: Return execution results ``` -------------------------------- ### MCP Code Executor Configuration (Docker) Source: https://github.com/bazinga012/mcp_code_executor/blob/master/README.md Configuration example for setting up the MCP Code Executor server using Docker. ```json { "mcpServers": { "mcp-code-executor": { "command": "docker", "args": [ "run", "-i", "--rm", "mcp-code-executor" ] } } } ``` -------------------------------- ### appendToCodeFile Example Usage Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/code-execution.md Example of how to use appendToCodeFile to add multiple code segments to a file. ```typescript // Continue from previous example await appendToCodeFile(filePath, "\n\ndef process_data(arr):\n return arr * 2"); // Add more code in subsequent calls await appendToCodeFile(filePath, "\n\nresult = process_data(data)"); await appendToCodeFile(filePath, "\nprint(result)"); // Finally execute const execResult = await executeCodeFromFile(filePath); ``` -------------------------------- ### executeCodeFromFile Example Usage Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/code-execution.md An example of how to use the executeCodeFromFile function in TypeScript. ```typescript const result = await executeCodeFromFile("/code/storage/my_script.py"); const response = JSON.parse(result.text); if (response.status === 'success') { console.log("Output:", response.output); } else { console.error("Execution failed:", response.error); } ``` -------------------------------- ### Execute Code File Tool Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/README.md Example JSON payload for the `execute_code_file` tool, used to run a complete Python script from a file. ```json { "name": "execute_code_file", "arguments": { "file_path": "/path/to/code/storage/my_script_abc123.py" } } ``` -------------------------------- ### executeCode Example Usage Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/code-execution.md An example of how to use the executeCode function in TypeScript. ```typescript const result = await executeCode( "import sys\nprint(f'Python {sys.version}')", "/code/storage/test_abc123.py" ); const response = JSON.parse(result.text); console.log(response.output); ``` -------------------------------- ### Dependency Installation Flow Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/architecture.md Diagram outlining the process for installing and checking Python package dependencies using the MCP Code Executor. ```text LLM Client ↓ install_dependencies(packages) ├─ Build package list ├─ Select package manager (conda/pip/uv) ├─ Get platform-specific activation command ├─ Execute: activate_env && pip install packages ├─ Capture output └─ Return JSON response ↓ check_installed_packages(packages) ├─ Create temporary Python check script ├─ Write script to CODE_STORAGE_DIR ├─ Execute check script in environment ├─ Parse import success/failure └─ Return detailed per-package status ↓ LLM Client receives installation status ``` -------------------------------- ### Execute Code Tool Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/README.md Example JSON payload for the `execute_code` tool, used to run Python code snippets. ```json { "name": "execute_code", "arguments": { "code": "import numpy as np\nprint(np.random.rand(3,3))", "filename": "matrix_gen" } } ``` -------------------------------- ### Switching Environments Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/README.md Example JSON payload for switching environments using the 'conda' type. ```json { "type": "conda", "conda_name": "new_environment" } ``` -------------------------------- ### MCP Code Executor Configuration (Node.js) Source: https://github.com/bazinga012/mcp_code_executor/blob/master/README.md Configuration example for setting up the MCP Code Executor server using Node.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" } } } } ``` -------------------------------- ### Example Usage of validateEnvironmentConfig Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/environment-config.md Demonstrates how to use the validateEnvironmentConfig function with both valid and invalid configurations. ```typescript // Valid config const error = validateEnvironmentConfig({ type: 'conda', conda_name: 'ml_env' }); console.log(error); // null (valid) // Invalid config const error2 = validateEnvironmentConfig({ type: 'conda' // Missing conda_name }); console.log(error2); // "conda_name is required when type is 'conda'" ``` -------------------------------- ### Building Complex Code with appendToCodeFile Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/code-execution.md Example demonstrating how to build complex code by initializing a file and then appending to it multiple times. ```typescript const filePath = JSON.parse( (await initializeCodeFile("import pandas as pd\n")).text ).file_path; await appendToCodeFile(filePath, "\ndf = pd.DataFrame({'a': [1, 2, 3]})"); await appendToCodeFile(filePath, "\nprint(df.describe())"); const result = await executeCodeFromFile(filePath); ``` -------------------------------- ### Version Detection Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/dependency-management.md Illustrates how to extract and display version information for installed packages. ```typescript const result = await checkPackageInstallation(["numpy", "scipy"]); const response = JSON.parse(result.text); const pkgInfo = response.package_details; // Get version info if (pkgInfo.numpy.installed && pkgInfo.numpy.version) { const version = pkgInfo.numpy.version; console.log(`NumPy ${version} is installed`); } else { console.log("NumPy not found or version unavailable"); } ``` -------------------------------- ### Error Response Structure Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/dependency-management.md JSON structure for a failed dependency installation. ```json { "status": "error", "env_type": "conda|venv|venv-uv", "error": "error message from package manager" } ``` -------------------------------- ### Execute Code Request Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/README.md Example JSON payload for executing short Python code snippets. ```json { "code": "print('Hello, World!')", "filename": "hello" } ``` -------------------------------- ### Example JSON Response for Python Runtime Error Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/errors.md This JSON shows an example of the response when a Python runtime error occurs during code execution. ```json { "status": "error", "output": "Traceback (most recent call last):\n File \"/code/storage/test_abc123.py\", line 2, in \n print(undefined_var)\nNameError: name 'undefined_var' is not defined\n", "file_path": "/code/storage/test_abc123.py" } ``` -------------------------------- ### install_dependencies Request Schema Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/endpoints.md Schema for the request to install Python dependencies. ```json { "type": "object", "properties": { "packages": { "type": "array", "items": { "type": "string" }, "description": "List of packages to install" } }, "required": ["packages"] } ``` -------------------------------- ### Example JSON Response for Python Syntax Error Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/errors.md This JSON shows an example of the response when a Python syntax error occurs during code execution. ```json { "status": "error", "output": "SyntaxError: invalid syntax\n File \"/code/storage/test_abc123.py\", line 1\n if x = 5:\n ^\nSyntaxError: invalid syntax\n", "file_path": "/code/storage/test_abc123.py" } ``` -------------------------------- ### Request Schema Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/endpoints.md Schema for the request to check installed packages. ```json { "type": "object", "properties": { "packages": { "type": "array", "items": { "type": "string" }, "description": "List of packages to check" } }, "required": ["packages"] } ``` -------------------------------- ### EnvironmentConfig Interface Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/types.md Configuration object for Python environment setup and activation. ```typescript interface EnvironmentConfig { type: 'conda' | 'venv' | 'venv-uv'; conda_name?: string; venv_path?: string; uv_venv_path?: string; } ``` -------------------------------- ### readCodeFile Verification Workflow Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/code-execution.md Example demonstrating how to use readCodeFile to verify file content after appending code. ```typescript // After appending code, verify state const readResult = await readCodeFile(filePath); const content = JSON.parse(readResult.text).content; // Check that expected code is in file if (content.includes("def my_function")) { console.log("Function definition found"); } else { // Handle issue, retry append } ``` -------------------------------- ### Success Response Structure Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/dependency-management.md JSON structure for a successful dependency installation. ```json { "status": "success", "env_type": "conda|venv|venv-uv", "installed_packages": ["numpy", "pandas", "matplotlib"], "output": "package manager output", "warnings": "stderr from package manager or undefined" } ``` -------------------------------- ### Server Creation Snippet Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/environment-config.md TypeScript code showing the instantiation of the MCP server with basic configuration. ```typescript const server = new Server( { name: "code-executor", version: "0.3.0", }, { capabilities: { tools: {}, }, } ); ``` -------------------------------- ### MCP Server Initialization Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/server-core.md Creates and configures the MCP server at module load time using the MCP SDK. ```typescript const server = new Server( { name: "code-executor", version: "0.3.0", }, { capabilities: { tools: {}, }, } ); ``` -------------------------------- ### Environment Initialization Steps Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/architecture.md Outlines the sequence of steps involved in initializing the MCP environment. ```text 1. Read environment variables 2. Validate configuration 3. Create CODE_STORAGE_DIR 4. Build MCP server 5. Register tools 6. Start stdio transport ``` -------------------------------- ### Configuration Update Pattern Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/REFERENCE-INDEX.md Steps for updating configuration. ```text 1. Store previous config 2. Spread and update config 3. Return both old and new ``` -------------------------------- ### TypeScript Response Parsing Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/README.md Example of how to parse the JSON response from MCP tools in TypeScript. ```typescript const response = JSON.parse(result.content[0].text); console.log(response.status); // "success" or "error" ``` -------------------------------- ### Configuration Update Pattern Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/server-core.md Illustrates how the environment configuration is updated by spreading the previous configuration and then overwriting changed fields. ```typescript const previousConfig = { ...ENV_CONFIG }; ENV_CONFIG = { ...ENV_CONFIG, type: args.type, ...(args.conda_name && { conda_name: args.conda_name }), ...(args.venv_path && { venv_path: args.venv_path }), ...(args.uv_venv_path && { uv_venv_path: args.uv_venv_path }) }; ``` -------------------------------- ### Append to Code File Tool Example Source: https://github.com/bazinga012/mcp_code_executor/blob/master/README.md Example JSON payload for the `append_to_code_file` tool, used to add content to an existing Python 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" } } ``` -------------------------------- ### Code Execution Pattern Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/REFERENCE-INDEX.md Steps for executing code using the MCP tool. ```text 1. Write code to file 2. Get platform-specific activation 3. Execute with Python 4. Return results ``` -------------------------------- ### Tool Handler Implementation Pattern - Step 1: Extract and Validate Arguments Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/server-core.md The first step in implementing a tool handler, focusing on extracting and validating arguments. ```typescript const args = request.params.arguments as ToolArgsInterface; if (!args?.requiredParam) { throw new Error("RequiredParam is required"); } ``` -------------------------------- ### install_dependencies Success Response Schema Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/endpoints.md Schema for a successful response from install_dependencies. ```json { "status": "success", "env_type": "conda|venv|venv-uv", "installed_packages": ["string"], "output": "string", "warnings": "string|undefined" } ``` -------------------------------- ### Command Output Format - UV Virtualenv Windows Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/environment-config.md Shell command format for UV Virtualenv activation on Windows. ```shell \Scripts\activate && ``` -------------------------------- ### CheckInstalledPackagesArgs Interface Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/types.md Arguments for the `check_installed_packages` MCP tool. ```typescript interface CheckInstalledPackagesArgs { packages?: string[]; } ``` -------------------------------- ### Build Project Source: https://github.com/bazinga012/mcp_code_executor/blob/master/README.md Builds the project using npm scripts. ```bash npm run build ``` -------------------------------- ### initialize_code_file Response Schema (Success) Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/endpoints.md Schema for a successful response from initialize_code_file. ```json { "status": "success", "message": "File initialized successfully", "file_path": "string", "filename": "string" } ``` -------------------------------- ### ConfigureEnvironmentArgs Interface Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/types.md Arguments for the `configure_environment` MCP tool. ```typescript interface ConfigureEnvironmentArgs { type: 'conda' | 'venv' | 'venv-uv'; conda_name?: string; venv_path?: string; uv_venv_path?: string; } ``` -------------------------------- ### MCP Tool Call Convention Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/README.md Standard format for MCP tool calls shown in code examples. ```json { "name": "tool_name", "arguments": { "param": "value" } } ``` -------------------------------- ### install_dependencies Error Response Schema Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/endpoints.md Schema for an error response from install_dependencies. ```json { "status": "error", "env_type": "conda|venv|venv-uv", "error": "string" } ``` -------------------------------- ### Incremental Code Pattern Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/REFERENCE-INDEX.md Steps for incremental code execution using initialize, append, and execute functions. ```text 1. initialize_code_file() — Create file 2. append_to_code_file() — Add code (repeat) 3. read_code_file() — Verify (optional) 4. execute_code_file() — Execute ``` -------------------------------- ### InitializeCodeFileArgs Interface Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/types.md Arguments for the `initialize_code_file` MCP tool. ```typescript interface InitializeCodeFileArgs { content?: string; filename?: string; } ``` -------------------------------- ### Command Output Format - UV Virtualenv Unix Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/environment-config.md Shell command format for UV Virtualenv activation on Unix-like systems. ```shell source /bin/activate && ``` -------------------------------- ### InstallDependenciesArgs Interface Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/types.md Arguments for the `install_dependencies` MCP tool. ```typescript interface InstallDependenciesArgs { packages?: string[]; } ``` -------------------------------- ### Navigate to Project Directory Source: https://github.com/bazinga012/mcp_code_executor/blob/master/README.md Changes the current directory to the cloned project directory. ```bash cd mcp_code_executor ``` -------------------------------- ### Success Response Schema Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/endpoints.md Schema for a successful response from the check_installed_packages tool. ```json { "status": "success", "env_type": "conda|venv|venv-uv", "all_installed": boolean, "not_installed": ["string"], "package_details": { "[package_name]": { "installed": boolean, "version": "string|null", "location": "string|null", "error": "string|undefined" } } } ``` -------------------------------- ### Command Output Format - Virtualenv Windows Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/environment-config.md Shell command format for Virtualenv activation on Windows. ```shell \Scripts\activate && ``` -------------------------------- ### initialize_code_file Response Schema (Error) Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/endpoints.md Schema for an error response from initialize_code_file. ```json { "status": "error", "error": "string" } ``` -------------------------------- ### ListToolsRequestSchema Handler Signature Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/server-core.md Handles MCP `tools/list` requests to return a complete list of available tools with input schemas. ```typescript server.setRequestHandler(ListToolsRequestSchema, async () => { ... }) ``` -------------------------------- ### initialize_code_file Request Schema Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/endpoints.md Schema for the request to initialize a Python file. ```json { "type": "object", "properties": { "content": { "type": "string", "description": "Initial content to write to the file" }, "filename": { "type": "string", "description": "Optional: Name of the file (default: generated UUID)" } }, "required": ["content"] } ``` -------------------------------- ### Command Output Format - Virtualenv Unix Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/environment-config.md Shell command format for Virtualenv activation on Unix-like systems. ```shell source /bin/activate && ``` -------------------------------- ### Initial Environment Configuration State Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/environment-config.md TypeScript code snippet showing the initial state of the ENV_CONFIG variable, populated from environment variables at server startup. ```typescript let ENV_CONFIG: EnvironmentConfig = { type: (process.env.ENV_TYPE || 'conda') as 'conda' | 'venv' | 'venv-uv', conda_name: process.env.CONDA_ENV_NAME, venv_path: process.env.VENV_PATH, uv_venv_path: process.env.UV_VENV_PATH }; ``` -------------------------------- ### Command Output Format - Conda Windows Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/environment-config.md Shell command format for Conda activation on Windows. ```shell conda run -n ``` -------------------------------- ### Tool Handler Implementation Pattern - Step 3: Wrap in MCP Response Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/api-reference/server-core.md The final step in implementing a tool handler, wrapping the result in the standard MCP response format. ```typescript return { content: [{ type: "text", text: result.text, isError: result.isError }] }; Returns standard MCP response format. ``` -------------------------------- ### Success Response (package operations) Source: https://github.com/bazinga012/mcp_code_executor/blob/master/_autodocs/types.md JSON structure for a successful package operation. ```json { "status": "success", "env_type": "conda|venv|venv-uv", "installed_packages": ["string"], "output": "string", "warnings": "string|undefined" } ```