Skip to content

Commit 66d082b

Browse files
committed
increase timeout
1 parent 293f922 commit 66d082b

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ codebench-mcp --enabled-modules http,fetch
4242
# Disable specific modules (enable all others)
4343
codebench-mcp --disabled-modules timers
4444

45+
# Set custom execution timeout (in seconds)
46+
codebench-mcp --execution-timeout 600 # 10 minutes
47+
4548
# Show help
4649
codebench-mcp --help
4750
```
@@ -212,6 +215,10 @@ Execute JavaScript code with a modern runtime environment.
212215
**Parameters:**
213216
- `code` (required): JavaScript code to execute
214217

218+
**Configuration:**
219+
- Default execution timeout: 5 minutes
220+
- Configurable via `--execution-timeout <seconds>` CLI flag
221+
215222
**Example:**
216223
```javascript
217224
console.log("Hello, World!");
@@ -259,6 +266,7 @@ console.log('Pathname:', url.pathname);
259266
- **Module access varies** - Some modules are global (fetch, http), others may need require()
260267
- **Each execution creates a fresh VM** - For isolation, each execution starts with a clean state
261268
- **Module filtering** - Configuration exists but actual runtime filtering not fully implemented
269+
- **Execution timeout** - JavaScript execution is limited by configurable timeout (default: 5 minutes)
262270

263271
## Building
264272

cmd/root.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"slices"
77
"strings"
8+
"time"
89

910
"github.com/mark3labs/codebench-mcp/internal/logger"
1011
"github.com/mark3labs/codebench-mcp/server"
@@ -16,6 +17,7 @@ var (
1617
enabledModules []string
1718
disabledModules []string
1819
debugMode bool
20+
executionTimeout int
1921
)
2022

2123
// Available modules
@@ -86,6 +88,7 @@ with a modern runtime including http, fetch, timers, buffer, crypto, and other m
8688
// Create server with module configuration
8789
config := server.ModuleConfig{
8890
EnabledModules: modulesToEnable,
91+
ExecutionTimeout: time.Duration(executionTimeout) * time.Second,
8992
}
9093

9194
jss, err := server.NewJSServerWithConfig(config)
@@ -119,6 +122,8 @@ func init() {
119122
strings.Join(availableModules, ", ")))
120123
rootCmd.Flags().BoolVar(&debugMode, "debug", false,
121124
"Enable debug logging (outputs to stderr)")
125+
rootCmd.Flags().IntVar(&executionTimeout, "execution-timeout", 300,
126+
"JavaScript execution timeout in seconds (default: 300 = 5 minutes)")
122127

123128
rootCmd.MarkFlagsMutuallyExclusive("enabled-modules", "disabled-modules")
124129
}

server/server.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ import (
2929
var Version = "dev"
3030

3131
type ModuleConfig struct {
32-
EnabledModules []string
33-
DisabledModules []string
32+
EnabledModules []string
33+
DisabledModules []string
34+
ExecutionTimeout time.Duration
3435
}
3536

3637
type JSHandler struct {
@@ -42,7 +43,8 @@ type JSHandler struct {
4243

4344
func NewJSHandler() *JSHandler {
4445
return NewJSHandlerWithConfig(ModuleConfig{
45-
EnabledModules: []string{"http", "fetch", "timers", "buffer", "kv", "crypto", "encoding", "url", "cache"},
46+
EnabledModules: []string{"http", "fetch", "timers", "buffer", "kv", "crypto", "encoding", "url", "cache"},
47+
ExecutionTimeout: 5 * time.Minute,
4648
})
4749
}
4850

@@ -213,8 +215,12 @@ func (h *JSHandler) handleRegularCode(ctx context.Context, code string) (*mcp.Ca
213215
consoleModule := console.NewConsoleModule(&output)
214216
consoleModule.Setup(vm.Runtime())
215217

216-
// Execute the JavaScript code with a timeout for regular code
217-
execCtx, cancel := context.WithTimeout(ctx, time.Second*10)
218+
// Execute the JavaScript code with configurable timeout
219+
timeout := h.config.ExecutionTimeout
220+
if timeout == 0 {
221+
timeout = 5 * time.Minute // Default fallback
222+
}
223+
execCtx, cancel := context.WithTimeout(ctx, timeout)
218224
defer cancel()
219225

220226
// Execute in a goroutine to respect timeout

0 commit comments

Comments
 (0)