Skip to content

Commit f8df5e4

Browse files
author
sourcehold
committed
tools: truncate output for mcp purposes (token reduction)
1 parent fcd8066 commit f8df5e4

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

tools/mcp/decomphelper.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
# Initialize MCP server
4949
mcp = FastMCP("decomp-helper")
5050

51-
def compile_project() -> tuple[bool, str, str]:
51+
def compile_project(truncated: bool = True, no_output_on_succes: bool = True) -> tuple[bool, str, str]:
5252
"""
5353
Compile the C++ project using MSVC. Must be executed after writing new cpp file contents.
5454
@@ -66,7 +66,20 @@ def compile_project() -> tuple[bool, str, str]:
6666
cwd=".",
6767
stdin=subprocess.DEVNULL,
6868
)
69-
return result.returncode == 0, result.stdout, result.stderr
69+
code = result.returncode
70+
stdout = result.stdout
71+
stderr = result.stderr
72+
if stderr and code == 0:
73+
code = -1
74+
if truncated:
75+
needle1 = "-- Build files have been written to:"
76+
if needle1 in stdout:
77+
start = stdout.index(needle1)
78+
eol_index = stdout.index("\n", start) + 1
79+
stdout = stdout[eol_index:]
80+
if no_output_on_succes and code == 0:
81+
return True, "", ""
82+
return False, stdout, stderr
7083
except Exception as e:
7184
return False, "", str(e)
7285

0 commit comments

Comments
 (0)