Allow run_script to run on a remote runner#182
Merged
Conversation
Isolate script execution (memory/CPU/OOM) from the main MCP server by letting it
forward run_script to a separate runner over one stateless HTTP POST:
- When PRODUCTIVE_MCP_RUN_RUNNER_URL is set, handleRunScript forwards
{ code, args, flags, dry_run, credentials } and relays the runner's ToolResult;
the runner URL also enables run_script without the local ENABLE_RUN flag.
Otherwise it runs locally as before (graceful fallback).
- Add a token-gated /run endpoint on the HTTP transport (active only when
PRODUCTIVE_MCP_RUN_RUNNER_TOKEN is set), which runs the script through the
normal pipeline and returns the ToolResult.
- Contract is infrastructure-agnostic and load-balancer-ready: stateless,
token-authenticated, must not be proxy-retried (non-dry-run scripts mutate).
- Unit tests for remote forwarding, the /run core, and the handler branch;
SKILL.md + CHANGELOG updated.
Co-authored-by: Claude <claude@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #182 +/- ##
==========================================
+ Coverage 97.25% 97.27% +0.02%
==========================================
Files 264 266 +2
Lines 8802 8867 +65
Branches 2783 2806 +23
==========================================
+ Hits 8560 8625 +65
Misses 236 236
Partials 6 6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
Lets the MCP server delegate
run_scriptexecution to a separate runner so a script's memory/CPU (and any OOM) is isolated from the main server — important on small VMs (the hosted HTTP MCP runs on 256 MB, where a heavy in-process run could OOM-kill the whole server). Infrastructure-agnostic and load-balancer-ready.How it works
PRODUCTIVE_MCP_RUN_RUNNER_URLset):handleRunScriptforwards a stateless{ code, args, flags, dry_run, credentials }POST to the runner and relays itsToolResult. The runner URL also enablesrun_scriptwithout the localPRODUCTIVE_MCP_ENABLE_RUNflag (the front can stay tiny + gated).PRODUCTIVE_MCP_RUN_RUNNER_TOKENset,PRODUCTIVE_MCP_ENABLE_RUN=true): a token-gatedPOST /runruns the script through the normal pipeline (its own limits + sandbox) and returns theToolResult.Infra-agnostic / LB-ready
The
/runcontract is a single stateless HTTP POST, so any backend works (Fly machine pool, k8s, serverless, …) and you can put a load balancer in front of a runner pool. It is:PRODUCTIVE_MCP_RUN_RUNNER_TOKEN(constant-time compare), so the hop is safe even on a shared private network;dry_runscript can mutate, so retries must be disabled at the LB/proxy.Config
Front:
PRODUCTIVE_MCP_RUN_RUNNER_URL,PRODUCTIVE_MCP_RUN_RUNNER_TOKEN, optionalPRODUCTIVE_MCP_RUN_RUNNER_TIMEOUT_MS(30000).Runner:
PRODUCTIVE_MCP_RUN_RUNNER_TOKEN(activates/run),PRODUCTIVE_MCP_ENABLE_RUN=true, plus the existingPRODUCTIVE_MCP_RUN_*limits.Testing
remote.ts(config parsing, token compare, forwarding success/non-2xx/timeout/transport-error, header/body),/runcore (run-endpoint.ts— token gating 404/401, body/credential validation, happy path), and thehandleRunScriptremote branch (forwards, doesn't run locally, still validates code).npm run checkclean; build OK. The thin H3 wiring inhttp.tsis covered by theexecuteRunRequestcore tests.Depends on a release before the runner deployment can pin it.
🤖 Generated with Claude Code