From 7bab4c0d0327639ad9f098a8b8810230335b343d Mon Sep 17 00:00:00 2001 From: ryan-crabbe-berri Date: Wed, 16 Sep 2026 10:54:16 -0700 Subject: [PATCH 1/3] feat(ui): persist mcp state in the URL The MCP Servers page keeps its tab, team, access group, search and sort filters, the open server and its tab, the selected tool and tool search, the toolsets table sort and page, the Connect client tab and the submissions filters in the query string, so reloads, shared links and back/forward restore the same view. The open server is resolved from the full server list, so a deep link opens it even when the current filters hide it and an unknown id shows the list instead of an "Unnamed Server" placeholder. The fill_env_vars deep link and the tools/edit OAuth return now go through nuqs instead of window.history, and the OAuth return writes server and server_tab. MCPConnect now defines its code block and step card at module level and renders the tab bodies as plain elements, so switching the URL-backed client tab (or copying a snippet) no longer remounts them and resets the x-mcp-servers toggle. --- .../_components/MCPSubmissionsTab.test.tsx | 101 +++ .../_components/MCPSubmissionsTab.tsx | 20 +- .../MCPToolsetsTab.integration.test.tsx | 78 ++- .../_components/MCPToolsetsTab.tsx | 17 +- .../_components/mcp_connect.test.tsx | 46 +- .../mcp-servers/_components/mcp_connect.tsx | 96 ++- .../_components/mcp_server_view.test.tsx | 111 ++- .../_components/mcp_server_view.tsx | 29 +- .../_components/mcp_servers.test.tsx | 646 ++++++++++-------- .../mcp-servers/_components/mcp_servers.tsx | 244 ++----- .../_components/mcp_tools.test.tsx | 145 +++- .../mcp-servers/_components/mcp_tools.tsx | 38 +- .../_components/useMcpServersUrlState.ts | 131 ++++ 13 files changed, 1093 insertions(+), 609 deletions(-) create mode 100644 ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/MCPSubmissionsTab.test.tsx create mode 100644 ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/useMcpServersUrlState.ts diff --git a/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/MCPSubmissionsTab.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/MCPSubmissionsTab.test.tsx new file mode 100644 index 00000000000..a0744af1601 --- /dev/null +++ b/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/MCPSubmissionsTab.test.tsx @@ -0,0 +1,101 @@ +import { describe, it, expect, vi, beforeEach } from "vitest"; +import type { OnUrlUpdateFunction } from "nuqs/adapters/testing"; +import { MCPSubmissionsTab } from "./MCPSubmissionsTab"; +import { fetchMCPSubmissions } from "@/components/networking"; +import type { MCPServer, MCPSubmissionsSummary } from "@/components/mcp_tools/types"; +import { fireEvent, renderWithProviders, screen, waitFor } from "@/../tests/test-utils"; + +vi.mock("@/components/networking", () => ({ + fetchMCPSubmissions: vi.fn(), + approveMCPServer: vi.fn(), + rejectMCPServer: vi.fn(), + getGeneralSettingsCall: vi.fn().mockResolvedValue({ data: [] }), + updateConfigFieldSetting: vi.fn(), +})); + +const submission = (alias: string, approval_status: MCPServer["approval_status"]): MCPServer => ({ + server_id: `id-${alias}`, + alias, + url: `https://${alias}.example.com/mcp`, + approval_status, + created_at: "2024-01-01T00:00:00Z", + created_by: "user-1", + updated_at: "2024-01-01T00:00:00Z", + updated_by: "user-1", +}); + +const SUBMISSION_NAMES = ["github-pending", "github-live", "linear-pending"]; + +const shownSubmissions = () => + screen + .getAllByRole("heading", { level: 3 }) + .map((heading) => heading.textContent) + .filter((name) => name !== null && SUBMISSION_NAMES.includes(name)); + +const renderTab = (searchParams: string, onUrlUpdate?: OnUrlUpdateFunction) => + renderWithProviders(, { searchParams, onUrlUpdate }); + +const SUMMARY: MCPSubmissionsSummary = { + total: 3, + pending_review: 2, + active: 1, + rejected: 0, + items: [ + submission("github-pending", "pending_review"), + submission("github-live", "active"), + submission("linear-pending", "pending_review"), + ], +}; + +describe("MCPSubmissionsTab filter URL state", () => { + beforeEach(() => { + vi.mocked(fetchMCPSubmissions).mockResolvedValue(SUMMARY); + }); + + it("lists every submission without filters", async () => { + renderTab(""); + + await screen.findByRole("heading", { level: 3, name: "linear-pending" }); + expect(shownSubmissions()).toEqual(SUBMISSION_NAMES); + }); + + it("applies the search and status in the URL", async () => { + renderTab("?sub_search=github&sub_status=pending_review"); + + await screen.findByRole("heading", { level: 3, name: "github-pending" }); + expect(shownSubmissions()).toEqual(["github-pending"]); + expect(screen.getByPlaceholderText("Search MCP servers...")).toHaveValue("github"); + expect(screen.getByRole("combobox")).toHaveValue("pending_review"); + }); + + it("ignores an unknown status in the URL", async () => { + renderTab("?sub_status=archived"); + + await screen.findByRole("heading", { level: 3, name: "linear-pending" }); + expect(shownSubmissions()).toEqual(SUBMISSION_NAMES); + expect(screen.getByRole("combobox")).toHaveValue("all"); + }); + + it("writes the search and status the user picks", async () => { + const onUrlUpdate = vi.fn(); + renderTab("?tab=submitted", onUrlUpdate); + await screen.findByRole("heading", { level: 3, name: "linear-pending" }); + + fireEvent.change(screen.getByPlaceholderText("Search MCP servers..."), { target: { value: "pending" } }); + + await waitFor(() => expect(onUrlUpdate.mock.calls.at(-1)?.[0].searchParams.get("sub_search")).toBe("pending")); + expect(shownSubmissions()).toEqual(["github-pending", "linear-pending"]); + + fireEvent.change(screen.getByRole("combobox"), { target: { value: "active" } }); + + await waitFor(() => expect(onUrlUpdate.mock.calls.at(-1)?.[0].searchParams.get("sub_status")).toBe("active")); + expect(onUrlUpdate.mock.calls.at(-1)?.[0].searchParams.get("sub_search")).toBe("pending"); + expect(onUrlUpdate.mock.calls.at(-1)?.[0].searchParams.get("tab")).toBe("submitted"); + expect(screen.getByText("No MCP server submissions match your filters.")).toBeInTheDocument(); + + fireEvent.change(screen.getByRole("combobox"), { target: { value: "all" } }); + + await waitFor(() => expect(onUrlUpdate.mock.calls.at(-1)?.[0].searchParams.has("sub_status")).toBe(false)); + expect(shownSubmissions()).toEqual(["github-pending", "linear-pending"]); + }); +}); diff --git a/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/MCPSubmissionsTab.tsx b/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/MCPSubmissionsTab.tsx index 7062a6f0a5f..f000691df9b 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/MCPSubmissionsTab.tsx +++ b/ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/MCPSubmissionsTab.tsx @@ -1,6 +1,7 @@ "use client"; import React, { useState, useEffect, useCallback } from "react"; +import { parseAsString, parseAsStringLiteral, useQueryStates } from "nuqs"; import { SearchIcon, CheckIcon, @@ -24,6 +25,17 @@ import { toast } from "@/lib/toast"; type MCPStatus = "active" | "pending_review" | "rejected"; +const STATUS_FILTERS = ["all", "pending_review", "active", "rejected"] as const; +type StatusFilter = (typeof STATUS_FILTERS)[number]; + +const submissionFilterParsers = { + sub_search: parseAsString.withDefault(""), + sub_status: parseAsStringLiteral(STATUS_FILTERS).withDefault("all"), +}; + +const toStatusFilter = (value: string): StatusFilter | null => + STATUS_FILTERS.find((status) => status === value) ?? null; + const STATUS_CONFIG: Record = { active: { label: "Active", @@ -456,8 +468,8 @@ export function MCPSubmissionsTab({ accessToken }: MCPSubmissionsTabProps) { rejected: 0, items: [], }); - const [search, setSearch] = useState(""); - const [statusFilter, setStatusFilter] = useState<"all" | MCPStatus>("all"); + const [{ sub_search: search, sub_status: statusFilter }, setSubmissionFilters] = + useQueryStates(submissionFilterParsers); const [confirmAction, setConfirmAction] = useState<{ serverId: string; serverName: string; @@ -578,13 +590,13 @@ export function MCPSubmissionsTab({ accessToken }: MCPSubmissionsTabProps) { type="text" placeholder="Search MCP servers..." value={search} - onChange={(e) => setSearch(e.target.value)} + onChange={(e) => void setSubmissionFilters({ sub_search: e.target.value })} className="w-full pl-9 pr-4 py-2 border border-border rounded-md text-sm text-foreground placeholder:text-muted-foreground focus:outline-hidden focus:ring-1 focus:ring-ring focus:border-info" /> handleTeamChange(v ?? "all")} + onValueChange={(v: string | null) => setTeam(v)} > @@ -625,7 +508,7 @@ const MCPServers: React.FC = ({ accessToken, userRole, userID }) setSortKey((v ?? "created_desc") as SortKey)} - > +