1
1
# JavaScript Executor MCP Server
2
2
3
- This MCP server provides JavaScript execution capabilities with a Node.js-like environment .
3
+ This MCP server provides JavaScript execution capabilities with ski runtime .
4
4
5
5
## Features
6
6
7
7
The ` executeJS ` tool provides:
8
8
9
- - ** Console API** : ` console.log() ` , ` console.error() ` , ` console.warn() `
10
- - ** File System** : ` fs.readFileSync() ` , ` fs.writeFileSync() ` , ` fs.existsSync() `
9
+ - ** Console API** : ` console.log() ` , ` console.error() ` , ` console.warn() ` (built-in)
11
10
- ** HTTP Server** : ` http.createServer() ` with request/response handling
12
- - ** Fetch API** : ` fetch() ` with Promise support for HTTP requests
13
- - ** Timers** : ` setTimeout() ` , ` clearTimeout() ` , ` setInterval() ` , ` clearInterval() `
14
- - ** Process** : ` process.argv ` , ` process.cwd() ` , ` process.exit() ` , ` process.env `
15
- - ** Module System** : ` require() ` for loading JavaScript modules
11
+ - ** HTTP Client** : ` http.request() ` for HTTP requests
12
+ - ** Fetch API** : Modern ` fetch() ` with Request, Response, Headers, FormData
13
+ - ** Timers** : ` setTimeout() ` , ` setInterval() ` , ` clearTimeout() ` , ` clearInterval() `
14
+ - ** Buffer** : Buffer, Blob, File APIs for binary data handling
15
+ - ** Crypto** : Cryptographic functions (hashing, encryption, HMAC)
16
+ - ** Additional modules** : cache, dom, encoding, ext, html, signal, stream, url
16
17
17
18
## Getting Started
18
19
@@ -36,25 +37,33 @@ codebench-mcp
36
37
37
38
``` bash
38
39
# Enable only specific modules
39
- codebench-mcp --enabled-modules console,fs,timers
40
+ codebench-mcp --enabled-modules http,fetch
40
41
41
42
# Disable specific modules (enable all others)
42
- codebench-mcp --disabled-modules http,fetch
43
+ codebench-mcp --disabled-modules timers
43
44
44
45
# Show help
45
46
codebench-mcp --help
46
47
```
47
48
48
49
** Available modules:**
49
- - ` console ` - Console logging (console.log, console.error, console.warn)
50
- - ` fs ` - File system operations (fs.readFileSync, fs.writeFileSync, fs.existsSync)
51
- - ` http ` - HTTP server creation (http.createServer)
52
- - ` fetch ` - HTTP client requests (fetch API with promises)
53
- - ` timers ` - Timer functions (setTimeout, setInterval, clearTimeout, clearInterval)
54
- - ` process ` - Process information (process.argv, process.cwd, process.env, process.exit)
55
- - ` require ` - Module loading system
56
-
57
- ** Note:** The ` executeJS ` tool description dynamically updates to show only the enabled modules and includes detailed information about what each module provides. This helps users understand exactly what JavaScript APIs are available in the simplified VM environment.
50
+ - ` http ` - HTTP server creation and client requests (import serve from 'ski/http/server')
51
+ - ` fetch ` - Modern fetch API with Request, Response, Headers, FormData (available globally)
52
+ - ` timers ` - setTimeout, setInterval, clearTimeout, clearInterval (available globally)
53
+ - ` buffer ` - Buffer, Blob, File APIs for binary data handling (available globally)
54
+ - ` cache ` - In-memory caching with TTL support (import cache from 'ski/cache')
55
+ - ` crypto ` - Cryptographic functions (hashing, encryption, HMAC) (import crypto from 'ski/crypto')
56
+ - ` dom ` - DOM Event and EventTarget APIs
57
+ - ` encoding ` - TextEncoder, TextDecoder for text encoding/decoding (available globally)
58
+ - ` ext ` - Extended context and utility functions
59
+ - ` html ` - HTML parsing and manipulation
60
+ - ` signal ` - AbortController and AbortSignal for cancellation (available globally)
61
+ - ` stream ` - ReadableStream and streaming APIs (available globally)
62
+ - ` url ` - URL and URLSearchParams APIs (available globally)
63
+
64
+ ** Default modules:** ` http ` , ` fetch ` , ` timers ` , ` buffer ` , ` crypto `
65
+
66
+ ** Note:** The ` executeJS ` tool description dynamically updates to show only the enabled modules and includes detailed information about what each module provides.
58
67
59
68
#### As a library in your Go project
60
69
@@ -200,7 +209,7 @@ To integrate the Docker image with apps that support MCP:
200
209
201
210
### executeJS
202
211
203
- Execute JavaScript code with full Node.js-like environment.
212
+ Execute JavaScript code with ski runtime environment.
204
213
205
214
** Parameters:**
206
215
- ` code ` (required): JavaScript code to execute
@@ -209,56 +218,50 @@ Execute JavaScript code with full Node.js-like environment.
209
218
``` javascript
210
219
console .log (" Hello, World!" );
211
220
212
- // File operations
213
- fs .writeFileSync (" test.txt" , " Hello from JS!" );
214
- const content = fs .readFileSync (" test.txt" );
215
- console .log (" File content:" , content);
216
-
217
- // Fetch API with promises
218
- fetch (" https://github.com/api/users/octocat" )
219
- .then (response => response .json ())
220
- .then (data => {
221
- console .log (" User:" , data .name );
222
- console .log (" Public repos:" , data .public_repos );
223
- })
224
- .catch (error => console .error (" Fetch error:" , error));
225
-
226
- // HTTP server with configurable ports and callbacks
227
- const server = http .createServer ((req , res ) => {
228
- console .log (` ${ req .method } ${ req .url } ` );
229
-
230
- res .setHeader (" Content-Type" , " application/json" );
231
- res .writeHead (200 );
232
- res .end (JSON .stringify ({
233
- message: " Hello from HTTP server!" ,
234
- method: req .method ,
235
- url: req .url
236
- }));
237
- });
221
+ // Basic JavaScript execution
222
+ const result = 2 + 3 ;
223
+ console .log (' Result:' , result);
238
224
239
- // Multiple ways to start the server:
240
- server .listen (3000 ); // Port only
241
- server .listen (3000 , () => console .log (" Started!" )); // Port + callback
242
- server .listen (3000 , " localhost" ); // Port + host
243
- server .listen (3000 , " localhost" , () => { // Port + host + callback
244
- console .log (" Server running on localhost:3000" );
225
+ // Fetch API (available globally when enabled)
226
+ const response = await fetch (' https://api.example.com/data' );
227
+ const data = await response .json ();
228
+
229
+ // HTTP server (import required)
230
+ import serve from ' ski/http/server' ;
231
+ serve (8000 , async (req ) => {
232
+ return new Response (' Hello World' );
245
233
});
246
234
247
- // Server management
248
- setTimeout (() => {
249
- server .close (); // Gracefully shutdown server
250
- }, 10000 );
235
+ // Cache operations (import required)
236
+ import cache from ' ski/cache' ;
237
+ cache .set (' key' , ' value' );
238
+ console .log (cache .get (' key' ));
239
+
240
+ // Crypto operations (import required)
241
+ import crypto from ' ski/crypto' ;
242
+ const hash = crypto .md5 (' hello' ).hex ();
243
+ console .log (' MD5 hash:' , hash);
251
244
252
- // Timers
253
- setTimeout (() => {
254
- console .log (" Timer executed!" );
255
- }, 1000 );
245
+ // Timers (available globally)
246
+ setTimeout (() => console .log (' Hello after 1 second' ), 1000 );
256
247
257
- // Process info
258
- console .log (" Current directory:" , process .cwd ());
259
- console .log (" Arguments:" , process .argv );
248
+ // Buffer operations (available globally)
249
+ const buffer = Buffer .from (' hello' , ' utf8' );
250
+ console .log (buffer .toString (' base64' ));
251
+
252
+ // URL operations (available globally)
253
+ const url = new URL (' https://example.com/path?param=value' );
254
+ console .log (' Host:' , url .host );
255
+ console .log (' Pathname:' , url .pathname );
260
256
```
261
257
258
+ ## Limitations
259
+
260
+ - ** No fs or process modules** - File system and process APIs are not available in ski runtime
261
+ - ** Module access varies** - Some modules are global (fetch, http), others may need require()
262
+ - ** Each execution creates a fresh VM** - For isolation, each execution starts with a clean state
263
+ - ** Module filtering** - Configuration exists but actual runtime filtering not fully implemented
264
+
262
265
## Building
263
266
264
267
``` bash
0 commit comments