History

right mcp url

Rhys Sullivan committed 8 months ago

Commit e8395261 parent 0056db22 files · +37 −10Browse files

Unified · Split

2 files
  1. apps/web/app/(console)/tools/page.tsx +25 −9
  2. apps/web/components/tools/tools-view.tsx +12 −1
apps/web/app/(console)/tools/page.tsx+25−9
@@ -1,22 +1,38 @@
11 import { ToolsView } from "../../../components/tools/tools-view";
22
3+const normalizeOriginCandidate = (value: string | undefined): string | null => {
4+ const trimmed = value?.trim();
5+ if (!trimmed) {
6+ return null;
7+ }
8+
9+ const withProtocol =
10+ trimmed.startsWith("http://") || trimmed.startsWith("https://")
11+ ? trimmed
12+ : `https://${trimmed}`;
13+
14+ try {
15+ return new URL(withProtocol).origin;
16+ } catch {
17+ return null;
18+ }
19+};
20+
321 const resolveMcpBaseUrl = (): string | null => {
422 const candidates = [
523 process.env.CONTROL_PLANE_UPSTREAM_URL,
624 process.env.CONTROL_PLANE_SERVER_BASE_URL,
725 process.env.NEXT_PUBLIC_CONTROL_PLANE_BASE_URL,
26+ process.env.EXECUTOR_PUBLIC_ORIGIN,
27+ process.env.NEXT_PUBLIC_APP_ORIGIN,
28+ process.env.VERCEL_PROJECT_PRODUCTION_URL,
29+ process.env.VERCEL_URL,
830 ];
931
1032 for (const candidate of candidates) {
11− const value = candidate?.trim();
12− if (!value) {
13− continue;
14− }
15−
16− try {
17− return new URL(value).origin;
18− } catch {
19− // ignore invalid URL and continue
33+ const origin = normalizeOriginCandidate(candidate);
34+ if (origin) {
35+ return origin;
2036 }
2137 }
2238
apps/web/components/tools/tools-view.tsx+12−1
@@ -68,6 +68,13 @@ type SourceGroup = { · 67 unmodified lines
6868 const configuredControlPlaneBaseUrl =
6969 process.env.NEXT_PUBLIC_CONTROL_PLANE_BASE_URL?.trim() ?? "";
7070
71+const isLocalHost = (hostname: string): boolean =>
72+ hostname === "localhost"
73+ || hostname === "127.0.0.1"
74+ || hostname === "0.0.0.0"
75+ || hostname === "::1"
76+ || hostname === "[::1]";
77+
7178 // ---------------------------------------------------------------------------
7279 // Search helpers (ported from old executor explorer-derived.ts)
7380 // ---------------------------------------------------------------------------
@@ -410,7 +417,11 @@ export function ToolsView(props: { · 336 unmodified lines
410417 return `http://127.0.0.1:8788/v1/mcp?workspaceId=${encodeURIComponent(workspaceId)}`;
411418 }
412419
413− const url = new URL("/v1/mcp", "http://127.0.0.1:8788");
420+ const baseOrigin = isLocalHost(window.location.hostname)
421+ ? "http://127.0.0.1:8788"
422+ : window.location.origin;
423+
424+ const url = new URL("/v1/mcp", baseOrigin);
414425 url.searchParams.set("workspaceId", workspaceId);
415426 return url.toString();
416427 }, [props.mcpBaseUrl, workspaceId]);