MCP Code Execution Tool
A Rust-based tool that provides both a command-line interface and an MCP (Model Context Protocol) server for executing JavaScript, TypeScript, and Python code in isolated environments.
Repository: https://github.com/nuwax-ai/run_code_rmcp
English | 中文
Features
- Execute JavaScript, TypeScript, and Python code in isolated environments
- JavaScript/TypeScript: Powered by Deno runtime
- Python: Powered by
uvwith automatic dependency management - Automatic code caching using blake3 hashing for faster repeated executions
- Support for ESM and CommonJS modules in JavaScript
- Automatic Python dependency parsing and installation
- Separate log capture and execution result handling
- Available as both CLI tool (
run_code_rmcp) and MCP server (script_runner)
Installation
Install CLI Tool
# Clone the repository
# Install the CLI tool (run_code_rmcp)
# Or install both CLI tool and MCP server
System Requirements
- Rust: 1.85 or higher (for building)
- Deno: Required for JavaScript/TypeScript execution
- uv: Required for Python execution and dependency management
Install Deno:
|
Install uv:
|
Usage
CLI Tool: run_code_rmcp
The run_code_rmcp command allows you to execute code directly from the command line.
Basic Syntax
Options:
--show-logs: Display execution logs--clear-cache: Clear cache before execution--use-mcp: Use MCP SDK integration (requires mcp feature)
Commands:
js: Execute JavaScript codets: Execute TypeScript codepython: Execute Python codeclear-cache: Clear cached files
Execute JavaScript/TypeScript
# Execute a JavaScript file
# Execute with parameters
# Execute TypeScript
# Execute inline code
Execute Python
# Execute a Python file
# Execute with parameters
# Execute inline code
Cache Management
# Clear all cache
# Clear specific language cache
# Clear cache before execution
Using as a Rust Library
[]
= { = "https://github.com/nuwax-ai/run_code_rmcp.git" }
use ;
async
MCP Server: script_runner
The script_runner is an MCP server that provides tools for AI assistants.
Starting the Server
# Start MCP server
# Start with verbose logging
The server communicates via stdio and waits for MCP protocol JSON requests.
Available Tools
The MCP server provides the following tools:
- run_javascript - Execute JavaScript code
- run_typescript - Execute TypeScript code
- run_python - Execute Python code
Each tool accepts:
code(string): The code to executeparams(object, optional): Parameters to pass to the handler function
Integration with AI Assistants
Add to your MCP client configuration (e.g., Claude Desktop):
Code Structure
Handler Functions
Your scripts should define a handler function that returns the result.
JavaScript/TypeScript
Supports both main and handler functions (main takes priority):
// This function takes priority
// This function is used if main is not defined
ESM modules are also supported:
import from "https://deno.land/std/http/server.ts";
Python
Supports both handler and main functions (handler takes priority):
# This function takes priority
=
return
# This function is used if handler is not defined
return
Parameter Passing
Parameters are passed to your handler function:
In your code:
Python Dependencies
Python dependencies are automatically detected and installed:
# Dependencies are automatically installed via uv
=
=
return
Log Capture
All console output is captured separately from the return value:
console.log;
console.log;
Result:
Development
# Build
# Run with cargo
# Run tests
# Build with MCP feature
# Run MCP server with cargo
Environment Pre-warming
The project includes a warm-up function to cache common dependencies:
use warm_up_all_envs;
async
TODO
- TTS (Text-to-Speech) functionality - Currently has known issues
License
This project is licensed under the Apache License 2.0. See LICENSE and NOTICE files in the root directory for details.