@@ -105,14 +105,14 @@ func (h *JSHandler) handleExecuteJS(
105105 ctx context.Context ,
106106 request mcp.CallToolRequest ,
107107) (* mcp.CallToolResult , error ) {
108- code , err := request .RequireString ("scriptCode " )
108+ code , err := request .RequireString ("code " )
109109 if err != nil {
110110 return nil , err
111111 }
112112
113113 // Check if this looks like HTTP server code
114114 isServerCode := strings .Contains (code , "serve(" ) || strings .Contains (code , "require('ski/http/server')" )
115-
115+
116116 if isServerCode {
117117 // For server code, run in a goroutine and return immediately
118118 return h .handleServerCode (ctx , code )
@@ -161,14 +161,14 @@ func (h *JSHandler) handleServerCode(ctx context.Context, code string) (*mcp.Cal
161161 serverStarted <- false
162162 return
163163 }
164-
164+
165165 // If no server was started, signal false and let goroutine exit
166166 select {
167167 case serverStarted <- false :
168168 default :
169169 // Channel already has a value, meaning a server was started
170170 }
171-
171+
172172 // Check if we should keep the goroutine alive
173173 select {
174174 case started := <- serverStarted :
@@ -200,41 +200,41 @@ func (h *JSHandler) setupHTTPModuleWithCallback(vm js.VM, serverStarted chan boo
200200 vm .Runtime ().Set ("__originalRequire" , vm .Runtime ().Get ("require" ))
201201 vm .Runtime ().Set ("require" , vm .Runtime ().ToValue (func (call sobek.FunctionCall ) sobek.Value {
202202 moduleName := call .Argument (0 ).String ()
203-
203+
204204 // If requesting the HTTP server module, return our wrapped version
205205 if moduleName == "ski/http/server" {
206206 httpServer := & httpmodule.Server {}
207207 value , err := httpServer .Instantiate (vm .Runtime ())
208208 if err != nil {
209209 panic (vm .Runtime ().NewGoError (err ))
210210 }
211-
211+
212212 // Wrap the serve function to detect when a server is actually started
213213 wrappedServe := vm .Runtime ().ToValue (func (call sobek.FunctionCall ) sobek.Value {
214214 // Call the original serve function
215215 serveFunc , ok := sobek .AssertFunction (value )
216216 if ! ok {
217217 panic (vm .Runtime ().NewTypeError ("serve is not a function" ))
218218 }
219-
219+
220220 result , err := serveFunc (sobek .Undefined (), call .Arguments ... )
221221 if err != nil {
222222 panic (vm .Runtime ().NewGoError (err ))
223223 }
224-
224+
225225 // Signal that a server was started
226226 select {
227227 case serverStarted <- true :
228228 default :
229229 // Channel already has a value
230230 }
231-
231+
232232 return result
233233 })
234-
234+
235235 return wrappedServe
236236 }
237-
237+
238238 // For all other modules, use the original require
239239 originalRequire , _ := sobek .AssertFunction (vm .Runtime ().Get ("__originalRequire" ))
240240 result , err := originalRequire (sobek .Undefined (), call .Arguments ... )
@@ -275,7 +275,7 @@ func (h *JSHandler) handleRegularCode(ctx context.Context, code string) (*mcp.Ca
275275 // Execute the JavaScript code with a timeout for regular code
276276 execCtx , cancel := context .WithTimeout (ctx , time .Second * 10 )
277277 defer cancel ()
278-
278+
279279 result , err := vm .RunString (execCtx , code )
280280
281281 if err != nil {
@@ -314,19 +314,19 @@ func (h *JSHandler) setupHTTPModule(vm js.VM) {
314314 vm .Runtime ().Set ("__originalRequire" , vm .Runtime ().Get ("require" ))
315315 vm .Runtime ().Set ("require" , vm .Runtime ().ToValue (func (call sobek.FunctionCall ) sobek.Value {
316316 moduleName := call .Argument (0 ).String ()
317-
317+
318318 // If requesting the HTTP server module, return our wrapped version
319319 if moduleName == "ski/http/server" {
320320 httpServer := & httpmodule.Server {}
321321 value , err := httpServer .Instantiate (vm .Runtime ())
322322 if err != nil {
323323 panic (vm .Runtime ().NewGoError (err ))
324324 }
325-
325+
326326 // Don't wrap or unref - let the server run normally
327327 return value
328328 }
329-
329+
330330 // For all other modules, use the original require
331331 originalRequire , _ := sobek .AssertFunction (vm .Runtime ().Get ("__originalRequire" ))
332332 result , err := originalRequire (sobek .Undefined (), call .Arguments ... )
@@ -374,7 +374,7 @@ func NewJSServerWithConfig(config ModuleConfig) (*server.MCPServer, error) {
374374 s .AddTool (mcp .NewTool (
375375 "executeJS" ,
376376 mcp .WithDescription (description ),
377- mcp .WithString ("scriptCode " ,
377+ mcp .WithString ("code " ,
378378 mcp .Description ("Complete JavaScript source code to execute in the ski runtime environment. This parameter accepts a full JavaScript program including variable declarations, function definitions, control flow statements, async/await operations, and module imports via require(). The code will be executed in a sandboxed environment with access to enabled ski modules. Supports modern JavaScript syntax (ES2020+) including arrow functions, destructuring, template literals, and promises. Use require() for module imports (e.g., 'const serve = require(\" ski/http/server\" )') rather than ES6 import statements. The execution context includes a console object for output, and any returned values will be displayed along with console output. For HTTP servers, they will run in the background without blocking execution completion." ),
379379 mcp .Required (),
380380 ),
@@ -427,21 +427,21 @@ func buildToolDescription(enabledModules []string) string {
427427 description .WriteString ("// Basic JavaScript execution\n " )
428428 description .WriteString ("const result = 2 + 3;\n " )
429429 description .WriteString ("console.log('Result:', result);\n \n " )
430-
430+
431431 // Create a set for faster lookup
432432 enabledSet := make (map [string ]bool )
433433 for _ , module := range enabledModules {
434434 enabledSet [module ] = true
435435 }
436-
436+
437437 // Add examples only for enabled modules
438438 if enabledSet ["fetch" ] {
439439 description .WriteString ("// Fetch API (available globally when enabled)\n " )
440440 description .WriteString ("const response = await fetch('https://api.example.com/data');\n " )
441441 description .WriteString ("const data = await response.json();\n " )
442442 description .WriteString ("console.log(data);\n \n " )
443443 }
444-
444+
445445 if enabledSet ["http" ] {
446446 description .WriteString ("// HTTP server (require import - NOT import statement)\n " )
447447 description .WriteString ("const serve = require('ski/http/server');\n " )
@@ -450,44 +450,44 @@ func buildToolDescription(enabledModules []string) string {
450450 description .WriteString ("});\n " )
451451 description .WriteString ("console.log('Server running at:', server.url);\n \n " )
452452 }
453-
453+
454454 if enabledSet ["cache" ] {
455455 description .WriteString ("// Cache operations (require import)\n " )
456456 description .WriteString ("const cache = require('ski/cache');\n " )
457457 description .WriteString ("cache.set('key', 'value');\n " )
458458 description .WriteString ("console.log(cache.get('key'));\n \n " )
459459 }
460-
460+
461461 if enabledSet ["crypto" ] {
462462 description .WriteString ("// Crypto operations (require import)\n " )
463463 description .WriteString ("const crypto = require('ski/crypto');\n " )
464464 description .WriteString ("const hash = crypto.md5('hello').hex();\n " )
465465 description .WriteString ("console.log('MD5 hash:', hash);\n \n " )
466466 }
467-
467+
468468 if enabledSet ["timers" ] {
469469 description .WriteString ("// Timers (available globally)\n " )
470470 description .WriteString ("setTimeout(() => {\n " )
471471 description .WriteString (" console.log('Hello after 1 second');\n " )
472472 description .WriteString ("}, 1000);\n \n " )
473473 }
474-
474+
475475 if enabledSet ["buffer" ] {
476476 description .WriteString ("// Buffer operations (available globally)\n " )
477477 description .WriteString ("const buffer = Buffer.from('hello', 'utf8');\n " )
478478 description .WriteString ("console.log(buffer.toString('base64'));\n \n " )
479479 }
480-
480+
481481 description .WriteString ("```\n " )
482482 description .WriteString ("\n Important notes:\n " )
483483 description .WriteString ("• Use require() for modules, NOT import statements\n " )
484484 description .WriteString ("• Modern JavaScript features supported (const/let, arrow functions, destructuring, etc.)\n " )
485-
485+
486486 // Add HTTP-specific note only if HTTP is enabled
487487 if enabledSet ["http" ] {
488488 description .WriteString ("• HTTP servers automatically run in background and don't block execution\n " )
489489 }
490-
490+
491491 description .WriteString ("• Async/await and Promises are fully supported\n " )
492492
493493 return description .String ()
0 commit comments