
MCP Sandbox
Automatically converts JavaScript modules into MCP-compatible servers, making any JavaScript function accessible to AI systems through secure sandboxing with automatic type inference.
README
MCP Sandbox
<p align=center> <img width="80%" src="https://raw.githubusercontent.com/danstarns/mcp-sandbox/main/docs/banner.png#gh-dark-mode-only" alt="MCP Sandbox"/> </p>
Turn any JavaScript module into a sandboxed MCP (Model Context Protocol) server with automatic reflection and type inference.
🎯 What is MCP Sandbox?
MCP Sandbox automatically converts JavaScript modules into MCP (Model Context Protocol) compatible servers, making any JavaScript function accessible to AI systems. It uses VM sandboxing for security, automatic type inference, and generates proper MCP configurations.
✨ Features
- 🔍 Automatic Reflection - Analyzes JS modules and extracts function signatures
- 🛡️ Secure Sandboxing - Executes code in isolated VM contexts with timeouts
- 🧠 Smart Type Inference - Detects parameter types from defaults and naming patterns
- 📚 JSDoc Integration - Extracts documentation from function comments
- 📡 MCP Protocol - Full JSON-RPC 2.0 and SSE support
- 🌐 REST API - Legacy REST endpoints for easy testing
- ⚙️ TypeScript - Full type safety and IntelliSense support
🚀 Quick Start
Installation
# Install globally for CLI usage
npm install -g @mcp-sandbox/cli
# Or use in a project
npm install @mcp-sandbox/core @mcp-sandbox/cli
Basic Usage
# Start MCP server for a JavaScript module
$ mcp-sandbox start ./math-utils.js
🏗️ Initializing MCP Sandbox...
🔍 Reflecting module
📊 Discovered 2 tools:
- circleArea: Calculate area of a circle
- fibonacci: Generate Fibonacci sequence
🚀 MCP Sandbox server running at http://localhost:3000
📋 MCP Tools: http://localhost:3000/mcp/tools
⚡ MCP Execute: http://localhost:3000/mcp/execute
🔄 MCP SSE: http://localhost:3000/sse
📡 MCP JSON-RPC: http://localhost:3000/mcp/jsonrpc
⚙️ MCP Config: http://localhost:3000/mcp-config
💡 For MCP Inspector, use: http://localhost:3000/sse
Example Module
/**
* Calculate the area of a circle
* @param radius The radius of the circle
*/
function circleArea(radius = 1) {
return Math.PI * radius * radius;
}
/**
* Generate fibonacci sequence
* @param count Number of fibonacci numbers to generate
*/
function fibonacci(count = 10) {
const seq = [0, 1];
for (let i = 2; i < count; i++) {
seq[i] = seq[i - 1] + seq[i - 2];
}
return seq.slice(0, count);
}
module.exports = { circleArea, fibonacci };
Running mcp-sandbox start math-utils.js
automatically:
- 🔍 Reflects the module and discovers functions
- 📊 Generates type schemas from parameters
- 🚀 Starts MCP server at
http://localhost:3000
- 💾 Creates
mcp-config.json
for MCP clients
📡 API Endpoints
The server exposes both MCP and REST endpoints:
MCP Protocol (JSON-RPC 2.0)
POST /mcp/jsonrpc
- Main MCP endpointGET /sse
- Server-Sent Events for real-time updates
REST API (for testing)
GET /tools
- List available toolsPOST /execute/:toolName
- Execute a specific toolGET /mcp-config
- Get MCP server configurationGET /health
- Health check
Example Usage
# List tools
curl http://localhost:3000/tools
# Execute function via REST
curl -X POST http://localhost:3000/execute/circleArea \
-H "Content-Type: application/json" \
-d '{"args": {"radius": 5}}'
# MCP JSON-RPC call
curl -X POST http://localhost:3000/mcp/jsonrpc \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "fibonacci", "arguments": {"count": 8}}}'
🏗️ Programmatic Usage
import { MCPSandbox } from '@mcp-sandbox/core';
const sandbox = new MCPSandbox({
port: 3000,
timeout: 5000,
});
// Load and analyze module
await sandbox.loadModule('./my-module.js');
// Start MCP server
await sandbox.start();
// Execute tools directly
const result = await sandbox.executeTool('myFunction', {
param1: 'value1',
});
📚 Example Modules Included
The repository includes several example modules demonstrating different use cases:
Mathematical Operations (examples/math-utils.js
)
- Circle area calculation
- Fibonacci sequence generation
- Compound interest calculation
- Prime number checking
- Degree/radian conversion
- Factorial calculation
String Manipulation (examples/string-utils.js
)
- Title case conversion
- Random string generation
- Word counting
- Palindrome detection
- String reversal
- Capitalization
Array Operations (examples/array-utils.js
)
- Array shuffling (Fisher-Yates)
- Unique value extraction
- Array chunking
- Set operations (intersection, difference)
- Array flattening
Filesystem Operations (examples/filesystem-utils.js
)
- File reading/writing (async)
- Directory listing and creation
- File searching with patterns
- Disk usage calculation
- File copying and deletion
- Line-by-line file reading
🛠️ Development
# Clone repository
git clone https://github.com/danstarns/mcp-sandbox.git
cd mcp-sandbox
# Install dependencies
pnpm install
# Build all packages
pnpm build
# Run examples
pnpm example:math # Math utilities
pnpm example:filesystem # File operations
pnpm example:string # String manipulation
# Lint and format
pnpm lint && pnpm format
🔧 Configuration Options
CLI Options
mcp-sandbox start <module> [options]
Options:
-p, --port <port> Server port (default: 3000)
-h, --host <host> Server host (default: localhost)
-t, --timeout <ms> Execution timeout (default: 5000ms)
-o, --output <file> Output MCP configuration to file
Programmatic Options
interface SandboxOptions {
port?: number; // Server port (default: 3000)
host?: string; // Server host (default: 'localhost')
timeout?: number; // Execution timeout (default: 5000ms)
maxMemory?: number; // Memory limit (default: 64MB)
}
🔒 Security Features
- VM Isolation - Code runs in separate V8 contexts
- Execution Timeouts - Configurable time limits prevent infinite loops
- Memory Limits - Prevent memory exhaustion attacks
- Controlled Requires - Limited module access in sandbox
- Input Validation - Parameter type checking and validation
🎮 Testing with MCP Inspector
- Start your MCP server:
mcp-sandbox start examples/math-utils.js
- Open MCP Inspector
- Set Transport Type to "Streamable HTTP"
- Enter URL:
http://localhost:3000/mcp/jsonrpc
- Connect and test your tools!
📦 Packages
This is a monorepo containing multiple packages:
@mcp-sandbox/cli
- Command-line interface@mcp-sandbox/core
- Core library@mcp-sandbox/utils
- Shared utilities
🤝 Contributing
Contributions are welcome! Please read our Contributing Guide and check out the open issues.
📄 License
MIT License - see LICENSE for details.
🔗 Links
- GitHub Repository: https://github.com/danstarns/mcp-sandbox
- Issues: https://github.com/danstarns/mcp-sandbox/issues
- NPM CLI Package: https://www.npmjs.com/package/@mcp-sandbox/cli
- NPM Core Package: https://www.npmjs.com/package/@mcp-sandbox/core
推荐服务器

Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。