fix(mcp): preserve IPv6 brackets when redacting URLs

This commit is contained in:
Xubin Ren
2026-06-30 22:43:12 +08:00
parent 780093d037
commit bfc2a74e4f
2 changed files with 3 additions and 1 deletions
+2 -1
View File
@@ -174,7 +174,8 @@ def _redact_url(url: str) -> str:
"""
try:
parts = urllib.parse.urlsplit(url)
netloc = parts.hostname or ""
hostname = parts.hostname or ""
netloc = f"[{hostname}]" if ":" in hostname else hostname
if parts.port:
netloc = f"{netloc}:{parts.port}"
return urllib.parse.urlunsplit((parts.scheme, netloc, parts.path, "", ""))
+1
View File
@@ -1247,6 +1247,7 @@ async def test_connect_mcp_servers_enabled_tools_matches_sanitized_name(
[
("https://user:secret@host.example/sse", "https://host.example/sse"),
("https://host.example:8443/mcp?token=abc#frag", "https://host.example:8443/mcp"),
("https://user:secret@[::1]:8443/sse?token=abc", "https://[::1]:8443/sse"),
("https://host.example/sse", "https://host.example/sse"),
],
)