Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

feat: add MCP/A2A enable/disable toggle switches on Endpoints page

diegosouzapw396ab2bab585
diff --git a/src/app/(dashboard)/dashboard/endpoint/page.tsx b/src/app/(dashboard)/dashboard/endpoint/page.tsx
index 01cb7f76a4..3983ce85d6 100644
--- a/src/app/(dashboard)/dashboard/endpoint/page.tsx
+++ b/src/app/(dashboard)/dashboard/endpoint/page.tsx
@@ -17,17 +17,21 @@ type ServiceStatus = {
function ServiceToggle({
label,
status,
- onRefresh,
+ enabled,
+ onToggle,
+ toggling,
}: {
label: string;
status: ServiceStatus;
- onRefresh: () => void;
+ enabled: boolean;
+ onToggle: () => void;
+ toggling: boolean;
}) {
return (
- <div className="flex items-center gap-2 ml-auto">
- <button
- onClick={onRefresh}
- className="flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium transition-all border"
+ <div className="flex items-center gap-3 ml-auto">
+ {/* Status indicator */}
+ <div
+ className="flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border"
style={{
borderColor: status.loading
? "var(--color-border)"
@@ -58,7 +62,43 @@ function ServiceToggle({
}}
/>
{status.loading ? "..." : status.online ? "Online" : "Offline"}
+ </div>
+
+ {/* Toggle switch */}
+ <button
+ onClick={onToggle}
+ disabled={toggling}
+ className="relative inline-flex items-center h-7 w-[52px] rounded-full transition-all duration-300 focus:outline-none focus:ring-2 focus:ring-offset-2 border"
+ style={{
+ background: enabled
+ ? "rgb(34,197,94)"
+ : "var(--color-bg-tertiary)",
+ borderColor: enabled
+ ? "rgba(34,197,94,0.5)"
+ : "var(--color-border)",
+ opacity: toggling ? 0.6 : 1,
+ cursor: toggling ? "wait" : "pointer",
+ focusRingColor: "var(--color-primary)",
+ }}
+ title={enabled ? `Disable ${label}` : `Enable ${label}`}
+ >
+ <span
+ className="inline-block w-5 h-5 rounded-full shadow-md transition-all duration-300"
+ style={{
+ transform: enabled ? "translateX(26px)" : "translateX(3px)",
+ background: enabled ? "#fff" : "var(--color-text-muted)",
+ }}
+ />
</button>
+
+ <span
+ className="text-xs font-medium min-w-[24px]"
+ style={{
+ color: enabled ? "rgb(34,197,94)" : "var(--color-text-muted)",
+ }}
+ >
+ {toggling ? "..." : enabled ? "ON" : "OFF"}
+ </span>
</div>
);
}
@@ -69,6 +109,55 @@ export default function EndpointPage() {
const [mcpStatus, setMcpStatus] = useState<ServiceStatus>({ online: false, loading: true });
const [a2aStatus, setA2aStatus] = useState<ServiceStatus>({ online: false, loading: true });
+ const [mcpEnabled, setMcpEnabled] = useState(false);
+ const [a2aEnabled, setA2aEnabled] = useState(false);
+ const [mcpToggling, setMcpToggling] = useState(false);
+ const [a2aToggling, setA2aToggling] = useState(false);
+
+ // Fetch initial enabled state from settings
+ useEffect(() => {
+ const fetchSettings = async () => {
+ try {
+ const res = await fetch("/api/settings");
+ if (res.ok) {
+ const data = await res.json();
+ setMcpEnabled(!!data.mcpEnabled);
+ setA2aEnabled(!!data.a2aEnabled);
+ }
+ } catch {
+ // defaults stay false
+ }
+ };
+ void fetchSettings();
+ }, []);
+
+ const toggleService = useCallback(
+ async (service: "mcp" | "a2a") => {
+ const setToggling = service === "mcp" ? setMcpToggling : setA2aToggling;
+ const setEnabled = service === "mcp" ? setMcpEnabled : setA2aEnabled;
+ const currentlyEnabled = service === "mcp" ? mcpEnabled : a2aEnabled;
+ const newValue = !currentlyEnabled;
+
+ setToggling(true);
+ try {
+ const res = await fetch("/api/settings", {
+ method: "PATCH",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({
+ [service === "mcp" ? "mcpEnabled" : "a2aEnabled"]: newValue,
+ }),
+ });
+ if (res.ok) {
+ setEnabled(newValue);
+ }
+ } catch {
+ // toggle failed — keep current state
+ } finally {
+ setToggling(false);
+ }
+ },
+ [mcpEnabled, a2aEnabled],
+ );
const refreshMcpStatus = useCallback(async () => {
setMcpStatus((prev) => ({ ...prev, loading: true }));
@@ -125,10 +214,22 @@ export default function EndpointPage() {
/>
{activeTab === "mcp" && (
- <ServiceToggle label="MCP" status={mcpStatus} onRefresh={refreshMcpStatus} />
+ <ServiceToggle
+ label="MCP"
+ status={mcpStatus}
+ enabled={mcpEnabled}
+ onToggle={() => void toggleService("mcp")}
+ toggling={mcpToggling}
+ />
)}
{activeTab === "a2a" && (
- <ServiceToggle label="A2A" status={a2aStatus} onRefresh={refreshA2aStatus} />
+ <ServiceToggle
+ label="A2A"
+ status={a2aStatus}
+ enabled={a2aEnabled}
+ onToggle={() => void toggleService("a2a")}
+ toggling={a2aToggling}
+ />
)}
</div>
diff --git a/src/shared/validation/schemas.ts b/src/shared/validation/schemas.ts
index cd34559f47..e7fd2a9870 100644
--- a/src/shared/validation/schemas.ts
+++ b/src/shared/validation/schemas.ts
@@ -128,6 +128,9 @@ export const updateSettingsSchema = z.object({
.optional(),
wildcardAliases: z.array(z.object({ pattern: z.string(), target: z.string() })).optional(),
stickyRoundRobinLimit: z.number().int().min(0).max(1000).optional(),
+ // Protocol toggles (default: disabled)
+ mcpEnabled: z.boolean().optional(),
+ a2aEnabled: z.boolean().optional(),
});
// ──── Auth Schemas ────