Skip to content

Commit 0d59edf

Browse files
Merge pull request #10 from heroku/remove_use_temp_dir_llm_arg
Turns tempdir LLM argument into a configvar
2 parents 759ee31 + 6d4adbe commit 0d59edf

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

app.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
"STDIO_MODE_ONLY": {
1616
"description": "Only allow tool requests via STDIO mode?",
1717
"value": "false"
18+
},
19+
"USE_TEMP_DIR": {
20+
"description": "Use a temporary working directory for npm installs and code execution. Not a secure sandbox.",
21+
"value": "false"
1822
}
1923
},
2024
"formation": [

example_clients/test_sse.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,14 @@ def mcp(method_name, args=None):
3232
3333
Examples:
3434
python example_clients/test_sse.py mcp list_tools
35-
python example_clients/test_sse.py mcp call_tool --args '{"name": "fetch_webpage_and_markdownify", "arguments": {"url": "https://example.com"}}'
35+
36+
python example_clients/test_sse.py mcp call_tool --args '{
37+
"name": "code_exec_node",
38+
"arguments": {
39+
"code": "console.log(Array.from({length: 50}, () => Math.random()));",
40+
"packages": []
41+
}
42+
}' | jq
3643
"""
3744
result = asyncio.run(run(method_name, args))
3845
print(json.dumps(result.model_dump(), indent=2))

src/code_execution.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import tempfile
55
from typing import Annotated, Optional, List, Dict, Any
66
from pydantic import Field
7+
# local:
8+
from src import config
79

810
def run_command(cmd: List[str], cwd: Optional[str] = None) -> Dict[str, Any]:
911
"""Executes a command using subprocess and returns output and errors."""
@@ -91,10 +93,6 @@ def code_exec_node(
9193
Optional[List[str]],
9294
Field(description="Optional list of npm package names to install before execution.")
9395
] = None,
94-
use_temp_dir: Annotated[
95-
bool,
96-
Field(description="Use a temporary working directory for code execution and npm installs.")
97-
] = False
9896
) -> Dict[str, Any]:
9997
"""Executes a Node.js code snippet with optional npm dependencies.
10098
@@ -108,7 +106,7 @@ def code_exec_node(
108106
- 'stdout': Captured standard output.
109107
- 'stderr': Captured standard error or install failure messages.
110108
"""
111-
if use_temp_dir:
109+
if config.USE_TEMP_DIR:
112110
return run_in_tempdir(code, packages)
113111

114112
install_result = install_dependencies(packages, install_cmd_path="npm")

src/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def get_env_variable(var_name, required=True):
1717
PORT = int(os.environ.get('PORT', 8000))
1818
WEB_CONCURRENCY = int(os.environ.get('WEB_CONCURRENCY', 1))
1919
STDIO_MODE_ONLY = os.getenv("STDIO_MODE_ONLY", "false").lower() == "true"
20+
USE_TEMP_DIR = os.getenv("USE_TEMP_DIR", "false").lower() == "true"
2021

2122
# Local or Not:
2223
is_one_off_dyno = os.getenv("DYNO") is not None

0 commit comments

Comments
 (0)