Content
# Sandbox Fusion MCP Server
This is an implementation of an MCP (Machine Code Protocol) server that interfaces with Sandbox Fusion, providing code interpreter functionality for large language models.
## Features
- Supports code execution in multiple programming languages
- Supports execution of Jupyter notebooks
- Communicates with clients via stdio interaction
- Provides resource and tool APIs for large language models to call
## Supported Programming Languages
- Python
- JavaScript/TypeScript
- Bash
- R
- Julia
- Go
- Java
- C++
- Rust
- PHP
## Installation
### Environment Requirements
- Python 3.10+
- Conda (recommended for environment management)
### Installation Steps
1. Clone the repository
```bash
git clone https://github.com/happyZYM/sandbox-fusion-mcp.git
cd sandbox-fusion-mcp
```
2. Create and activate the Conda environment
```bash
conda env create -f environment.yml
conda activate mcp-sandbox-fusion
```
## Configuration
The server is configured via environment variables:
- `SANDBOX_FUSION_ENDPOINT`: The endpoint address for the Sandbox Fusion API, default is `http://localhost:8000`
## Running
Run the server using the provided launch script:
```bash
./launch.sh
```
Or run the Python script directly:
```bash
python server.py
```
## API Description
### Resources
The server provides the following resources:
1. `sandbox://languages` - Get the list of supported programming languages
2. `sandbox://endpoint` - Get the current configured Sandbox Fusion endpoint information
### Tools
The server provides the following tools:
1. `execute_code` - Execute a code snippet
- Parameters:
- `code` (string): The code to execute
- `language` (string, optional): The programming language, default is "python"
- `timeout` (integer, optional): Execution timeout (seconds)
2. `execute_jupyter` - Execute a Jupyter notebook
- Parameters:
- `notebook_content` (string): Jupyter notebook content (in JSON format)
- `timeout` (integer, optional): Execution timeout (seconds)
### Prompt Templates
The server provides the following prompt templates:
1. `code_execution_prompt` - Code execution prompt template
- Parameters:
- `language` (string, optional): The programming language, default is "python"
- `description` (string, optional): Description of the code task
2. `jupyter_execution_prompt` - Jupyter notebook execution prompt template
- Parameters:
- `description` (string, optional): Description of the notebook task
## Client Integration
The MCP server communicates with clients via stdio interaction, and clients can communicate using JSON-RPC.
Example: List available tools
```json
{"jsonrpc": "2.0", "method": "list_tools", "params": {}, "id": 1}
```
## Troubleshooting
If you encounter issues, please check the following log files:
- `mcp_server.log`: Main server log
- `mcp_stderr.log`: Standard error output log
## Development
### Project Structure
```
sandbox-fusion-mcp/
├── server.py - MCP server implementation
├── launch.sh - Launch script
├── environment.yml - Conda environment configuration
└── README.md - Documentation
```
### Adding New Features
To add new tools or resources, modify `server.py` following this pattern:
```python
@mcp_server.tool()
def your_tool_name(param1: str, param2: int = 0) -> str:
"""
Tool description
Parameters:
- param1: Description of parameter 1
- param2: Description of parameter 2
"""
# Implementation logic
return json.dumps(result)
@mcp_server.resource("sandbox://your_resource")
def your_resource_function() -> str:
"""Resource description"""
# Implementation logic
return json.dumps(result)
```
## Notes
- Ensure that `stderr` is redirected to the log file to avoid interfering with stdio communication
- Tool functions should return results in JSON string format
- Handle all possible exceptions and return useful error messages when errors occur
## License
MIT
You Might Also Like
Ollama
Ollama enables easy access to large language models on various platforms.

n8n
n8n is a secure workflow automation platform for technical teams with 400+...
OpenWebUI
Open WebUI is an extensible web interface for customizable applications.

Dify
Dify is a platform for AI workflows, enabling file uploads and self-hosting.

Zed
Zed is a high-performance multiplayer code editor from the creators of Atom.
MarkItDown MCP
markitdown-mcp is a lightweight MCP server for converting various URIs to Markdown.