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