Skip to content

Turns tempdir LLM argument into a configvar #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
"STDIO_MODE_ONLY": {
"description": "Only allow tool requests via STDIO mode?",
"value": "false"
},
"USE_TEMP_DIR": {
"description": "Use a temporary working directory for npm installs and code execution. Not a secure sandbox.",
"value": "false"
}
},
"formation": [
Expand Down
9 changes: 8 additions & 1 deletion example_clients/test_sse.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +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_node",
"arguments": {
"code": "console.log(Array.from({length: 50}, () => Math.random()));",
"packages": []
}
}' | jq
"""
result = asyncio.run(run(method_name, args))
print(json.dumps(result.model_dump(), indent=2))
Expand Down
8 changes: 3 additions & 5 deletions src/code_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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], cwd: Optional[str] = None) -> Dict[str, Any]:
"""Executes a command using subprocess and returns output and errors."""
Expand Down Expand Up @@ -91,10 +93,6 @@ def code_exec_node(
Optional[List[str]],
Field(description="Optional list of npm package names to install before execution.")
] = None,
use_temp_dir: Annotated[
bool,
Field(description="Use a temporary working directory for code execution and npm installs.")
] = False
) -> Dict[str, Any]:
"""Executes a Node.js code snippet with optional npm dependencies.

Expand All @@ -108,7 +106,7 @@ def code_exec_node(
- '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)

install_result = install_dependencies(packages, install_cmd_path="npm")
Expand Down
1 change: 1 addition & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down