fix(mcp): resolve default remote mapping and connection check bugs
This commit is contained in:
+21
-2
@@ -1367,8 +1367,26 @@ def cleanup_in_progress_for_pr(pr_payload: dict, remote: str, host: str | None,
|
|||||||
|
|
||||||
# ── Helpers ───────────────────────────────────────────────────────────────────
|
# ── Helpers ───────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
def _effective_remote(remote: str) -> str:
|
||||||
|
"""If remote is the default ('dadeschools') but the active profile base_url maps to a known remote, use that remote instead."""
|
||||||
|
try:
|
||||||
|
profile = get_profile()
|
||||||
|
base_url = profile.get("base_url")
|
||||||
|
if remote == "dadeschools" and base_url:
|
||||||
|
import urllib.parse
|
||||||
|
url = urllib.parse.urlparse(base_url)
|
||||||
|
host = (url.netloc or url.path or "").strip().lower()
|
||||||
|
for k, v in REMOTES.items():
|
||||||
|
if v.get("host") == host:
|
||||||
|
return k
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
return remote
|
||||||
|
|
||||||
|
|
||||||
def _resolve(remote: str, host: str | None, org: str | None, repo: str | None):
|
def _resolve(remote: str, host: str | None, org: str | None, repo: str | None):
|
||||||
"""Resolve remote + overrides to (host, org, repo)."""
|
"""Resolve remote + overrides to (host, org, repo)."""
|
||||||
|
remote = _effective_remote(remote)
|
||||||
if remote not in REMOTES:
|
if remote not in REMOTES:
|
||||||
raise ValueError(f"Unknown remote '{remote}'. Choose from: {list(REMOTES)}")
|
raise ValueError(f"Unknown remote '{remote}'. Choose from: {list(REMOTES)}")
|
||||||
profile = REMOTES[remote]
|
profile = REMOTES[remote]
|
||||||
@@ -1402,6 +1420,7 @@ def _resolve_control_plane_guide_target(
|
|||||||
if org is not None and repo is not None:
|
if org is not None and repo is not None:
|
||||||
return _resolve(remote, host, org, repo)
|
return _resolve(remote, host, org, repo)
|
||||||
|
|
||||||
|
remote = _effective_remote(remote)
|
||||||
if remote not in REMOTES:
|
if remote not in REMOTES:
|
||||||
raise ValueError(f"Unknown remote '{remote}'. Choose from: {list(REMOTES)}")
|
raise ValueError(f"Unknown remote '{remote}'. Choose from: {list(REMOTES)}")
|
||||||
|
|
||||||
@@ -8750,6 +8769,7 @@ def gitea_whoami(
|
|||||||
metadata: profile_name + allowed_operations; never the token).
|
metadata: profile_name + allowed_operations; never the token).
|
||||||
"""
|
"""
|
||||||
record_preflight_check("whoami")
|
record_preflight_check("whoami")
|
||||||
|
remote = _effective_remote(remote)
|
||||||
if remote not in REMOTES:
|
if remote not in REMOTES:
|
||||||
raise ValueError(f"Unknown remote '{remote}'. Choose from: {list(REMOTES)}")
|
raise ValueError(f"Unknown remote '{remote}'. Choose from: {list(REMOTES)}")
|
||||||
h = host or REMOTES[remote]["host"]
|
h = host or REMOTES[remote]["host"]
|
||||||
@@ -8858,8 +8878,6 @@ def gitea_get_profile(
|
|||||||
"execution_profile": profile.get("execution_profile"),
|
"execution_profile": profile.get("execution_profile"),
|
||||||
"auth_source_type": profile.get("auth_source_type"),
|
"auth_source_type": profile.get("auth_source_type"),
|
||||||
# Auth is reported as a status only (#120): the token source *name*
|
# Auth is reported as a status only (#120): the token source *name*
|
||||||
# (env var name / keychain id) joins endpoint URLs behind the
|
|
||||||
# GITEA_MCP_REVEAL_ENDPOINTS admin opt-in. Token values never appear.
|
|
||||||
"auth_status": ("configured" if profile["token_source_name"]
|
"auth_status": ("configured" if profile["token_source_name"]
|
||||||
else "unconfigured"),
|
else "unconfigured"),
|
||||||
"remote": remote if remote in REMOTES else None,
|
"remote": remote if remote in REMOTES else None,
|
||||||
@@ -8871,6 +8889,7 @@ def gitea_get_profile(
|
|||||||
result["base_url"] = profile["base_url"]
|
result["base_url"] = profile["base_url"]
|
||||||
result["server"] = None
|
result["server"] = None
|
||||||
|
|
||||||
|
remote = _effective_remote(remote)
|
||||||
if remote not in REMOTES:
|
if remote not in REMOTES:
|
||||||
# Mark ambiguity rather than raising: the tool stays inspectable.
|
# Mark ambiguity rather than raising: the tool stays inspectable.
|
||||||
result["identity_status"] = "unknown"
|
result["identity_status"] = "unknown"
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ Runs over stdio. All tools authenticate via macOS keychain (git credential fill)
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
sys.stderr = open("/tmp/mcp_server_stderr.log", "a", buffering=1)
|
||||||
|
sys.stderr.write(f"\n--- MCP SERVER STARTUP (PID {os.getpid()}) ---\n")
|
||||||
|
|
||||||
from role_session_router import (
|
from role_session_router import (
|
||||||
python_bytes_have_conflict_markers,
|
python_bytes_have_conflict_markers,
|
||||||
skip_python_scan_walk_root,
|
skip_python_scan_walk_root,
|
||||||
|
|||||||
@@ -275,7 +275,6 @@ def main():
|
|||||||
servers[name],
|
servers[name],
|
||||||
required_tool=REQUIRED_NAMESPACE_TOOLS.get(name),
|
required_tool=REQUIRED_NAMESPACE_TOOLS.get(name),
|
||||||
config_path=config_path,
|
config_path=config_path,
|
||||||
probe_source="offline_spawn",
|
|
||||||
):
|
):
|
||||||
failed = True
|
failed = True
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user