From a854282cafe437f1aa7581e513959b05f277289e Mon Sep 17 00:00:00 2001 From: Rafael Uzarowski Date: Wed, 26 Nov 2025 17:23:46 +0100 Subject: [PATCH 1/4] Fix packaging, set TERM type correctly --- .../code_execution_tool.py | 9 ++++---- .../helpers}/__init__.py | 0 .../helpers}/log.py | 0 .../helpers}/print_style.py | 0 .../helpers}/shell_local.py | 21 ++++++++++++++----- .../helpers}/shell_utils.py | 0 .../helpers}/strings.py | 0 .../helpers}/tty_session.py | 0 main.py => code_execution_mcp/main.py | 2 +- .../prompts}/fw.code.info.md | 0 .../prompts}/fw.code.max_time.md | 0 .../prompts}/fw.code.no_out_time.md | 0 .../prompts}/fw.code.no_output.md | 0 .../prompts}/fw.code.pause_dialog.md | 0 .../prompts}/fw.code.pause_time.md | 0 .../prompts}/fw.code.reset.md | 0 prompts/__init__.py | 0 pyproject.toml | 8 +++++-- 18 files changed, 27 insertions(+), 13 deletions(-) rename code_execution_tool.py => code_execution_mcp/code_execution_tool.py (98%) rename {helpers => code_execution_mcp/helpers}/__init__.py (100%) rename {helpers => code_execution_mcp/helpers}/log.py (100%) rename {helpers => code_execution_mcp/helpers}/print_style.py (100%) rename {helpers => code_execution_mcp/helpers}/shell_local.py (76%) rename {helpers => code_execution_mcp/helpers}/shell_utils.py (100%) rename {helpers => code_execution_mcp/helpers}/strings.py (100%) rename {helpers => code_execution_mcp/helpers}/tty_session.py (100%) rename main.py => code_execution_mcp/main.py (97%) rename {prompts => code_execution_mcp/prompts}/fw.code.info.md (100%) rename {prompts => code_execution_mcp/prompts}/fw.code.max_time.md (100%) rename {prompts => code_execution_mcp/prompts}/fw.code.no_out_time.md (100%) rename {prompts => code_execution_mcp/prompts}/fw.code.no_output.md (100%) rename {prompts => code_execution_mcp/prompts}/fw.code.pause_dialog.md (100%) rename {prompts => code_execution_mcp/prompts}/fw.code.pause_time.md (100%) rename {prompts => code_execution_mcp/prompts}/fw.code.reset.md (100%) delete mode 100644 prompts/__init__.py diff --git a/code_execution_tool.py b/code_execution_mcp/code_execution_tool.py similarity index 98% rename from code_execution_tool.py rename to code_execution_mcp/code_execution_tool.py index b62402c..35dddef 100644 --- a/code_execution_tool.py +++ b/code_execution_mcp/code_execution_tool.py @@ -5,11 +5,10 @@ import re import os import sys -from helpers.print_style import PrintStyle -from helpers.shell_local import LocalInteractiveSession -from helpers.strings import truncate_text as truncate_text_string -from helpers.log import Log - +from .helpers.print_style import PrintStyle +from .helpers.shell_local import LocalInteractiveSession +from .helpers.strings import truncate_text as truncate_text_string +from .helpers.log import Log def truncate_text_agent(output: str, threshold: int = 1000000) -> str: if len(output) <= threshold: diff --git a/helpers/__init__.py b/code_execution_mcp/helpers/__init__.py similarity index 100% rename from helpers/__init__.py rename to code_execution_mcp/helpers/__init__.py diff --git a/helpers/log.py b/code_execution_mcp/helpers/log.py similarity index 100% rename from helpers/log.py rename to code_execution_mcp/helpers/log.py diff --git a/helpers/print_style.py b/code_execution_mcp/helpers/print_style.py similarity index 100% rename from helpers/print_style.py rename to code_execution_mcp/helpers/print_style.py diff --git a/helpers/shell_local.py b/code_execution_mcp/helpers/shell_local.py similarity index 76% rename from helpers/shell_local.py rename to code_execution_mcp/helpers/shell_local.py index 0250466..2678a5c 100644 --- a/helpers/shell_local.py +++ b/code_execution_mcp/helpers/shell_local.py @@ -7,14 +7,25 @@ from . import tty_session from .shell_utils import clean_string + class LocalInteractiveSession: - def __init__(self, executable: str | None = None): + def __init__( + self, + executable: str | None = None, + term_type: str = "dumb", + ): self.executable = executable - self.session: tty_session.TTYSession|None = None + self.term_type = term_type + self.session: tty_session.TTYSession | None = None self.full_output = '' async def connect(self): - self.session = tty_session.TTYSession(self.executable, env=os.environ.copy()) + env = os.environ.copy() + env["TERM"] = self.term_type + self.session = tty_session.TTYSession( + self.executable, + env=env, + ) await self.session.start() await self.session.read_full_until_idle(idle_timeout=1, total_timeout=1) @@ -28,7 +39,7 @@ async def send_command(self, command: str): raise Exception("Shell not connected") self.full_output = "" await self.session.sendline(command) - + async def read_output(self, timeout: float = 0, reset_full_output: bool = False) -> Tuple[str, Optional[str]]: if not self.session: raise Exception("Shell not connected") @@ -46,4 +57,4 @@ async def read_output(self, timeout: float = 0, reset_full_output: bool = False) if not partial_output: return clean_full_output, None - return clean_full_output, partial_output \ No newline at end of file + return clean_full_output, partial_output diff --git a/helpers/shell_utils.py b/code_execution_mcp/helpers/shell_utils.py similarity index 100% rename from helpers/shell_utils.py rename to code_execution_mcp/helpers/shell_utils.py diff --git a/helpers/strings.py b/code_execution_mcp/helpers/strings.py similarity index 100% rename from helpers/strings.py rename to code_execution_mcp/helpers/strings.py diff --git a/helpers/tty_session.py b/code_execution_mcp/helpers/tty_session.py similarity index 100% rename from helpers/tty_session.py rename to code_execution_mcp/helpers/tty_session.py diff --git a/main.py b/code_execution_mcp/main.py similarity index 97% rename from main.py rename to code_execution_mcp/main.py index b83ed50..7556c99 100644 --- a/main.py +++ b/code_execution_mcp/main.py @@ -2,7 +2,7 @@ import os import sys from fastmcp import FastMCP -from code_execution_tool import CodeExecutionTool +from code_execution_mcp.code_execution_tool import CodeExecutionTool # Helpers for debugging version = f"v0.1.3, Python {sys.version.split(' ')[0]}, executable={sys.executable}" diff --git a/prompts/fw.code.info.md b/code_execution_mcp/prompts/fw.code.info.md similarity index 100% rename from prompts/fw.code.info.md rename to code_execution_mcp/prompts/fw.code.info.md diff --git a/prompts/fw.code.max_time.md b/code_execution_mcp/prompts/fw.code.max_time.md similarity index 100% rename from prompts/fw.code.max_time.md rename to code_execution_mcp/prompts/fw.code.max_time.md diff --git a/prompts/fw.code.no_out_time.md b/code_execution_mcp/prompts/fw.code.no_out_time.md similarity index 100% rename from prompts/fw.code.no_out_time.md rename to code_execution_mcp/prompts/fw.code.no_out_time.md diff --git a/prompts/fw.code.no_output.md b/code_execution_mcp/prompts/fw.code.no_output.md similarity index 100% rename from prompts/fw.code.no_output.md rename to code_execution_mcp/prompts/fw.code.no_output.md diff --git a/prompts/fw.code.pause_dialog.md b/code_execution_mcp/prompts/fw.code.pause_dialog.md similarity index 100% rename from prompts/fw.code.pause_dialog.md rename to code_execution_mcp/prompts/fw.code.pause_dialog.md diff --git a/prompts/fw.code.pause_time.md b/code_execution_mcp/prompts/fw.code.pause_time.md similarity index 100% rename from prompts/fw.code.pause_time.md rename to code_execution_mcp/prompts/fw.code.pause_time.md diff --git a/prompts/fw.code.reset.md b/code_execution_mcp/prompts/fw.code.reset.md similarity index 100% rename from prompts/fw.code.reset.md rename to code_execution_mcp/prompts/fw.code.reset.md diff --git a/prompts/__init__.py b/prompts/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/pyproject.toml b/pyproject.toml index a937c36..9e07adb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,10 +13,14 @@ dependencies = [ ] [project.scripts] -code-execution-mcp = "main:main" +code-execution-mcp = "code_execution_mcp.main:main" [tool.setuptools] -py-modules = ["main", "code_execution_tool"] +py-modules = ["code_execution_mcp.main", "code_execution_mcp.code_execution_tool"] +include-package-data = true + +[tool.setuptools.package-data] +"code_execution_mcp" = ["prompts/*.md"] [build-system] requires = ["setuptools>=61.0"] From 56e707dbc5d74b203843bdd5fa4f8efc3e726828 Mon Sep 17 00:00:00 2001 From: frdel <38891707+frdel@users.noreply.github.com> Date: Wed, 26 Nov 2025 18:47:45 +0100 Subject: [PATCH 2/4] Create __init__.py --- code_execution_mcp/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 code_execution_mcp/__init__.py diff --git a/code_execution_mcp/__init__.py b/code_execution_mcp/__init__.py new file mode 100644 index 0000000..e69de29 From 8a4ce92069aeba757e822664082d74979589d6f6 Mon Sep 17 00:00:00 2001 From: frdel <38891707+frdel@users.noreply.github.com> Date: Wed, 26 Nov 2025 18:55:52 +0100 Subject: [PATCH 3/4] Update main.py --- code_execution_mcp/main.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/code_execution_mcp/main.py b/code_execution_mcp/main.py index 7556c99..d8e77eb 100644 --- a/code_execution_mcp/main.py +++ b/code_execution_mcp/main.py @@ -2,7 +2,18 @@ import os import sys from fastmcp import FastMCP -from code_execution_mcp.code_execution_tool import CodeExecutionTool + +try: + # Prefer package-style import when running as an installed package or with -m + from code_execution_mcp.code_execution_tool import CodeExecutionTool +except ImportError: + # Fallback for running this file directly, e.g. `python /path/to/code_execution_mcp/main.py` + # Ensure the project root (parent of this directory) is on sys.path so that + # `code_execution_mcp` can be imported as a proper package and relative imports work. + package_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + if package_root not in sys.path: + sys.path.insert(0, package_root) + from code_execution_mcp.code_execution_tool import CodeExecutionTool # Helpers for debugging version = f"v0.1.3, Python {sys.version.split(' ')[0]}, executable={sys.executable}" From 7bac5a42c9cd4e27a6b8d5d500863767c61a4239 Mon Sep 17 00:00:00 2001 From: frdel <38891707+frdel@users.noreply.github.com> Date: Wed, 26 Nov 2025 18:56:41 +0100 Subject: [PATCH 4/4] Delete __init__.py --- code_execution_mcp/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 code_execution_mcp/__init__.py diff --git a/code_execution_mcp/__init__.py b/code_execution_mcp/__init__.py deleted file mode 100644 index e69de29..0000000