Files
Gitea-Tools/mcp_server.py
sysadminandClaude Opus 4.8 7a28d09b5d fix(mcp): line-anchor conflict scan and worktree scan paths (#272)
Match git conflict markers on whole lines only so decorative equals
borders in mcp_discoverability.py no longer false-positive. Scan
session worktrees under branches/ without skipping the entire tree
when the worktree path contains "branches".

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
2026-07-06 14:09:44 -04:00

59 lines
2.3 KiB
Python

#!/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
from role_session_router import (
python_bytes_have_conflict_markers,
skip_python_scan_walk_root,
)
# 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__))
for root, dirs, files in os.walk(dir_path):
if skip_python_scan_walk_root(dir_path, root):
continue
for file in files:
if file.endswith(".py"):
file_path = os.path.join(root, file)
try:
with open(file_path, "rb") as f:
if python_bytes_have_conflict_markers(f.read()):
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