mcp-js-executor
v1.1.3
Published
MCP server that executes JavaScript code for data analysis with support for JSON, CSV, and TSV formats
Maintainers
Readme
MCP JavaScript Executor
Secure MCP server that executes JavaScript code for data analysis with support for multiple data formats using isolated-vm.
🚀 Features
- ✅ Multi-format Data Support: JSON, CSV, TSV, and pipe-separated data
- ✅ Smart Format Detection: Automatically detects data format from content (not file extension)
- ✅ Secure Execution: Isolated JavaScript environment with resource limits
- ✅ Flexible Data Input: Support for URLs and inline data
- ✅ Advanced JavaScript: Variables, functions, return statements, and complex logic
- ✅ Safety Limits: 5-second timeout and 128MB memory protection
📊 Supported Data Formats
JSON
[{"name": "John", "age": 30}, {"name": "Jane", "age": 25}]CSV (Comma-separated)
name,age,city
John,30,New York
Jane,25,BostonTSV (Tab-separated)
name age city
John 30 New York
Jane 25 BostonPipe-separated
name|age|city
John|30|New York
Jane|25|BostonNote: The MCP automatically detects the format and delimiter from the content, converting all tabular data into JavaScript arrays of objects.
Installation
npx mcp-js-executor🔧 Usage Examples
Simple Data Analysis
// Count total records
data.length
// Filter and count active items
data.filter(item => item.status === 'active').length
// Find maximum value
Math.max(...data.map(item => item.price))Complex Data Processing
// Sales analysis by month
const salesByMonth = {};
data.forEach(sale => {
const month = sale.Mese;
salesByMonth[month] = (salesByMonth[month] || 0) + sale['Totale Vendita'];
});
return Object.entries(salesByMonth).map(([month, total]) => ({month, total}));Advanced Analytics
// Find top performers with statistics
const sellers = {};
data.filter(o => o.Mese === 'agosto').forEach(o => {
sellers[o.Venditore] = (sellers[o.Venditore] || 0) + 1;
});
return Object.entries(sellers)
.map(([name, count]) => ({name, orders: count}))
.sort((a,b) => b.orders - a.orders);🌐 MCP Tool Call Format
Using URL Data Source
{
"tool": "execute_js",
"parameters": {
"url": "https://example.com/data.csv",
"code": "data.filter(item => item.status === 'active').length"
}
}Using Inline Data
{
"tool": "execute_js",
"parameters": {
"data": [{"name": "John", "age": 30}],
"code": "data.filter(person => person.age > 25).length"
}
}🔄 Data Conversion Process
- Format Detection: Analyzes content to identify delimiter (
,,\t,;,|) - Smart Parsing: Skips header lines and separator rows automatically
- Type Conversion: Converts strings to numbers/booleans when appropriate
- Object Creation: Transforms rows into JavaScript objects with column headers as keys
Example Conversion
Input CSV:
name,age,active
John,30,true
Jane,25,falseBecomes JavaScript:
[
{"name": "John", "age": 30, "active": true},
{"name": "Jane", "age": 25, "active": false}
]🛡️ Security & Limits
- Isolated Execution: Uses
isolated-vmfor complete sandboxing - Memory Limit: 128MB maximum per execution
- Timeout Protection: 5-second execution limit
- No File System Access: Cannot read/write local files
- No Network Access: Cannot make external HTTP requests (except for data fetching)
- Safe Environment: No access to Node.js modules or system functions
🔧 Technical Details
Supported Delimiters
,(comma) - Standard CSV\t(tab) - TSV files;(semicolon) - European CSV format|(pipe) - Custom delimiter format
Auto-Detection Logic
- Analyzes first data line (skipping headers and separators)
- Counts occurrence of each delimiter
- Selects most frequent delimiter
- Falls back to comma if no clear winner
Data Type Conversion
- Numbers: Automatic conversion for integers and floats
- Booleans: Converts "true"/"false" strings
- Null Values: Empty cells become
null - Strings: Everything else remains as string
📈 Version History
v1.1.0 (Current)
- ✅ Added CSV/TSV/pipe-separated data support
- ✅ Implemented smart delimiter detection
- ✅ Enhanced data parsing with type conversion
- ✅ Improved error handling for malformed data
- ✅ Maintained full backward compatibility
v1.0.2
- ✅ Initial JSON-only support
- ✅ Basic JavaScript execution
- ✅ Security isolation with isolated-vm
🤝 Contributing
This MCP server is designed for secure data analysis. When contributing:
- Maintain security isolation
- Preserve backward compatibility
- Add comprehensive tests for new data formats
- Update documentation and examples
📄 License
MIT License - Feel free to use in your projects!
