feat: JavaScript Code Execution Tool with Full Observability#138
Merged
Conversation
Implement JavaScript code execution feature for orchestrating multiple upstream MCP tools in a single request. This reduces round-trip latency and enables complex multi-step workflows with conditional logic, loops, and data transformations. ## Core Features - Sandboxed JavaScript (ES5.1+) execution using Goja - call_tool() function for invoking upstream MCP servers - Execution limits (timeout, max_tool_calls, allowed_servers) - Concurrent execution pool with configurable size - Feature toggle (disabled by default for security) ## Observability - execution_id tracking for log correlation - Pool metrics (size, available, in-use) - Acquisition/release duration tracking - Tool call timing and result logging - Thread-safe metrics collection ## Security - Sandbox restrictions (no require, fs, network access) - Timeout enforcement with watchdog goroutine - Server whitelist support - Max tool calls limit to prevent abuse ## Developer Experience - CLI command: mcpproxy code exec - Comprehensive documentation (overview, examples, API reference, troubleshooting) - 19 unit tests with 100% pass rate ## Configuration - enable_code_execution: false (default) - code_execution_timeout_ms: 120000 (2 minutes) - code_execution_max_tool_calls: 0 (unlimited) - code_execution_pool_size: 10 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…ct methods Add missing code_execution operation constant and register it in all tool routing methods to enable CLI command support. - Add operationCodeExecution constant - Add case in CallBuiltInTool switch statement - Add case in CallToolDirect switch statement - Add to proxyTools map in handleCallTool - Add to proxy tool routing switch statement This fixes the 'unknown built-in tool: code_execution' error when using the mcpproxy code exec CLI command. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Add comprehensive session tracking for MCP tool calls with UI display: - Track MCP session ID, client name, and client version from InitializeRequest - Link nested tool calls (from code_execution) to their parent calls - Add 5 new optional fields to ToolCallRecord: parent_call_id, execution_type, mcp_session_id, mcp_client_name, mcp_client_version - Create thread-safe session store for capturing client metadata - Display session information in Tool Call History UI with Session column - Show full session details and JavaScript code in expanded row view - Support error status display with red badge and error messages - Include test data generator for populating sample records Backend changes: - internal/server/session_store.go: Thread-safe session metadata storage - internal/server/mcp.go: OnRegisterSession hook for capturing client info - internal/server/mcp_code_execution.go: Parent-child linking for nested calls - internal/runtime/runtime.go: API conversion includes new session fields - internal/storage/server_identity.go: Extended ToolCallRecord schema - internal/contracts/types.go: API response types with session fields Frontend changes: - frontend/src/types/api.ts: TypeScript types for session tracking - frontend/src/views/ToolCalls.vue: Session column, Monaco editor for code, parent call navigation Testing: - cmd/populate-test-data: Tool to generate test records with session data 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Changes: - Updated Validate() to apply defaults for code_execution fields before validation - Modified ValidateDetailed() to allow 0 values (treat as "use default") - Fixed test failures in TestValidateDetailed and TestValidateWithDefaults Fields affected: - CodeExecutionTimeoutMs: 0 or 1-600000 (default: 120000) - CodeExecutionPoolSize: 0 or 1-100 (default: 10) - CodeExecutionMaxToolCalls: >= 0 (0 means unlimited) This ensures configs without these fields can still validate successfully.
📦 Build Artifacts for PR #138Version: Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 19395037238 --repo smart-mcp-proxy/mcpproxy-go
# Or download a specific artifact:
gh run download 19395037238 --name dmg-darwin-arm64
|
This was referenced Nov 17, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements a production-ready JavaScript code execution feature that allows LLM agents to orchestrate multiple upstream MCP tools in a single request using sandboxed JavaScript (ES5.1+). This significantly reduces round-trip latency and enables complex multi-step workflows with conditional logic, loops, and data transformations.
Key Features
Core Functionality
call_tool()function for invoking upstream MCP servers from JavaScriptenable_code_execution: false)Observability (Completed in this PR)
Security
require(), filesystem, or network accessallowed_serversper requestDeveloper Experience
mcpproxy code execwith comprehensive flagsConfiguration
{ "enable_code_execution": false, "code_execution_timeout_ms": 120000, "code_execution_max_tool_calls": 0, "code_execution_pool_size": 10 }Example Usage
JavaScript Example:
Test Plan
Implementation Status
Completion: 100% (Production-Ready)
See IMPLEMENTATION_STATUS.md for detailed breakdown.
Files Changed
New Files
internal/jsruntime/- JavaScript runtime package (errors, pool, runtime)internal/server/mcp_code_execution.go- MCP tool handler with observabilitycmd/mcpproxy/code_cmd.go- CLI command implementationdocs/code_execution/- Complete documentation suitespecs/001-code-execution/- Feature specification and trackingModified Files
internal/config/config.go- Configuration supportinternal/server/mcp.go- Tool registrationinternal/server/server.go- Pool lifecycle integrationCLAUDE.md- Development documentationSuccess Metrics
All critical success criteria met:
🤖 Generated with Claude Code