unslothai/unsloth · warning · HTTPException
url is missing a host
Error message
url is missing a host
What it means
400 raised after scheme validation passes (http:// or https://) but urlparse finds no netloc — the authority/host component is empty. This catches malformed URLs where the host slot is blank, since a URL without a host cannot be dialed.
Source
Thrown at studio/backend/routes/mcp_servers.py:105
"first token is an executable (not a URL).",
)
return trimmed
parsed = urlparse(trimmed)
if parsed.scheme not in ("http", "https"):
if _looks_like_command(trimmed):
detail = (
"Local commands aren't enabled on this server. To allow them, "
"set UNSLOTH_STUDIO_ALLOW_STDIO_MCP=1 and restart Unsloth, or use "
"an http:// or https:// URL instead."
)
else:
detail = (
"MCP server address must start with http:// or https:// "
"(for example https://example.com/mcp)."
)
raise HTTPException(status_code = 400, detail = detail)
if not parsed.netloc:
raise HTTPException(status_code = 400, detail = "url is missing a host")
return trimmed
def _normalize_headers(headers: dict[str, str] | None) -> dict[str, str] | None:
"""Trim header names, drop empties, coerce values to str; None if empty."""
if not headers:
return None
out: dict[str, str] = {}
for raw_key, value in headers.items():
key = str(raw_key).strip()
if key:
out[key] = str(value)
return out or None
def _row_to_response(row: dict) -> McpServerResponse:
return McpServerResponse(
id = row["id"],View on GitHub (pinned to 203007d190)
Solutions
- Fix the URL to include a host: 'https://example.com/mcp', 'http://127.0.0.1:8080/mcp'.
- When templating, assert the host variable is non-empty before building the URL.
- Watch for doubled slashes after the scheme that push the host into the path.
Example fix
# before
url = f'http://{host}/mcp' # host == '' -> 'http:///mcp' -> 400
# after
assert host, 'MCP host must be set'
url = f'http://{host}/mcp' Defensive patterns
Strategy: validation
Validate before calling
try { const u = new URL(url); if (!u.hostname) throw new Error('missing host'); } catch { throw new Error('invalid MCP url'); } Type guard
function urlHasHost(v) { try { return new URL(v).hostname.length > 0; } catch { return false; } } Prevention
- Template URLs only after asserting the host variable is non-empty.
- Avoid extra slashes between scheme and host.
When it happens
Trigger: POST/PUT with url values like 'http://', 'http:///path', 'https://:8080', or 'http:// /x' where everything lands in the path and the netloc stays empty.
Common situations: String-concatenation bugs building URLs from empty host variables (f'http://{host}/mcp' with host=''), or typos adding extra slashes after the scheme.
Related errors
- url must not be empty
- Enter an http(s):// URL, or a local command whose first toke
- MCP server address must start with http:// or https:// (for
- command must not be empty
- is_enabled must be true or false
AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15).
Data as JSON: /api/errors/9f190debeda692f4.
Report an issue: GitHub.