Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

test(ui): pin the client-forwarded token contract on create and edit

Tin4786e599b0f7
diff --git a/ui/litellm-dashboard/src/components/mcp_tools/create_mcp_server.test.tsx b/ui/litellm-dashboard/src/components/mcp_tools/create_mcp_server.test.tsx
index 658116ede1f..02374a3ffa4 100644
--- a/ui/litellm-dashboard/src/components/mcp_tools/create_mcp_server.test.tsx
+++ b/ui/litellm-dashboard/src/components/mcp_tools/create_mcp_server.test.tsx
@@ -374,6 +374,68 @@ describe("CreateMCPServer", () => {
expect(credentials.access_token).toBeUndefined();
});
+ it.each([
+ ["true_passthrough", "True Passthrough (no LiteLLM auth)"],
+ ["oauth_delegate", "OAuth Delegate (client-supplied upstream token)"],
+ ])("persists only tool config on create for %s; the token stays browser-held", async (_authType, optionLabel) => {
+ oauthHook.tokenResponse = { access_token: "upstream-tok", token_type: "Bearer" };
+ await selectHttpTransport();
+
+ const user = userEvent.setup({ delay: null });
+ await user.type(getServerNameInput(), "CF_Server");
+ await user.type(screen.getByPlaceholderText("https://your-mcp-server.com"), "https://example.com/mcp");
+
+ await selectAntOption("Authentication", optionLabel);
+
+ await waitFor(() => expect(oauthHook.onTokenReceived).toBeTruthy());
+ await act(async () => {
+ oauthHook.onTokenReceived!({ access_token: "upstream-tok", token_type: "Bearer" }, undefined);
+ });
+
+ fireEvent.click(screen.getByRole("button", { name: "Disable all tools" }));
+
+ // Previewing and configuring must stay stateless: nothing is persisted anywhere (server row,
+ // per-user DB credential, sessionStorage) until the admin submits.
+ expect(networking.createMCPServer).not.toHaveBeenCalled();
+ expect(networking.storeMCPOAuthUserCredential).not.toHaveBeenCalled();
+ expect(setToken).not.toHaveBeenCalled();
+
+ const createdServer = {
+ server_id: "new-cf-server",
+ server_name: "CF_Server",
+ alias: "CF_Server",
+ url: "https://example.com/mcp",
+ transport: "http",
+ auth_type: _authType,
+ created_at: "2024-01-01T00:00:00Z",
+ created_by: "user-1",
+ updated_at: "2024-01-01T00:00:00Z",
+ updated_by: "user-1",
+ };
+ vi.mocked(networking.createMCPServer).mockResolvedValue(createdServer);
+
+ const submitButton = screen.getByRole("button", { name: "Add MCP Server" });
+ await act(async () => {
+ fireEvent.click(submitButton);
+ });
+
+ await waitFor(() => expect(networking.createMCPServer).toHaveBeenCalledTimes(1));
+ const [, payload] = vi.mocked(networking.createMCPServer).mock.calls[0];
+
+ // Only the tool configuration persists on the server row; the upstream token appears nowhere
+ // in the create payload and no per-user DB credential is written. The token is committed to
+ // sessionStorage only, keyed to the created server.
+ expect(payload.allowed_tools).toEqual([]);
+ expect(payload.credentials).toBeUndefined();
+ expect(JSON.stringify(payload)).not.toContain("upstream-tok");
+ expect(networking.storeMCPOAuthUserCredential).not.toHaveBeenCalled();
+ expect(setToken).toHaveBeenCalledWith(
+ "new-cf-server",
+ expect.objectContaining({ access_token: "upstream-tok" }),
+ undefined,
+ );
+ });
+
it("should not show auth value field when None auth type is selected", async () => {
await selectHttpTransport();
diff --git a/ui/litellm-dashboard/src/components/mcp_tools/mcp_server_edit.test.tsx b/ui/litellm-dashboard/src/components/mcp_tools/mcp_server_edit.test.tsx
index 9a9db2eeb95..93ff1333cd8 100644
--- a/ui/litellm-dashboard/src/components/mcp_tools/mcp_server_edit.test.tsx
+++ b/ui/litellm-dashboard/src/components/mcp_tools/mcp_server_edit.test.tsx
@@ -1339,6 +1339,7 @@ describe("MCPServerEdit (OAuth token persistence on save)", () => {
expect(networking.storeMCPOAuthUserCredential).not.toHaveBeenCalled();
const [, payload] = vi.mocked(networking.updateMCPServer).mock.calls[0];
expect(payload.credentials).toBeUndefined();
+ expect(JSON.stringify(payload)).not.toContain("cf-tok");
},
);