Skip to content

feat: add TypeScript support to code_execution#331

Merged
Dumbris merged 2 commits intomainfrom
033-typescript-code-execution
Mar 10, 2026
Merged

feat: add TypeScript support to code_execution#331
Dumbris merged 2 commits intomainfrom
033-typescript-code-execution

Conversation

@Dumbris
Copy link
Contributor

@Dumbris Dumbris commented Mar 10, 2026

Summary

  • Add TypeScript transpilation to the code_execution tool using esbuild's Go API
  • Users can now write TypeScript code that gets transparently transpiled to JS before execution in goja
  • New language parameter added to MCP tool, REST API, and CLI (javascript | typescript, default: javascript)
  • ~1ms transpilation overhead, zero external runtime dependencies

Changes

  • internal/jsruntime/typescript.go: esbuild-based transpilation layer (TranspileTypeScript, ValidateLanguage)
  • internal/jsruntime/runtime.go: Added Language field to ExecutionOptions, auto-transpile in Execute()
  • internal/jsruntime/errors.go: New TRANSPILE_ERROR and INVALID_LANGUAGE error codes
  • internal/server/mcp.go: Added language parameter to MCP tool schema
  • internal/server/mcp_code_execution.go: Language parsing and pass-through
  • internal/httpapi/code_exec.go: Language field in REST API request
  • cmd/mcpproxy/code_cmd.go: --language CLI flag
  • docs/code_execution/: Updated overview and API reference

Usage

# MCP tool
{"language": "typescript", "code": "const x: number = 42; ({result: x})"}

# REST API
curl -X POST /api/v1/code/exec -d '{"language": "typescript", "code": "..."}'

# CLI
mcpproxy code exec --language typescript --code "const x: number = 42; ({result: x})"

Test plan

  • 38 jsruntime tests pass with -race (10 new transpilation + 7 integration)
  • All server tests pass including 5 CodeExecution tests
  • All httpapi tests pass including 6 CodeExec tests (3 new)
  • Both editions compile
  • Pre-commit hooks pass
  • Backward compatible — default language: "javascript" preserves existing behavior

🤖 Generated with Claude Code

Enable LLM agents to write code execution scripts in TypeScript with
type annotations, interfaces, enums, generics, and namespaces. Types
are automatically stripped via esbuild before execution in the goja
sandbox with near-zero transpilation overhead (<5ms).

Changes across all three surfaces (MCP tool, REST API, CLI):
- New `language` parameter on code_execution tool (enum: javascript, typescript)
- esbuild-based transpilation layer in internal/jsruntime/typescript.go
- TRANSPILE_ERROR and INVALID_LANGUAGE error codes for clear diagnostics
- Backward compatible: omitting language defaults to JavaScript
- 38 jsruntime tests, 6 httpapi tests, 5 server tests all passing

Spec: specs/033-typescript-code-execution/

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 10, 2026

Deploying mcpproxy-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 587ab4a
Status:⚡️  Build in progress...

View logs

@github-actions
Copy link

📦 Build Artifacts

Workflow Run: View Run
Branch: 033-typescript-code-execution

Available Artifacts

  • archive-darwin-amd64 (25 MB)
  • archive-darwin-arm64 (23 MB)
  • archive-linux-amd64 (14 MB)
  • archive-linux-arm64 (13 MB)
  • archive-windows-amd64 (25 MB)
  • archive-windows-arm64 (22 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (28 MB)
  • installer-dmg-darwin-arm64 (25 MB)

How to Download

Option 1: GitHub Web UI (easiest)

  1. Go to the workflow run page linked above
  2. Scroll to the bottom "Artifacts" section
  3. Click on the artifact you want to download

Option 2: GitHub CLI

gh run download 22898648966 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

Resolve merge conflicts between TypeScript code execution feature and
main branch changes (routing modes PR#327, tool quarantine PR#328,
goja update PR#330).

Conflicts resolved by keeping both sides:
- internal/jsruntime/runtime.go: Added Language field alongside auth
  context fields from Spec 031
- internal/server/mcp.go: Combined TypeScript+ES2020+ tool descriptions
  and kept language parameter alongside updated code description
- internal/server/mcp_code_execution.go: Kept language logging alongside
  auth context injection from Spec 031
- docs/code_execution/api-reference.md: Merged TypeScript language
  parameter docs with ES2020+ description updates

Also fixed binary E2E test config to disable tool-level quarantine
(quarantine_enabled: false), matching the approach in non-binary E2E
tests. Without this, the new tool quarantine feature from Spec 032
causes tools to be quarantined during tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Dumbris Dumbris merged commit b4df1de into main Mar 10, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants