Add file upload support to /api/exec and run_js file-path reads#167
Open
r33drichards wants to merge 1 commit into
Open
Add file upload support to /api/exec and run_js file-path reads#167r33drichards wants to merge 1 commit into
r33drichards wants to merge 1 commit into
Conversation
The run_js MCP tool gains an optional `file` parameter that reads the script from a path on the server's own filesystem instead of inline `code`. It is off by default and unlocked by either `--allow-run-js-file` (allow any server-readable path) or a new `run_js_file` OPA/Rego policy category in `--policies-json` (authorize per path). Paths are canonicalized before policy evaluation, so `..` cannot escape an allowed directory. Supplying both `code` and `file` is an error. POST /api/exec now also accepts multipart/form-data: clients can upload the script as a `file` (or `code`) part, with the optional heap/session/ tags/limit fields as sibling parts. The JSON body still works. Unlike the tool's `file` parameter, uploads carry content from the client and need no server flag or policy. The mcp-v8-cli `exec` command gains `--file <PATH>` to read and submit a local script. Tests: unit tests for the policy-gated reader and the new policy config; stateless-shell tests for the tool `file` path (allow-all / disabled / conflict); an e2e test for multipart uploads (and a JSON regression). Docs: regenerated CLI-flags, MCP-tools, OpenAPI, and HTTP-API references; updated the js-execution and policies reference/how-to/concept pages, the embedded README and llms.txt, and the run_js tool descriptions. https://claude.ai/code/session_01DGrcRNsCvv6QvGxn71MmhR
🦀 mcp-v8-client Built SuccessfullyPackage: Add as dependency[dependencies]
mcp-v8-client = { git = "https://github.com/r33drichards/mcp-js", branch = "claude/peaceful-dirac-esj097" }CLI (from this branch)cargo install --git https://github.com/r33drichards/mcp-js --branch claude/peaceful-dirac-esj097 mcp-v8-client |
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 adds two complementary features for JavaScript execution:
Multipart file upload to
/api/exec: The REST endpoint now acceptsmultipart/form-datarequests, allowing clients to upload script files directly instead of embedding code in JSON strings.File-path execution for
run_js: Both the MCPrun_jstool and REST/api/execendpoint now support afileparameter to read and execute scripts from the server's own filesystem, with optional policy-based access control.Key Changes
New module
server/src/engine/run_js_file.rs: Implements policy-gated file reading for therun_jstool. Files are canonicalized before policy evaluation to prevent../escape attacks. Supports two modes:AllowAll: Allow reading any path the server process can access (--allow-run-js-file)Policy: Gate reads behind an OPA/Rego policy chain (run_js_filein--policies-json)Updated
/api/exechandler (server/src/api.rs):Content-Typeheadermultipart/form-datarequests withfileorcodepartsheap,session,heap_memory_max_mb,execution_timeout_secs,tagsExtended
EngineandRunJsRequest(server/src/engine/mod.rs):run_js_file_policyfield toEnginefile()andmaybe_file()builder methods toRunJsRequestrun_js_inner()to handle file-path reads with policy evaluationUpdated MCP
run_jstool (server/src/mcp.rs):codeparameter optional (defaults to empty string)fileparameterCLI enhancements (
server/src/cli.rs,mcp-v8-client/src/main.rs):--allow-run-js-fileflag for the server--file/-foption to the CLI client'sexeccommandComprehensive integration tests (
server/tests/exec_upload_e2e.rs):Documentation updates:
run_js_filepolicy input schemaImplementation Details
..resolved) before policy evaluation, preventing directory escape attacksMultipartextractor; unknown form parts are silently ignoredContent-Typerun_js_filepolicy categoryhttps://claude.ai/code/session_01DGrcRNsCvv6QvGxn71MmhR