microsoft/autogen · warning · Error
Invalid server URL configuration
Error message
Invalid server URL configuration
What it means
Error thrown by getBaseUrl in autogen-studio's playground chat when normalizing the configured server URL fails inside the try block. The function strips protocols, handles 'localhost' and '/api' special cases, and re-raises any unexpected failure as this generic configuration error, so the WebSocket URL cannot be built.
Source
Thrown at python/packages/autogen-studio/frontend/src/components/views/playground/chat/chat.tsx:546
return socket;
};
// Helper for WebSocket URL
const getBaseUrl = (url: string): string => {
try {
let baseUrl = url.replace(/(^\w+:|^)\/\//, "");
if (baseUrl.startsWith("localhost")) {
baseUrl = baseUrl.replace("/api", "");
} else if (baseUrl === "/api") {
baseUrl = window.location.host;
} else {
baseUrl = baseUrl.replace("/api", "").replace(/\/$/, "");
}
return baseUrl;
} catch (error) {
console.error("Error processing server URL:", error);
throw new Error("Invalid server URL configuration");
}
};
return (
<div className="text-primary h-[calc(100vh-165px)] bg-primary relative rounded flex-1 scroll">
{contextHolder}
<div className="flex pt-2 items-center justify-between text-sm h-10">
<div className="flex items-center gap-2 min-w-0 overflow-hidden flex-1 pr-4">
{isCompareMode ? (
<SessionDropdown
session={session}
availableSessions={availableSessions}
onSessionChange={onSessionChange || (() => {})}
className="w-full"
/>
) : (
<>
<span className="text-primary font-medium whitespace-nowrap flex-shrink-0">View on GitHub (pinned to 027ecf0a37)
Solutions
- Validate the serverUrl setting before use: default it to window.location.host when empty or null.
- Guard non-browser environments: only build the WS URL when typeof window !== "undefined".
- Clear/re-save the server URL setting in the UI if it was persisted in an old format.
Example fix
// before
const wsUrl = `${wsProtocol}//${getBaseUrl(serverUrl)}/api/ws/runs/${runId}`;
// after
const base = serverUrl || window.location.host;
const wsUrl = `${wsProtocol}//${getBaseUrl(base)}/api/ws/runs/${runId}`; Defensive patterns
Strategy: validation
Validate before calling
if (typeof window === "undefined" || !window.location?.host) {
throw new Error("getBaseUrl requires a browser environment");
}
const normalizedUrl = serverUrl?.trim() || window.location.host;
const base = getBaseUrl(normalizedUrl); Type guard
const isValidServerUrl = (u: unknown): u is string => typeof u === "string" && u.trim().length > 0;
Try / catch
try { const base = getBaseUrl(serverUrl); }
catch (e) {
if (e instanceof Error && e.message === "Invalid server URL configuration") {
const fallback = window.location.host;
return getBaseUrl(fallback);
}
throw e;
} Prevention
- Default empty serverUrl to window.location.host before calling getBaseUrl.
- Never persist null as the server URL setting; coerce blank inputs on save.
- Skip WebSocket setup during SSR by guarding on typeof window.
When it happens
Trigger: Practically hard to trigger because String.prototype.replace does not throw on ordinary inputs; it fires only if url or window.location is unexpectedly null/undefined (e.g. url passed as null from config, or the code runs outside a browser during SSR/test where window is undefined and the catch converts the ReferenceError).
Common situations: Server URL setting left blank or saved as null in the UI settings; importing the chat component in a Node test environment where window is undefined; corrupted localStorage settings after a version change renamed the config key.
Related errors
- Invalid server URL configuration
- useAuth must be used within an AuthProvider
- Invalid session configuration
- Unable to generate valid configuration
- Failed to delete team
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/7005fedd71edefbe.
Report an issue: GitHub.