From bfc2a74e4f93598d5d8e9fbb73401cb2f70dd805 Mon Sep 17 00:00:00 2001 From: Xubin Ren <52506698+Re-bin@users.noreply.github.com> Date: Mon, 29 Jun 2026 18:00:36 +0800 Subject: [PATCH] fix(mcp): preserve IPv6 brackets when redacting URLs --- nanobot/agent/tools/mcp.py | 3 ++- tests/tools/test_mcp_tool.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/nanobot/agent/tools/mcp.py b/nanobot/agent/tools/mcp.py index f5a41e10..28219892 100644 --- a/nanobot/agent/tools/mcp.py +++ b/nanobot/agent/tools/mcp.py @@ -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, "", "")) diff --git a/tests/tools/test_mcp_tool.py b/tests/tools/test_mcp_tool.py index c2eb81e5..81676f18 100644 --- a/tests/tools/test_mcp_tool.py +++ b/tests/tools/test_mcp_tool.py @@ -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"), ], )