From 82aca6a324b77fdd9fe287ac788c27d27689b14a Mon Sep 17 00:00:00 2001 From: giveen Date: Wed, 14 Jan 2026 15:01:44 -0700 Subject: [PATCH] fix(mcp): correct indentation and robust /sse URL handling --- pentestagent/mcp/manager.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pentestagent/mcp/manager.py b/pentestagent/mcp/manager.py index 61de68a..6e1eb80 100644 --- a/pentestagent/mcp/manager.py +++ b/pentestagent/mcp/manager.py @@ -456,15 +456,18 @@ class MCPManager: use_http = True # If args specify a --server URL, prefer that if not http_url: + from urllib.parse import urlparse + for i, a in enumerate(config.args or []): if a == "--server" and i + 1 < len(config.args): candidate = config.args[i + 1] if isinstance(candidate, str) and candidate.startswith("http"): - # If the provided server URL doesn't include a path, default to the MCP SSE path - if candidate.rstrip('/').endswith(str(port)) or candidate.rstrip('/') == candidate.split('//')[-1].split(':')[0]: - http_url = candidate.rstrip('/') + '/sse' - else: - http_url = candidate + # If the provided server URL doesn't include a path, default to the MCP SSE path + p = urlparse(candidate) + if p.path and p.path != "/": + http_url = candidate + else: + http_url = candidate.rstrip("/") + "/sse" use_http = True break