feat(runtime-isolation): loader, health checks, tests, and documentation for Issue #221

This commit is contained in:
2026-07-05 21:13:40 -04:00
parent cb974d659f
commit 2cd61a90fe
3 changed files with 129 additions and 0 deletions
+60
View File
@@ -0,0 +1,60 @@
#!/usr/bin/env python3
"""Gitea MCP Server — exposes Gitea operations as MCP tools.
Runs over stdio. All tools authenticate via macOS keychain (git credential fill).
"""
import os
import sys
# Startup health check: scan all python files in the Gitea-Tools directory for unresolved conflict markers.
def check_conflict_markers():
dir_path = os.path.dirname(os.path.abspath(__file__))
# Construct conflict patterns dynamically so the loader does not match itself
conflict_patterns = [
b"<" * 7 + b" ",
b"=" * 7 + b"\n",
b"=" * 7 + b"\r\n",
b">" * 7 + b" "
]
for root, dirs, files in os.walk(dir_path):
if any(p in root for p in ("venv", ".git", ".pytest_cache", "branches")):
continue
for file in files:
if file.endswith(".py"):
file_path = os.path.join(root, file)
try:
with open(file_path, "rb") as f:
content = f.read()
if any(pattern in content for pattern in conflict_patterns):
rel_path = os.path.relpath(file_path, dir_path)
print(
f"infra_stop: Unresolved merge conflict detected in {rel_path}. "
"Please resolve all conflicts manually, finish/abort the merge, "
"restart the MCP server, and retry.",
file=sys.stderr
)
sys.exit(1)
except Exception:
pass
check_conflict_markers()
# Execute the actual server logic via exec in this namespace.
impl_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "gitea_mcp_server.py")
try:
with open(impl_path, "rb") as f:
# Override __file__ global so that inspect.getsource(mcp_server) returns the implementation source
globals()["__file__"] = impl_path
code = compile(f.read(), impl_path, "exec")
exec(code, globals())
except Exception as e:
if isinstance(e, SyntaxError):
# Fallback if a syntax error/conflict marker was introduced in gitea_mcp_server.py
print(
f"infra_stop: Unresolved merge conflict or syntax error in gitea_mcp_server.py. "
"Please resolve all conflicts manually, finish/abort the merge, "
"restart the MCP server, and retry.",
file=sys.stderr
)
sys.exit(1)
raise e