diff --git a/app.json b/app.json index 8e567fd..f07e071 100644 --- a/app.json +++ b/app.json @@ -15,6 +15,10 @@ "STDIO_MODE_ONLY": { "description": "Only allow tool requests via STDIO mode?", "value": "false" + }, + "USE_TEMP_DIR": { + "description": "If True, gems are installed in an isolated temporary directory and will not affect or reuse the user's ~/.gem folder. Not a secure sandbox.", + "value": "false" } }, "formation": [ diff --git a/example_clients/test_sse.py b/example_clients/test_sse.py index 0b531d8..6149707 100644 --- a/example_clients/test_sse.py +++ b/example_clients/test_sse.py @@ -32,8 +32,14 @@ def mcp(method_name, args=None): Examples: python example_clients/test_sse.py mcp list_tools - python example_clients/test_sse.py mcp call_tool --args '{"name": "fetch_webpage_and_markdownify", "arguments": {"url": "https://example.com"}}' - """ + + python example_clients/test_sse.py mcp call_tool --args '{ + "name": "code_exec_ruby", + "arguments": { + "code": "puts Array.new(100) { rand(1..100) }.join(\", \")", + "packages": [""] + } + }' | jq """ result = asyncio.run(run(method_name, args)) print(json.dumps(result.model_dump(), indent=2)) diff --git a/src/code_execution.py b/src/code_execution.py index 2d0a75b..1bb59b0 100644 --- a/src/code_execution.py +++ b/src/code_execution.py @@ -4,6 +4,8 @@ import tempfile from typing import Annotated, Optional, List, Dict, Any from pydantic import Field +# local: +from src import config def run_command(cmd: List[str], env: Optional[Dict[str, str]] = None) -> Dict[str, Any]: """Executes a command using subprocess and returns output and errors.""" @@ -108,15 +110,7 @@ def code_exec_ruby( packages: Annotated[ Optional[List[str]], Field(description="Optional list of gem names to install before execution.") - ] = None, - use_temp_dir: Annotated[ - bool, - Field(description=( - "If True, code and dependencies are run in a temporary working directory. " - "Gems are installed in an isolated directory and will not affect or reuse the user's ~/.gem folder. " - "Not a secure sandbox." - )) - ] = False + ] = None ) -> Dict[str, Any]: """Executes a Ruby code snippet with optional gem dependencies. @@ -132,7 +126,7 @@ def code_exec_ruby( - 'stdout': Captured standard output. - 'stderr': Captured standard error or install failure messages. """ - if use_temp_dir: + if config.USE_TEMP_DIR: return run_in_tempdir(code, packages) # Otherwise, you can rely on pre-installed shared packages, if they exist: diff --git a/src/config.py b/src/config.py index 01b1341..31cbcec 100644 --- a/src/config.py +++ b/src/config.py @@ -17,6 +17,7 @@ def get_env_variable(var_name, required=True): PORT = int(os.environ.get('PORT', 8000)) WEB_CONCURRENCY = int(os.environ.get('WEB_CONCURRENCY', 1)) STDIO_MODE_ONLY = os.getenv("STDIO_MODE_ONLY", "false").lower() == "true" +USE_TEMP_DIR = os.getenv("USE_TEMP_DIR", "false").lower() == "true" # Local or Not: is_one_off_dyno = os.getenv("DYNO") is not None